1. 17 1月, 2016 5 次提交
  2. 07 1月, 2016 1 次提交
  3. 07 11月, 2015 5 次提交
  4. 21 7月, 2015 1 次提交
  5. 17 4月, 2015 2 次提交
    • R
      lib/vsprintf.c: improve put_dec_trunc8 slightly · 675cf53c
      Rasmus Villemoes 提交于
      I hadn't had enough coffee when I wrote this. Currently, the final
      increment of buf depends on the value loaded from the table, and
      causes gcc to emit a cmov immediately before the return. It is smarter
      to let it depend on r, since the increment can then be computed in
      parallel with the final load/store pair. It also shaves 16 bytes of
      .text.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      675cf53c
    • R
      lib/vsprintf.c: even faster binary to decimal conversion · 7c43d9a3
      Rasmus Villemoes 提交于
      The most expensive part of decimal conversion is the divisions by 10
      (albeit done using reciprocal multiplication with appropriately chosen
      constants).  I decided to see if one could eliminate around half of
      these multiplications by emitting two digits at a time, at the cost of a
      200 byte lookup table, and it does indeed seem like there is something
      to be gained, especially on 64 bits.  Microbenchmarking shows
      improvements ranging from -50% (for numbers uniformly distributed in [0,
      2^64-1]) to -25% (for numbers heavily biased toward the smaller end, a
      more realistic distribution).
      
      On a larger scale, perf shows that top, one of the big consumers of /proc
      data, uses 0.5-1.0% fewer cpu cycles.
      
      I had to jump through some hoops to get the 32 bit code to compile and run
      on my 64 bit machine, so I'm not sure how relevant these numbers are, but
      just for comparison the microbenchmark showed improvements between -30%
      and -10%.
      
      The bloat-o-meter costs are around 150 bytes (the generated code is a
      little smaller, so it's not the full 200 bytes) on both 32 and 64 bit.
      I'm aware that extra cache misses won't show up in a microbenchmark as
      used above, but on the other hand decimal conversions often happen in bulk
      (for example in the case of top).
      
      I have of course tested that the new code generates the same output as the
      old, for both the first and last 1e10 numbers in [0,2^64-1] and 4e9
      'random' numbers in-between.
      
      Test and verification code on github: https://github.com/Villemoes/dec.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Tested-by: NJeff Epler <jepler@unpythonic.net>
      Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Joe Perches <joe@perches.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      7c43d9a3
  6. 16 4月, 2015 7 次提交
    • R
      lib/string_helpers.c: change semantics of string_escape_mem · 41416f23
      Rasmus Villemoes 提交于
      The current semantics of string_escape_mem are inadequate for one of its
      current users, vsnprintf().  If that is to honour its contract, it must
      know how much space would be needed for the entire escaped buffer, and
      string_escape_mem provides no way of obtaining that (short of allocating a
      large enough buffer (~4 times input string) to let it play with, and
      that's definitely a big no-no inside vsnprintf).
      
      So change the semantics for string_escape_mem to be more snprintf-like:
      Return the size of the output that would be generated if the destination
      buffer was big enough, but of course still only write to the part of dst
      it is allowed to, and (contrary to snprintf) don't do '\0'-termination.
      It is then up to the caller to detect whether output was truncated and to
      append a '\0' if desired.  Also, we must output partial escape sequences,
      otherwise a call such as snprintf(buf, 3, "%1pE", "\123") would cause
      printf to write a \0 to buf[2] but leaving buf[0] and buf[1] with whatever
      they previously contained.
      
      This also fixes a bug in the escaped_string() helper function, which used
      to unconditionally pass a length of "end-buf" to string_escape_mem();
      since the latter doesn't check osz for being insanely large, it would
      happily write to dst.  For example, kasprintf(GFP_KERNEL, "something and
      then %pE", ...); is an easy way to trigger an oops.
      
      In test-string_helpers.c, the -ENOMEM test is replaced with testing for
      getting the expected return value even if the buffer is too small.  We
      also ensure that nothing is written (by relying on a NULL pointer deref)
      if the output size is 0 by passing NULL - this has to work for
      kasprintf("%pE") to work.
      
      In net/sunrpc/cache.c, I think qword_add still has the same semantics.
      Someone should definitely double-check this.
      
      In fs/proc/array.c, I made the minimum possible change, but longer-term it
      should stop poking around in seq_file internals.
      
      [andriy.shevchenko@linux.intel.com: simplify qword_add]
      [andriy.shevchenko@linux.intel.com: add missed curly braces]
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      41416f23
    • R
      lib/vsprintf.c: fix potential NULL deref in hex_string · 9c98f235
      Rasmus Villemoes 提交于
      The helper hex_string() is broken in two ways.  First, it doesn't
      increment buf regardless of whether there is room to print, so callers
      such as kasprintf() that try to probe the correct storage to allocate will
      get a too small return value.  But even worse, kasprintf() (and likely
      anyone else trying to find the size of the result) pass NULL for buf and 0
      for size, so we also have end == NULL.  But this means that the end-1 in
      hex_string() is (char*)-1, so buf < end-1 is true and we get a NULL
      pointer deref.  I double-checked this with a trivial kernel module that
      just did a kasprintf(GFP_KERNEL, "%14ph", "CrashBoomBang").
      
      Nobody seems to be using %ph with kasprintf, but we might as well fix it
      before it hits someone.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9c98f235
    • G
      lib/vsprintf: add %pC{,n,r} format specifiers for clocks · 900cca29
      Geert Uytterhoeven 提交于
      Add format specifiers for printing struct clk:
        - '%pC' or '%pCn': name (Common Clock Framework) or address (legacy
          clock framework) of the clock,
        - '%pCr': rate of the clock.
      
      [akpm@linux-foundation.org: omit code if !CONFIG_HAVE_CLK]
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Mike Turquette <mturquette@linaro.org>
      Cc: Stephen Boyd <sboyd@codeaurora.org>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      900cca29
    • R
      lib/vsprintf.c: another small hack · d1c1b121
      Rasmus Villemoes 提交于
      Making ZEROPAD == '0'-' ', we can eliminate a few more instructions.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d1c1b121
    • R
      lib/vsprintf.c: eliminate duplicate hex string array · 3ea8d440
      Rasmus Villemoes 提交于
      gcc doesn't merge or overlap const char[] objects with identical contents
      (probably language lawyers would also insist that these things have
      different addresses), but there's no reason to have the string
      "0123456789ABCDEF" occur in multiple places.  hex_asc_upper is declared in
      kernel.h and defined in lib/hexdump.c, which is unconditionally compiled
      in.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      3ea8d440
    • R
      lib/vsprintf.c: reduce stack use in number() · e26c12c7
      Rasmus Villemoes 提交于
      At least since the initial git commit, when base was passed as a separate
      parameter, number() has only been called with bases 8, 10 and 16.  I'm
      guessing that 66 was to accommodate 64 0/1, a sign and a '\0', but the
      buffer is only used for the actual digits.  Octal digits carry 3 bits of
      information, so 24 is enough.  Spell that 3*sizeof(num) so one less place
      needs to be changed should long long ever be 128 bits.  Also remove the
      commented-out code that would handle an arbitrary base.
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      e26c12c7
    • R
      lib/vsprintf.c: eliminate some branches · 51be17df
      Rasmus Villemoes 提交于
      Since FORMAT_TYPE_INT is simply 1 more than FORMAT_TYPE_UINT, and
      similarly for BYTE/UBYTE, SHORT/USHORT, LONG/ULONG, we can eliminate a few
      instructions by making SIGN have the value 1 instead of 2, and then use
      arithmetic instead of branches for computing the right spec->type.  It's a
      little hacky, but certainly in the same spirit as SMALL needing to have
      the value 0x20.  For example for the spec->qualifier == 'l' case, gcc now
      generates
      
           75e:       0f b6 53 01             movzbl 0x1(%rbx),%edx
           762:       83 e2 01                and    $0x1,%edx
           765:       83 c2 09                add    $0x9,%edx
           768:       88 13                   mov    %dl,(%rbx)
      
      instead of
      
           763:       0f b6 53 01             movzbl 0x1(%rbx),%edx
           767:       83 e2 02                and    $0x2,%edx
           76a:       80 fa 01                cmp    $0x1,%dl
           76d:       19 d2                   sbb    %edx,%edx
           76f:       83 c2 0a                add    $0xa,%edx
           772:       88 13                   mov    %dl,(%rbx)
      Signed-off-by: NRasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Tejun Heo <tj@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      51be17df
  7. 14 2月, 2015 1 次提交
    • T
      lib/vsprintf: implement bitmap printing through '%*pb[l]' · dbc760bc
      Tejun Heo 提交于
      bitmap and its derivatives such as cpumask and nodemask currently only
      provide formatting functions which put the output string into the
      provided buffer; however, how long this buffer should be isn't defined
      anywhere and given that some of these bitmaps can be too large to be
      formatted into an on-stack buffer it users sometimes are unnecessarily
      forced to come up with creative solutions and compromises for the
      buffer just to printk these bitmaps.
      
      There have been a couple different attempts at making this easier.
      
      1. Way back, PeterZ tried printk '%pb' extension with the precision
         for bit width - '%.*pb'.  This was intuitive and made sense but
         unfortunately triggered a compile warning about using precision
         for a pointer.
      
         http://lkml.kernel.org/g/1336577562.2527.58.camel@twins
      
      2. I implemented bitmap_pr_cont[_list]() and its wrappers for cpumask
         and nodemask.  This works but PeterZ pointed out that pr_cont's
         tendency to produce broken lines when multiple CPUs are printing is
         bothering considering the usages.
      
         http://lkml.kernel.org/g/1418226774-30215-3-git-send-email-tj@kernel.org
      
      So, this patch is another attempt at teaching printk and friends how
      to print bitmaps.  It's almost identical to what PeterZ tried with
      precision but it uses the field width for the number of bits instead
      of precision.  The format used is '%*pb[l]', with the optional
      trailing 'l' specifying list format instead of hex masks.
      
      This is a valid format string and doesn't trigger compiler warnings;
      however, it does make it impossible to specify output field width when
      printing bitmaps.  I think this is an acceptable trade-off given how
      much easier it makes printing bitmaps and that we don't have any
      in-kernel user which is using the field width specification.  If any
      future user wants to use field width with a bitmap, it'd have to
      format the bitmap into a string buffer and then print that buffer with
      width spec, which isn't different from how it should be done now.
      
      This patch implements bitmap[_list]_string() which are called from the
      vsprintf pointer() formatting function.  The implementation is mostly
      identical to bitmap_scn[list]printf() except that the output is
      performed in the vsprintf way.  These functions handle formatting into
      too small buffers and sprintf() family of functions report the correct
      overrun output length.
      
      bitmap_scn[list]printf() are now thin wrappers around scnprintf().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: "John W. Linville" <linville@tuxdriver.com>
      Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Chris Metcalf <cmetcalf@tilera.com>
      Cc: Chris Zankel <chris@zankel.net>
      Cc: Christoph Lameter <cl@linux.com>
      Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Li Zefan <lizefan@huawei.com>
      Cc: Max Filippov <jcmvbkbc@gmail.com>
      Cc: Mike Travis <travis@sgi.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Steffen Klassert <steffen.klassert@secunet.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tony Luck <tony.luck@intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      dbc760bc
  8. 13 2月, 2015 3 次提交
  9. 14 10月, 2014 1 次提交
  10. 09 9月, 2014 1 次提交
  11. 05 6月, 2014 1 次提交
  12. 04 4月, 2014 1 次提交
  13. 27 2月, 2014 1 次提交
    • B
      vsprintf: Add support for IORESOURCE_UNSET in %pR · d19cb803
      Bjorn Helgaas 提交于
      Sometimes we have a struct resource where we know the type (MEM/IO/etc.)
      and the size, but we haven't assigned address space for it.  The
      IORESOURCE_UNSET flag is a way to indicate this situation.  For these
      "unset" resources, the start address is meaningless, so print only the
      size, e.g.,
      
        - pci 0000:0c:00.0: reg 184: [mem 0x00000000-0x00001fff 64bit]
        + pci 0000:0c:00.0: reg 184: [mem size 0x2000 64bit]
      
      For %pr (printing with raw flags), we still print the address range,
      because %pr is mostly used for debugging anyway.
      
      Thanks to Fengguang Wu <fengguang.wu@intel.com> for suggesting
      resource_size().
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      d19cb803
  14. 24 1月, 2014 1 次提交
  15. 15 11月, 2013 1 次提交
    • K
      vsprintf: ignore %n again · 9196436a
      Kees Cook 提交于
      This ignores %n in printf again, as was originally documented.
      Implementing %n poses a greater security risk than utility, so it should
      stay ignored.  To help anyone attempting to use %n, a warning will be
      emitted if it is encountered.
      
      Based on an earlier patch by Joe Perches.
      
      Because %n was designed to write to pointers on the stack, it has been
      frequently used as an attack vector when bugs are found that leak
      user-controlled strings into functions that ultimately process format
      strings.  While this class of bug can still be turned into an
      information leak, removing %n eliminates the common method of elevating
      such a bug into an arbitrary kernel memory writing primitive,
      significantly reducing the danger of this class of bug.
      
      For seq_file users that need to know the length of a written string for
      padding, please see seq_setwidth() and seq_pad() instead.
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Cc: Joe Perches <joe@perches.com>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: David Miller <davem@davemloft.net>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9196436a
  16. 13 11月, 2013 2 次提交
    • O
      lib/vsprintf.c: document formats for dentry and struct file · c0d92a57
      Olof Johansson 提交于
      Looks like these were added to Documentation/printk-formats.txt but
      not the in-file table.
      Signed-off-by: NOlof Johansson <olof@lixom.net>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      c0d92a57
    • R
      vsprintf: check real user/group id for %pK · 312b4e22
      Ryan Mallon 提交于
      Some setuid binaries will allow reading of files which have read
      permission by the real user id.  This is problematic with files which
      use %pK because the file access permission is checked at open() time,
      but the kptr_restrict setting is checked at read() time.  If a setuid
      binary opens a %pK file as an unprivileged user, and then elevates
      permissions before reading the file, then kernel pointer values may be
      leaked.
      
      This happens for example with the setuid pppd application on Ubuntu 12.04:
      
        $ head -1 /proc/kallsyms
        00000000 T startup_32
      
        $ pppd file /proc/kallsyms
        pppd: In file /proc/kallsyms: unrecognized option 'c1000000'
      
      This will only leak the pointer value from the first line, but other
      setuid binaries may leak more information.
      
      Fix this by adding a check that in addition to the current process having
      CAP_SYSLOG, that effective user and group ids are equal to the real ids.
      If a setuid binary reads the contents of a file which uses %pK then the
      pointer values will be printed as NULL if the real user is unprivileged.
      
      Update the sysctl documentation to reflect the changes, and also correct
      the documentation to state the kptr_restrict=0 is the default.
      
      This is a only temporary solution to the issue.  The correct solution is
      to do the permission check at open() time on files, and to replace %pK
      with a function which checks the open() time permission.  %pK uses in
      printk should be removed since no sane permission check can be done, and
      instead protected by using dmesg_restrict.
      Signed-off-by: NRyan Mallon <rmallon@gmail.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Joe Perches <joe@perches.com>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      312b4e22
  17. 04 9月, 2013 1 次提交
    • A
      add formats for dentry/file pathnames · 4b6ccca7
      Al Viro 提交于
      New formats: %p[dD][234]?.  The next pointer is interpreted as struct dentry *
      or struct file * resp. ('d' => dentry, 'D' => file) and the last component(s)
      of pathname are printed (%pd => just the last one, %pd2 => the last two, etc.)
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      4b6ccca7
  18. 02 7月, 2013 1 次提交
    • D
      lib: vsprintf: add IPv4/v6 generic %p[Ii]S[pfs] format specifier · 10679643
      Daniel Borkmann 提交于
      In order to avoid making code that deals with printing both, IPv4 and
      IPv6 addresses, unnecessary complicated as for example ...
      
        if (sa.sa_family == AF_INET6)
          printk("... %pI6 ...", ..sin6_addr);
        else
          printk("... %pI4 ...", ..sin_addr.s_addr);
      
      ... it would be better to introduce a format specifier that can deal
      with those kind of situations internally; just as we have a "struct
      sockaddr" for generic mapping into "struct sockaddr_in" or "struct
      sockaddr_in6" as e.g. done in "union sctp_addr". Then, we could
      reduce the above statement into something like:
      
        printk("... %pIS ..", &sockaddr);
      
      In case our pointer is NULL, pointer() then deals with that already at
      an earlier point in time internally. While we're at it, support for both
      %piS/%pIS, where 'S' stands for sockaddr, comes (almost) for free.
      
      Additionally to that, postfix specifiers 'p', 'f' and 's' are supported
      as suggested and initially implemented in 2009 by Joe Perches [1].
      Handling of those additional specifiers orientate on the initial RFC that
      was proposed. Also we support IPv6 compressed format specified by 'c' and
      various other IPv4 extensions as stated in the documentation part.
      
      Likely, there are many other areas than just SCTP in the kernel to make
      use of this extension as well.
      
       [1] http://patchwork.ozlabs.org/patch/31480/Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
      CC: Joe Perches <joe@perches.com>
      CC: linux-kernel@vger.kernel.org
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      10679643
  19. 29 5月, 2013 1 次提交
  20. 01 5月, 2013 1 次提交
    • J
      vsprintf: Add extension %pSR - print_symbol replacement · b0d33c2b
      Joe Perches 提交于
      print_symbol takes a long and converts it to a function
      name and offset.  %pS does something similar, but doesn't
      translate the address via __builtin_extract_return_addr.
      %pSR does the translation.
      
      This will enable replacing multiple calls like
      	printk(...);
      	printk_symbol(addr);
      	printk("\n");
      with a single non-interleavable in dmesg
      	printk("... %pSR\n", (void *)addr);
      
      Update documentation too.
      Signed-off-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      b0d33c2b
  21. 22 2月, 2013 1 次提交
  22. 18 12月, 2012 1 次提交