1. 28 May, 2013 1 commit
  2. 30 Apr, 2013 1 commit
    • Joe Perches's avatar
      vsprintf: Add extension %pSR - print_symbol replacement · b0d33c2b
      Joe Perches authored
      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
      with a single non-interleavable in dmesg
      	printk("... %pSR\n", (void *)addr);
      Update documentation too.
      Signed-off-by: 's avatarJoe Perches <joe@perches.com>
      Signed-off-by: 's avatarJiri Kosina <jkosina@suse.cz>
  3. 22 Feb, 2013 1 commit
  4. 18 Dec, 2012 3 commits
  5. 05 Oct, 2012 6 commits
  6. 31 Jul, 2012 4 commits
  7. 01 Jun, 2012 2 commits
    • Denys Vlasenko's avatar
      vsprintf: further optimize decimal conversion · 133fd9f5
      Denys Vlasenko authored
      Previous code was using optimizations which were developed to work well
      even on narrow-word CPUs (by today's standards).  But Linux runs only on
      32-bit and wider CPUs.  We can use that.
      First: using 32x32->64 multiply and trivial 32-bit shift, we can correctly
      divide by 10 much larger numbers, and thus we can print groups of 9 digits
      instead of groups of 5 digits.
      Next: there are two algorithms to print larger numbers.  One is generic:
      divide by 1000000000 and repeatedly print groups of (up to) 9 digits.
      It's conceptually simple, but requires an (unsigned long long) /
      1000000000 division.
      Second algorithm splits 64-bit unsigned long long into 16-bit chunks,
      manipulates them cleverly and generates groups of 4 decimal digits.  It so
      happens that it does NOT require long long division.
      If long is > 32 bits, division of 64-bit values is relatively easy, and we
      will use the first algorithm.  If long long is > 64 bits (strange
      architecture with VERY large long long), second algorithm can't be used,
      and we again use the first one.
      Else (if long is 32 bits and long long is 64 bits) we use second one.
      And third: there is a simple optimization which takes fast path not only
      for zero as was done before, but for all one-digit numbers.
      In all tested cases new code is faster than old one, in many cases by 30%,
      in few cases by more than 50% (for example, on x86-32, conversion of
      12345678).  Code growth is ~0 in 32-bit case and ~130 bytes in 64-bit
      This patch is based upon an original from Michal Nazarewicz.
      [akpm@linux-foundation.org: checkpatch fixes]
      Signed-off-by: 's avatarMichal Nazarewicz <mina86@mina86.com>
      Signed-off-by: 's avatarDenys Vlasenko <vda.linux@googlemail.com>
      Cc: Douglas W Jones <jones@cs.uiowa.edu>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Grant Likely's avatar
      vsprintf: correctly handle width when '#' flag used in %#p format · 725fe002
      Grant Likely authored
      The '%p' output of the kernel's vsprintf() uses spec.field_width to
      determine how many digits to output based on 2 * sizeof(void*) so that all
      digits of a pointer are shown.  ie.  a pointer will be output as
      "001A2B3C" instead of "1A2B3C".  However, if the '#' flag is used in the
      format (%#p), then the code doesn't take into account the width of the
      '0x' prefix and will end up outputing "0x1A2B3C" instead of "0x001A2B3C".
      This patch reworks the "pointer()" format hook to include 2 characters for
      the '0x' prefix if the '#' flag is included.
      [akpm@linux-foundation.org: checkpatch fixes]
      Signed-off-by: 's avatarGrant Likely <grant.likely@secretlab.ca>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  8. 29 May, 2012 2 commits
  9. 23 Mar, 2012 1 commit
    • KAMEZAWA Hiroyuki's avatar
      procfs: add num_to_str() to speed up /proc/stat · 1ac101a5
      KAMEZAWA Hiroyuki authored
      == stat_check.py
      num = 0
      with open("/proc/stat") as f:
              while num < 1000 :
                      data = f.read()
                      f.seek(0, 0)
                      num = num + 1
      perf shows
          20.39%  stat_check.py  [kernel.kallsyms]    [k] format_decode
          13.41%  stat_check.py  [kernel.kallsyms]    [k] number
          12.61%  stat_check.py  [kernel.kallsyms]    [k] vsnprintf
          10.85%  stat_check.py  [kernel.kallsyms]    [k] memcpy
           4.85%  stat_check.py  [kernel.kallsyms]    [k] radix_tree_lookup
           4.43%  stat_check.py  [kernel.kallsyms]    [k] seq_printf
      This patch removes most of calls to vsnprintf() by adding num_to_str()
      and seq_print_decimal_ull(), which prints decimal numbers without rich
      functions provided by printf().
      On my 8cpu box.
      == Before patch ==
      [root@bluextal test]# time ./stat_check.py
      real    0m0.150s
      user    0m0.026s
      sys     0m0.121s
      == After patch ==
      [root@bluextal test]# time ./stat_check.py
      real    0m0.055s
      user    0m0.022s
      sys     0m0.030s
      [akpm@linux-foundation.org: remove incorrect comment, use less statck in num_to_str(), move comment from .h to .c, simplify seq_put_decimal_ull()]
      [andrea@betterlinux.com: avoid breaking the ABI in /proc/stat]
      Signed-off-by: 's avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
      Signed-off-by: 's avatarAndrea Righi <andrea@betterlinux.com>
      Cc: Eric Dumazet <eric.dumazet@gmail.com>
      Cc: Glauber Costa <glommer@parallels.com>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Paul Turner <pjt@google.com>
      Cc: Russell King <rmk@arm.linux.org.uk>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  10. 07 Mar, 2012 1 commit
  11. 06 Mar, 2012 1 commit
    • Jan Beulich's avatar
      vsprintf: make %pV handling compatible with kasprintf() · 5756b76e
      Jan Beulich authored
      kasprintf() (and potentially other functions that I didn't run across so
      far) want to evaluate argument lists twice.  Caring to do so for the
      primary list is obviously their job, but they can't reasonably be
      expected to check the format string for instances of %pV, which however
      need special handling too: On architectures like x86-64 (as opposed to
      e.g.  ix86), using the same argument list twice doesn't produce the
      expected results, as an internally managed cursor gets updated during
      the first run.
      Fix the problem by always acting on a copy of the original list when
      handling %pV.
      Signed-off-by: 's avatarJan Beulich <jbeulich@suse.com>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  12. 16 Nov, 2011 1 commit
  13. 01 Nov, 2011 2 commits
  14. 26 Jul, 2011 1 commit
  15. 14 Jul, 2011 1 commit
  16. 09 Jun, 2011 1 commit
  17. 25 May, 2011 1 commit
  18. 12 May, 2011 1 commit
    • Ingo Molnar's avatar
      vsprintf: Turn kptr_restrict off by default · 411f05f1
      Ingo Molnar authored
      kptr_restrict has been triggering bugs in apps such as perf, and it also makes
      the system less useful by default, so turn it off by default.
      This is how we generally handle security features that remove functionality,
      such as firewall code or SELinux - they have to be configured and activated
      from user-space.
      Distributions can turn kptr_restrict on again via this line in
      kernel.kptr_restrict = 1
      ( Also mark the variable __read_mostly while at it, as it's typically modified
        only once per bootup, or not at all. )
      Signed-off-by: 's avatarIngo Molnar <mingo@elte.hu>
      Acked-by: 's avatarDavid S. Miller <davem@davemloft.net>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  19. 06 Apr, 2011 1 commit
  20. 24 Mar, 2011 1 commit
    • Namhyung Kim's avatar
      vsprintf: Introduce %pB format specifier · 0f77a8d3
      Namhyung Kim authored
      The %pB format specifier is for stack backtrace. Its handler
      sprint_backtrace() does symbol lookup using (address-1) to
      ensure the address will not point outside of the function.
      If there is a tail-call to the function marked "noreturn",
      gcc optimized out the code after the call then causes saved
      return address points outside of the function (i.e. the start
      of the next function), so pollutes call trace somewhat.
      This patch adds the %pB printk mechanism that allows architecture
      call-trace printout functions to improve backtrace printouts.
      Signed-off-by: 's avatarNamhyung Kim <namhyung@gmail.com>
      Acked-by: 's avatarSteven Rostedt <rostedt@goodmis.org>
      Acked-by: 's avatarFrederic Weisbecker <fweisbec@gmail.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: linux-arch@vger.kernel.org
      LKML-Reference: <1300934550-21394-1-git-send-email-namhyung@gmail.com>
      Signed-off-by: 's avatarIngo Molnar <mingo@elte.hu>
  21. 23 Mar, 2011 3 commits
    • Alexey Dobriyan's avatar
      kstrto*: converting strings to integers done (hopefully) right · 33ee3b2e
      Alexey Dobriyan authored
      1. simple_strto*() do not contain overflow checks and crufty,
         libc way to indicate failure.
      2. strict_strto*() also do not have overflow checks but the name and
         comments pretend they do.
      3. Both families have only "long long" and "long" variants,
         but users want strtou8()
      4. Both "simple" and "strict" prefixes are wrong:
         Simple doesn't exactly say what's so simple, strict should not exist
         because conversion should be strict by default.
      The solution is to use "k" prefix and add convertors for more types.
      Include runtime testsuite (somewhat incomplete) as well.
      strict_strto*() become deprecated, stubbed to kstrto*() and
      eventually will be removed altogether.
      Use kstrto*() in code today!
      Note: on some archs _kstrtoul() and _kstrtol() are left in tree, even if
            they'll be unused at runtime. This is temporarily solution,
            because I don't want to hardcode list of archs where these
            functions aren't needed. Current solution with sizeof() and
            __alignof__ at least always works.
      Signed-off-by: 's avatarAlexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Kees Cook's avatar
      printk: use %pK for /proc/kallsyms and /proc/modules · 9f36e2c4
      Kees Cook authored
      In an effort to reduce kernel address leaks that might be used to help
      target kernel privilege escalation exploits, this patch uses %pK when
      displaying addresses in /proc/kallsyms, /proc/modules, and
      Note that this changes %x to %p, so some legitimately 0 values in
      /proc/kallsyms would have changed from 00000000 to "(null)".  To avoid
      this, "(null)" is not used when using the "K" format.  Anything that was
      already successfully parsing "(null)" in addition to full hex digits
      should have no problem with this change.  (Thanks to Joe Perches for the
      suggestion.) Due to the %x to %p, "void *" casts are needed since these
      addresses are already "unsigned long" everywhere internally, due to their
      starting life as ELF section offsets.
      Signed-off-by: 's avatarKees Cook <kees.cook@canonical.com>
      Cc: Eugene Teo <eugene@redhat.com>
      Cc: Dan Rosenberg <drosenberg@vsecurity.com>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Joe Perches's avatar
      vsprintf: neaten %pK kptr_restrict, save a bit of code space · 26297607
      Joe Perches authored
      If kptr restrictions are on, just set the passed pointer to NULL.
      $ size lib/vsprintf.o.*
         text	   data	    bss	    dec	    hex	filename
         8247	      4	      2	   8253	   203d	lib/vsprintf.o.new
         8282	      4	      2	   8288	   2060	lib/vsprintf.o.old
      Signed-off-by: 's avatarJoe Perches <joe@perches.com>
      Cc: Dan Rosenberg <drosenberg@vsecurity.com>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  22. 13 Jan, 2011 2 commits
    • Anton Arapov's avatar
      lib/vsprintf.c: fix vscnprintf() if @size is == 0 · b921c69f
      Anton Arapov authored
      vscnprintf() should return 0 if @size is == 0.  Update the comment for it,
      as @size is unsigned.
      This change based on the code of commit
      b903c0b8 ("lib: fix scnprintf() if @size
      is == 0") moves the real fix into vscnprinf() from scnprintf() and makes
      scnprintf() call vscnprintf(), thus avoid code duplication.
      Signed-off-by: 's avatarAnton Arapov <aarapov@redhat.com>
      Acked-by: 's avatarChangli Gao <xiaosuo@gmail.com>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Dan Rosenberg's avatar
      kptr_restrict for hiding kernel pointers from unprivileged users · 455cd5ab
      Dan Rosenberg authored
      Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
      The %pK format specifier is designed to hide exposed kernel pointers,
      specifically via /proc interfaces.  Exposing these pointers provides an
      easy target for kernel write vulnerabilities, since they reveal the
      locations of writable structures containing easily triggerable function
      pointers.  The behavior of %pK depends on the kptr_restrict sysctl.
      If kptr_restrict is set to 0, no deviation from the standard %p behavior
      occurs.  If kptr_restrict is set to 1, the default, if the current user
      (intended to be a reader via seq_printf(), etc.) does not have CAP_SYSLOG
      (currently in the LSM tree), kernel pointers using %pK are printed as 0's.
       If kptr_restrict is set to 2, kernel pointers using %pK are printed as
      0's regardless of privileges.  Replacing with 0's was chosen over the
      default "(null)", which cannot be parsed by userland %p, which expects
      [akpm@linux-foundation.org: check for IRQ context when !kptr_restrict, save an indent level, s/WARN/WARN_ONCE/]
      [akpm@linux-foundation.org: coding-style fixup]
      [randy.dunlap@oracle.com: fix kernel/sysctl.c warning]
      Signed-off-by: 's avatarDan Rosenberg <drosenberg@vsecurity.com>
      Signed-off-by: 's avatarRandy Dunlap <randy.dunlap@oracle.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: Eric Dumazet <eric.dumazet@gmail.com>
      Cc: Thomas Graf <tgraf@infradead.org>
      Cc: Eugene Teo <eugeneteo@kernel.org>
      Cc: Kees Cook <kees.cook@canonical.com>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: David S. Miller <davem@davemloft.net>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Cc: Eric Paris <eparis@parisplace.org>
      Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: 's avatarLinus Torvalds <torvalds@linux-foundation.org>
  23. 26 Oct, 2010 2 commits