15 Aug, 2019

2 commits


21 May, 2019

1 commit

  • Add SPDX license identifiers to all files which:

    - Have no license information of any form

    - Have MODULE_LICENCE("GPL*") inside which was used in the initial
    scan/conversion to ignore the file

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0-only

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

08 May, 2019

1 commit

  • Pull printk updates from Petr Mladek:

    - Allow state reset of printk_once() calls.

    - Prevent crashes when dereferencing invalid pointers in vsprintf().
    Only the first byte is checked for simplicity.

    - Make vsprintf warnings consistent and inlined.

    - Treewide conversion of obsolete %pf, %pF to %ps, %pF printf
    modifiers.

    - Some clean up of vsprintf and test_printf code.

    * tag 'printk-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    lib/vsprintf: Make function pointer_string static
    vsprintf: Limit the length of inlined error messages
    vsprintf: Avoid confusion between invalid address and value
    vsprintf: Prevent crash when dereferencing invalid pointers
    vsprintf: Consolidate handling of unknown pointer specifiers
    vsprintf: Factor out %pO handler as kobject_string()
    vsprintf: Factor out %pV handler as va_format()
    vsprintf: Factor out %p[iI] handler as ip_addr_string()
    vsprintf: Do not check address of well-known strings
    vsprintf: Consistent %pK handling for kptr_restrict == 0
    vsprintf: Shuffle restricted_pointer()
    printk: Tie printk_once / printk_deferred_once into .data.once for reset
    treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively
    lib/test_printf: Switch to bitmap_zalloc()

    Linus Torvalds
     

06 May, 2019

1 commit


26 Apr, 2019

2 commits

  • We already prevent crash when dereferencing some obviously broken
    pointers. But the handling is not consistent. Sometimes we print "(null)"
    only for pure NULL pointer, sometimes for pointers in the first
    page and sometimes also for pointers in the last page (error codes).

    Note that printk() call this code under logbuf_lock. Any recursive
    printks are redirected to the printk_safe implementation and the messages
    are stored into per-CPU buffers. These buffers might be eventually flushed
    in printk_safe_flush_on_panic() but it is not guaranteed.

    This patch adds a check using probe_kernel_read(). It is not a full-proof
    test. But it should help to see the error message in 99% situations where
    the kernel would silently crash otherwise.

    Also it makes the error handling unified for "%s" and the many %p*
    specifiers that need to read the data from a given address. We print:

    + (null) when accessing data on pure pure NULL address
    + (efault) when accessing data on an invalid address

    It does not affect the %p* specifiers that just print the given address
    in some form, namely %pF, %pf, %pS, %ps, %pB, %pK, %px, and plain %p.

    Note that we print (efault) from security reasons. In fact, the real
    address can be seen only by %px or eventually %pK.

    Link: http://lkml.kernel.org/r/20190417115350.20479-9-pmladek@suse.com
    To: Rasmus Villemoes
    Cc: Linus Torvalds
    Cc: "Tobin C . Harding"
    Cc: Joe Perches
    Cc: Andrew Morton
    Cc: Michal Hocko
    Cc: Steven Rostedt
    Cc: Sergey Senozhatsky
    Cc: linux-kernel@vger.kernel.org
    Reviewed-by: Sergey Senozhatsky
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Petr Mladek

    Petr Mladek
     
  • There are few printk formats that make sense only with two or more
    specifiers. Also some specifiers make sense only when a kernel feature
    is enabled.

    The handling of unknown specifiers is inconsistent and not helpful.
    Using WARN() looks like an overkill for this type of error. pr_warn()
    is not good either. It would by handled via printk_safe buffer and
    it might be hard to match it with the problematic string.

    A reasonable compromise seems to be writing the unknown format specifier
    into the original string with a question mark, for example (%pC?).
    It should be self-explaining enough. Note that it is in brackets
    to follow the (null) style.

    Note that it introduces a warning about that test_hashed() function
    is unused. It is going to be used again by a later patch.

    Link: http://lkml.kernel.org/r/20190417115350.20479-8-pmladek@suse.com
    To: Rasmus Villemoes
    Cc: Linus Torvalds
    Cc: "Tobin C . Harding"
    Cc: Joe Perches
    Cc: Andrew Morton
    Cc: Michal Hocko
    Cc: Steven Rostedt
    Cc: Sergey Senozhatsky
    Cc: linux-kernel@vger.kernel.org
    Reviewed-by: Sergey Senozhatsky
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Petr Mladek

    Petr Mladek
     

09 Apr, 2019

2 commits

  • We just added a new C header file for use with test modules that are
    intended to be run with kselftest. We can reduce code duplication by
    using this header.

    Use new kselftest header to reduce code duplication in test_printf and
    test_bitmap test modules.

    Acked-by: Kees Cook
    Signed-off-by: Tobin C. Harding
    Signed-off-by: Shuah Khan

    Tobin C. Harding
     
  • Currently the test_printf module does not have an exit function, this
    prevents the module from being unloaded. If we cannot unload the
    module we cannot run the tests a second time.

    Add an empty exit function.

    Acked-by: Kees Cook
    Signed-off-by: Tobin C. Harding
    Signed-off-by: Shuah Khan

    Tobin C. Harding
     

20 Mar, 2019

1 commit

  • Switch to bitmap_zalloc() to show clearly what we are allocating.
    Besides that it returns pointer of bitmap type instead of opaque void *.

    Link: http://lkml.kernel.org/r/20190304100009.65147-1-andriy.shevchenko@linux.intel.com
    To: linux-kernel@vger.kernel.org
    To: Andrew Morton
    To: linux@rasmusvillemoes.dk
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     

11 Dec, 2018

1 commit

  • There are users which print time and date represented by content of
    struct rtc_time in human readable format.

    Instead of open coding that each time introduce %ptR[dt][r] specifier.

    Cc: Arnd Bergmann
    Cc: Bartlomiej Zolnierkiewicz
    Cc: Dmitry Torokhov
    Cc: Geert Uytterhoeven
    Cc: Guan Xuetao
    Cc: Ingo Molnar
    Cc: Jason Wessel
    Cc: Jonathan Corbet
    Cc: Jonathan Hunter
    Cc: Krzysztof Kozlowski
    Cc: "Rafael J. Wysocki"
    Cc: Thierry Reding
    Cc: Petr Mladek
    Signed-off-by: Andy Shevchenko
    Reviewed-by: Petr Mladek
    Signed-off-by: Alexandre Belloni

    Andy Shevchenko
     

15 Jun, 2018

1 commit

  • If the test_printf module is loaded before the crng is initialized, the
    plain 'p' tests will fail because the printed address will not be hashed
    and the buffer will contain "(____ptrval____)" or "(ptrval)" instead
    (64-bit vs 32-bit).
    Since we cannot wait for the crng to be initialized for an undefined
    time, both plain 'p' tests now accept the strings "(____ptrval____)" or
    "(ptrval)" as a valid result and print a warning message.

    Link: http://lkml.kernel.org/r/20180613171840.29827-1-thierry.escande@linaro.org
    Fixes: ad67b74d2469d9b82 ("printk: hash addresses printed with %p")
    To: Andrew Morton
    To: David Miller
    Cc: Rasmus Villemoes
    Cc: "Tobin C . Harding"
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Thierry Escande
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Petr Mladek

    Thierry Escande
     

11 Apr, 2018

1 commit

  • Sparse complains that constant is so big for unsigned long on 64-bit
    architecture.

    lib/test_printf.c:217:54: warning: constant 0xffff0123456789ab is so big it is unsigned long
    lib/test_printf.c:246:54: warning: constant 0xffff0123456789ab is so big it is unsigned long

    To satisfy everyone, mark the constant with UL.

    Link: http://lkml.kernel.org/r/20180216210711.79901-1-andriy.shevchenko@linux.intel.com
    To: "Tobin C . Harding"
    To: linux@rasmusvillemoes.dk
    To: Joe Perches
    To: linux-kernel@vger.kernel.org
    To: Andrew Morton
    Signed-off-by: Andy Shevchenko
    [pmladek@suse.com: Changed from ULL to UL as suggested by Luc Van Oostenryck ]
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     

29 Nov, 2017

1 commit

  • Currently there exist approximately 14 000 places in the kernel where
    addresses are being printed using an unadorned %p. This potentially
    leaks sensitive information regarding the Kernel layout in memory. Many
    of these calls are stale, instead of fixing every call lets hash the
    address by default before printing. This will of course break some
    users, forcing code printing needed addresses to be updated.

    Code that _really_ needs the address will soon be able to use the new
    printk specifier %px to print the address.

    For what it's worth, usage of unadorned %p can be broken down as
    follows (thanks to Joe Perches).

    $ git grep -E '%p[^A-Za-z0-9]' | cut -f1 -d"/" | sort | uniq -c
    1084 arch
    20 block
    10 crypto
    32 Documentation
    8121 drivers
    1221 fs
    143 include
    101 kernel
    69 lib
    100 mm
    1510 net
    40 samples
    7 scripts
    11 security
    166 sound
    152 tools
    2 virt

    Add function ptr_to_id() to map an address to a 32 bit unique
    identifier. Hash any unadorned usage of specifier %p and any malformed
    specifiers.

    Signed-off-by: Tobin C. Harding

    Tobin C. Harding
     

16 Mar, 2016

1 commit

  • In mm we use several kinds of flags bitfields that are sometimes printed
    for debugging purposes, or exported to userspace via sysfs. To make
    them easier to interpret independently on kernel version and config, we
    want to dump also the symbolic flag names. So far this has been done
    with repeated calls to pr_cont(), which is unreliable on SMP, and not
    usable for e.g. sysfs export.

    To get a more reliable and universal solution, this patch extends
    printk() format string for pointers to handle the page flags (%pGp),
    gfp_flags (%pGg) and vma flags (%pGv). Existing users of
    dump_flag_names() are converted and simplified.

    It would be possible to pass flags by value instead of pointer, but the
    %p format string for pointers already has extensions for various kernel
    structures, so it's a good fit, and the extra indirection in a
    non-critical path is negligible.

    [linux@rasmusvillemoes.dk: lots of good implementation suggestions]
    Signed-off-by: Vlastimil Babka
    Acked-by: Michal Hocko
    Cc: Steven Rostedt
    Cc: Peter Zijlstra
    Cc: Arnaldo Carvalho de Melo
    Cc: Ingo Molnar
    Cc: Rasmus Villemoes
    Cc: Joonsoo Kim
    Cc: Minchan Kim
    Cc: Sasha Levin
    Cc: "Kirill A. Shutemov"
    Cc: Mel Gorman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vlastimil Babka
     

17 Jan, 2016

7 commits

  • Signed-off-by: Rasmus Villemoes
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Kees Cook
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • Following "lib/vsprintf.c: expand field_width to 24 bits", let's add a
    test to see that we now actually support bitmaps with 65536 bits.

    Signed-off-by: Rasmus Villemoes
    Acked-by: Kees Cook
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • These should also count as performed tests.

    Signed-off-by: Rasmus Villemoes
    Acked-by: Kees Cook
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • This adds a few tests to test_number, one of which serves to document
    another deviation from POSIX/C99 (printing 0 with an explicit precision
    of 0).

    Signed-off-by: Rasmus Villemoes
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Kees Cook
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • The kernel's printf doesn't follow the standards in a few corner cases
    (which are probably mostly irrelevant). Add tests that document the
    current behaviour.

    Signed-off-by: Rasmus Villemoes
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Kees Cook
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • Add a few padding bytes on either side of the test buffer, and check
    that these (and the part of the buffer not used) are untouched by
    vsnprintf.

    Signed-off-by: Rasmus Villemoes
    Acked-by: Kees Cook
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     
  • BUG is a completely unnecessarily big hammer, and we're more likely to
    get the internal bug reported if we just pr_err() and ensure the test
    suite fails.

    Signed-off-by: Rasmus Villemoes
    Acked-by: Kees Cook
    Cc: Al Viro
    Cc: Andy Shevchenko
    Cc: Ingo Molnar
    Cc: Joe Perches
    Cc: Maurizio Lombardi
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes
     

07 Nov, 2015

1 commit

  • This adds a simple module for testing the kernel's printf facilities.
    Previously, some %p extensions have caused a wrong return value in case
    the entire output didn't fit and/or been unusable in kasprintf(). This
    should help catch such issues. Also, it should help ensure that changes
    to the formatting algorithms don't break anything.

    I'm not sure if we have a struct dentry or struct file lying around at
    boot time or if we can fake one, but most %p extensions should be
    testable, as should the ordinary number and string formatting.

    The nature of vararg functions means we can't use a more conventional
    table-driven approach.

    For now, this is mostly a skeleton; contributions are very
    welcome. Some tests are/will be slightly annoying to write, since the
    expected output depends on stuff like CONFIG_*, sizeof(long), runtime
    values etc.

    Signed-off-by: Rasmus Villemoes
    Reviewed-by: Kees Cook
    Cc: Andy Shevchenko
    Cc: Martin Kletzander
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rasmus Villemoes