26 Mar, 2011

1 commit


24 Mar, 2011

1 commit

  • 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: Namhyung Kim
    Acked-by: Steven Rostedt
    Acked-by: Frederic Weisbecker
    Cc: Linus Torvalds
    Cc: Andrew Morton
    Cc: linux-arch@vger.kernel.org
    LKML-Reference:
    Signed-off-by: Ingo Molnar

    Namhyung Kim
     

23 Mar, 2011

3 commits

  • 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.
    Enter
    kstrtoull()
    kstrtoll()
    kstrtoul()
    kstrtol()
    kstrtouint()
    kstrtoint()

    kstrtou64()
    kstrtos64()
    kstrtou32()
    kstrtos32()
    kstrtou16()
    kstrtos16()
    kstrtou8()
    kstrtos8()

    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: Alexey Dobriyan
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     
  • 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
    /sys/module/*/sections/*.

    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: Kees Cook
    Cc: Eugene Teo
    Cc: Dan Rosenberg
    Cc: Rusty Russell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     
  • 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: Joe Perches
    Cc: Dan Rosenberg
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

14 Jan, 2011

2 commits

  • 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
    b903c0b8899b46829a9b80ba55b61079b35940ec ("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: Anton Arapov
    Acked-by: Changli Gao
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Anton Arapov
     
  • Add the %pK printk format specifier and the /proc/sys/kernel/kptr_restrict
    sysctl.

    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
    "(nil)".

    [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: Dan Rosenberg
    Signed-off-by: Randy Dunlap
    Cc: James Morris
    Cc: Eric Dumazet
    Cc: Thomas Graf
    Cc: Eugene Teo
    Cc: Kees Cook
    Cc: Ingo Molnar
    Cc: David S. Miller
    Cc: Peter Zijlstra
    Cc: Eric Paris

    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Rosenberg
     

27 Oct, 2010

2 commits

  • scnprintf() should return 0 if @size is == 0. Update the comment for it,
    as @size is unsigned.

    Signed-off-by: Changli Gao
    Cc: Ingo Molnar
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Changli Gao
     
  • It might be nicer to align the output.

    For instance, ACPI messages sometimes have "(null)" pointers.

    $ dmesg | grep "(null)" -A 1 -B 1
    [ 0.198733] ACPI: Dynamic OEM Table Load:
    [ 0.198745] ACPI: SSDT (null) 00239 (v02 PmRef Cpu0Ist 00003000 INTL 20051117)
    [ 0.199294] ACPI: SSDT 7f596e10 001C7 (v02 PmRef Cpu0Cst 00003001 INTL 20051117)
    [ 0.200708] ACPI: Dynamic OEM Table Load:
    [ 0.200721] ACPI: SSDT (null) 001C7 (v02 PmRef Cpu0Cst 00003001 INTL 20051117)
    [ 0.201950] ACPI: SSDT 7f597f10 000D0 (v02 PmRef Cpu1Ist 00003000 INTL 20051117)
    [ 0.203386] ACPI: Dynamic OEM Table Load:
    [ 0.203398] ACPI: SSDT (null) 000D0 (v02 PmRef Cpu1Ist 00003000 INTL 20051117)
    [ 0.203871] ACPI: SSDT 7f595f10 00083 (v02 PmRef Cpu1Cst 00003000 INTL 20051117)
    [ 0.205301] ACPI: Dynamic OEM Table Load:
    [ 0.205315] ACPI: SSDT (null) 00083 (v02 PmRef Cpu1Cst 00003000 INTL 20051117)

    [akpm@linux-foundation.org: add code comment]
    Signed-off-by: Joe Perches
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

10 Aug, 2010

1 commit


05 Jul, 2010

1 commit

  • Add the ability to print a format and va_list from a structure pointer

    Allows __dev_printk to be implemented as a single printk while
    minimizing string space duplication.

    %pV should not be used without some mechanism to verify the
    format and argument use ala __attribute__(format (printf(...))).

    Signed-off-by: Joe Perches
    Acked-by: Greg Kroah-Hartman
    Signed-off-by: David S. Miller

    Joe Perches
     

25 May, 2010

2 commits

  • Mark static functions with noinline_for_stack

    Before:

    akpm:/usr/src/25> objdump -d lib/vsprintf.o | perl scripts/checkstack.pl
    0x00000e82 pointer [vsprintf.o]: 344
    0x0000198c pointer [vsprintf.o]: 344
    0x000025d6 scnprintf [vsprintf.o]: 216
    0x00002648 scnprintf [vsprintf.o]: 216
    0x00002565 snprintf [vsprintf.o]: 208
    0x0000267c sprintf [vsprintf.o]: 208
    0x000030a3 bprintf [vsprintf.o]: 208
    0x00003b1e sscanf [vsprintf.o]: 208
    0x00000608 number [vsprintf.o]: 136
    0x00000937 number [vsprintf.o]: 136

    After:

    akpm:/usr/src/25> objdump -d lib/vsprintf.o | perl scripts/checkstack.pl
    0x00000a7c symbol_string [vsprintf.o]: 248
    0x00000ae8 symbol_string [vsprintf.o]: 248
    0x00002310 scnprintf [vsprintf.o]: 216
    0x00002382 scnprintf [vsprintf.o]: 216
    0x0000229f snprintf [vsprintf.o]: 208
    0x000023b6 sprintf [vsprintf.o]: 208
    0x00002ddd bprintf [vsprintf.o]: 208
    0x00003858 sscanf [vsprintf.o]: 208
    0x00000625 number [vsprintf.o]: 136
    0x00000954 number [vsprintf.o]: 136

    Signed-off-by: Joe Perches
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     
  • - C99 knows about USHRT_MAX/SHRT_MAX/SHRT_MIN, not
    USHORT_MAX/SHORT_MAX/SHORT_MIN.

    - Make SHRT_MIN of type s16, not int, for consistency.

    [akpm@linux-foundation.org: fix drivers/dma/timb_dma.c]
    [akpm@linux-foundation.org: fix security/keys/keyring.c]
    Signed-off-by: Alexey Dobriyan
    Acked-by: WANG Cong
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

25 Apr, 2010

1 commit


15 Apr, 2010

1 commit

  • Commit ef0658f3de484bf9b173639cd47544584e01efa5 changed precision
    from int to s8.

    There is existing kernel code that uses a larger precision.

    An example from the audit code:
    vsnprintf(...,..., " msg='%.1024s'", (char *)data);
    which overflows precision and truncates to nothing.

    Extending precision size fixes the audit system issue.

    Other changes:

    Change the size of the struct printf_spec.type from u16 to u8 so
    sizeof(struct printf_spec) stays as small as possible.
    Reorder the struct members so sizeof(struct printf_spec) remains 64 bits
    without alignment holes.
    Document the struct members a bit more.

    Original-patch-by: Eric Paris
    Signed-off-by: Joe Perches
    Tested-by: Justin P. Mattock
    Signed-off-by: Linus Torvalds

    Joe Perches
     

15 Mar, 2010

2 commits


07 Mar, 2010

3 commits


23 Jan, 2010

1 commit


14 Jan, 2010

1 commit


12 Jan, 2010

1 commit


11 Jan, 2010

1 commit


08 Jan, 2010

1 commit

  • On Mon, 2010-01-04 at 23:43 +0000, Maciej W. Rozycki wrote:
    > The example below shows an address, and the sequence of bits or symbols
    > that would be transmitted when the address is used in the Source Address
    > or Destination Address fields on the MAC header. The transmission line
    > shows the address bits in the order transmitted, from left to right. For
    > IEEE 802 LANs these correspond to actual bits on the medium. The FDDI
    > symbols line shows how the FDDI PHY sends the address bits as encoded
    > symbols.
    >
    > MSB: 35:7B:12:00:00:01
    > Canonical: AC-DE-48-00-00-80
    > Transmission: 00110101 01111011 00010010 00000000 00000000 00000001
    > FDDI Symbols: 35 7B 12 00 00 01"
    >
    > Please note that this address has its group bit clear.
    >
    > This notation is also defined in the "FDDI MEDIA ACCESS CONTROL-2
    > (MAC-2)" (X3T9/92-120) document although that book does not have a need
    > to use the MSB form and it's skipped.

    Adds 6 bytes to object size for x86

    New:
    $ size lib/vsprintf.o
    text data bss dec hex filename
    8664 0 2 8666 21da lib/vsprintf.o
    $ size lib/vsprintf.o
    text data bss dec hex filename
    8658 0 2 8660 21d4 lib/vsprintf.o

    Signed-off-by: Joe Perches
    Signed-off-by: David S. Miller

    Joe Perches
     

18 Dec, 2009

1 commit

  • These were added in

    9ac6e44 (lib/vsprintf.c: add %pU to print UUID/GUIDs)
    c7dabef (vsprintf: use %pR, %pr instead of %pRt, %pRf)
    8a27f7c (lib/vsprintf.c: Add "%pI6c" - print pointer as compressed ipv6 address)
    4aa9960 (printk: add %I4, %I6, %i4, %i6 format specifiers)
    dd45c9c (printk: add %pM format specifier for MAC addresses)

    but only added comments to pointer() not vsnprintf() that is refered to by
    printk's comments.

    Signed-off-by: Uwe Kleine-König
    Cc: Harvey Harrison
    Cc: David S. Miller
    Cc: Joe Perches
    Cc: Jens Rosenboom
    Cc: David S. Miller
    Cc: Bjorn Helgaas
    Cc: Jesse Barnes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Uwe Kleine-König
     

16 Dec, 2009

10 commits

  • UUID/GUIDs are somewhat common in kernel source.

    Standardize the printed style of UUID/GUIDs by using
    another extension to %p.

    %pUb: 01020304-0506-0708-090a-0b0c0d0e0f10
    %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10 (upper case)
    %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10
    %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10 (upper case)

    %pU defaults to %pUb

    Signed-off-by: Joe Perches
    Cc: Jeff Garzik
    Cc: Tejun Heo
    Cc: Alex Elder
    Cc: Christoph Hellwig
    Cc: Artem Bityutskiy
    Cc: Adrian Hunter
    Cc: Steven Whitehouse
    Cc: Mauro Carvalho Chehab
    Cc: Matt Mackall
    Cc: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     
  • Makes use of skip_spaces() defined in lib/string.c for removing leading
    spaces from strings all over the tree.

    It decreases lib.a code size by 47 bytes and reuses the function tree-wide:
    text data bss dec hex filename
    64688 584 592 65864 10148 (TOTALS-BEFORE)
    64641 584 592 65817 10119 (TOTALS-AFTER)

    Also, while at it, if we see (*str && isspace(*str)), we can be sure to
    remove the first condition (*str) as the second one (isspace(*str)) also
    evaluates to 0 whenever *str == 0, making it redundant. In other words,
    "a char equals zero is never a space".

    Julia Lawall tried the semantic patch (http://coccinelle.lip6.fr) below,
    and found occurrences of this pattern on 3 more files:
    drivers/leds/led-class.c
    drivers/leds/ledtrig-timer.c
    drivers/video/output.c

    @@
    expression str;
    @@

    ( // ignore skip_spaces cases
    while (*str && isspace(*str)) { \(str++;\|++str;\) }
    |
    - *str &&
    isspace(*str)
    )

    Signed-off-by: André Goddard Rosa
    Cc: Julia Lawall
    Cc: Martin Schwidefsky
    Cc: Jeff Dike
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Cc: Richard Purdie
    Cc: Neil Brown
    Cc: Kyle McMartin
    Cc: Henrique de Moraes Holschuh
    Cc: David Howells
    Cc:
    Cc: Samuel Ortiz
    Cc: Patrick McHardy
    Cc: Takashi Iwai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • The difference between simple_strtoul() and simple_strtoull() is just
    the size of the variable used to keep track of the sum of characters
    converted to numbers:

    unsigned long simple_strtoul() {...}
    unsigned long long simple_strtoull(){...}

    Both are same size on my Core 2/gcc 4.4.1.
    Overflow condition is not checked on both functions, so an extremely large
    string can break these functions so that they don't even notice it.

    As we do not care for overflowing on these functions, always keep the sum
    using the larger variable around (unsigned long long) on simple_strtoull()
    and cast it to (unsigned long) on simple_strtoul(), which then becomes
    just a wrapper around simple_strtoull().

    Code size decreases by 304 bytes:
    text data bss dec hex filename
    15534 0 8 15542 3cb6 vsprintf.o (ex lib/lib.a-BEFORE)
    15230 0 8 15238 3b86 vsprintf.o (ex lib/lib.a-AFTER)

    Signed-off-by: André Goddard Rosa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • When converting more caller sites, the inline decision will be left up to gcc.

    It decreases code size:
    text data bss dec hex filename
    15710 0 8 15718 3d66 vsprintf.o (ex lib/lib.a-BEFORE)
    15534 0 8 15542 3cb6 vsprintf.o (ex lib/lib.a-AFTER)

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • Cleanup by moving variables closer to the scope where they're used in fact.
    Also, remove unneeded ones.

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • No functional change, just refactor the code so that it avoid checking
    "if (hi)" two times in a sequence, taking advantage of previous check made.

    It also reduces code size:
    text data bss dec hex filename
    15726 0 8 15734 3d76 vsprintf.o (ex lib/lib.a-BEFORE)
    15710 0 8 15718 3d66 vsprintf.o (ex lib/lib.a-AFTER)

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • It decreases code size as well:
    text data bss dec hex filename
    15758 0 8 15766 3d96 vsprintf.o (ex lib/lib.a-BEFORE)
    15726 0 8 15734 3d76 vsprintf.o (ex lib/lib.a-TOLOWER)

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • Most relevant complaints were addressed.

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     
  • This patchset reduces lib/lib.a code size by 482 bytes on my Core 2 with
    gcc 4.4.1 even considering that it exports a newly defined function
    skip_spaces() to drivers:

    text data bss dec hex filename
    64867 840 592 66299 102fb (TOTALS-lib.a-BEFORE)
    64641 584 592 65817 10119 (TOTALS-lib.a-AFTER)
    and implements some code tidy up.

    Besides reducing lib.a size, it converts many in-tree drivers to use the
    newly defined function, which makes another small reduction on kernel size
    overall when those drivers are used.

    This patch:

    Change "" to "(null)", unifying 3 equal strings.
    glibc also uses "(null)" for the same purpose.

    It decreases code size by 7 bytes:
    text data bss dec hex filename
    15765 0 8 15773 3d9d vsprintf.o (ex lib/lib.a-BEFORE)
    15758 0 8 15766 3d96 vsprintf.o (ex lib/lib.a-AFTER)

    Signed-off-by: André Goddard Rosa
    Acked-by: Frederic Weisbecker
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    André Goddard Rosa
     

05 Nov, 2009

4 commits

  • Jesse accidentally applied v1 [1] of the patchset instead of v2 [2]. This
    is the diff between v1 and v2.

    The changes in this patch are:
    - tidied vsprintf stack buffer to shrink and compute size more
    accurately
    - use %pR for decoding and %pr for "raw" (with type and flags) instead
    of adding %pRt and %pRf

    [1] http://lkml.org/lkml/2009/10/6/491
    [2] http://lkml.org/lkml/2009/10/13/441

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Jesse Barnes

    Bjorn Helgaas
     
  • This adds support for printing struct resource type and flag information.
    For example, "%pRt" looks like "[mem 0x80080000000-0x8008001ffff 64bit pref]",
    and "%pRf" looks like "[mem 0xff5e2000-0xff5e2007 pref flags 0x1]".

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Jesse Barnes

    Bjorn Helgaas
     
  • Print addresses (IO port numbers and memory addresses) in hex, but print
    others (IRQs and DMA channels) in decimal. Only print the end if it's
    different from the start.

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Jesse Barnes

    Bjorn Helgaas
     
  • The leading "0x" consumes field width, so leave space for it in addition to
    the 4 or 8 hex digits. This means we'll print "0x0000-0x01df" rather than
    "0x00-0x1df", for example.

    Signed-off-by: Bjorn Helgaas
    Signed-off-by: Jesse Barnes

    Bjorn Helgaas