05 Oct, 2018

1 commit

  • The functions vbin_printf() and bstr_printf() are used by trace_printk() to
    try to keep the overhead down during printing. trace_printk() uses
    vbin_printf() at the time of execution, as it only scans the fmt string to
    record the printf values into the buffer, and then uses vbin_printf() to do
    the conversions to print the string based on the format and the saved
    values in the buffer.

    This is an issue for dereferenced pointers, as before commit 841a915d20c7b,
    the processing of the pointer could happen some time after the pointer value
    was recorded (reading the trace buffer). This means the processing of the
    value at a later time could show different results, or even crash the
    system, if the pointer no longer existed.

    Commit 841a915d20c7b addressed this by processing dereferenced pointers at
    the time of execution and save the result in the ring buffer as a string.
    The bstr_printf() would then treat these pointers as normal strings, and
    print the value. But there was an off-by-one bug here, where after
    processing the argument, it move the pointer only "strlen(arg)" which made
    the arg pointer not point to the next argument in the ring buffer, but
    instead point to the nul character of the last argument. This causes any
    values after a dereferenced pointer to be corrupted.

    Cc: stable@vger.kernel.org
    Fixes: 841a915d20c7b ("vsprintf: Do not have bprintf dereference pointers")
    Reported-by: Nikolay Borisov
    Tested-by: Nikolay Borisov
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

16 Aug, 2018

1 commit

  • Pull random updates from Ted Ts'o:
    "Some changes to trust cpu-based hwrng (such as RDRAND) for
    initializing hashed pointers and (optionally, controlled by a config
    option) to initialize the CRNG to avoid boot hangs"

    * tag 'random_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random:
    random: Make crng state queryable
    random: remove preempt disabled region
    random: add a config option to trust the CPU's hwrng
    vsprintf: Add command line option debug_boot_weak_hash
    vsprintf: Use hw RNG for ptr_key
    random: Return nbytes filled from hw RNG
    random: Fix whitespace pre random-bytes work

    Linus Torvalds
     

07 Aug, 2018

1 commit

  • This patch avoids that gcc reports the following when building with W=1:

    lib/vsprintf.c:1941:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
    switch (fmt[1]) {
    ^~~~~~

    Fixes: 7b1924a1d930eb2 ("vsprintf: add printk specifier %px")
    Link: http://lkml.kernel.org/r/20180806223421.11995-1-bart.vanassche@wdc.com
    Cc: linux-kernel@vger.kernel.org
    Cc: Bart Van Assche
    Cc: Pantelis Antoniou
    Cc: Joe Perches
    Cc: Rob Herring
    Cc: v4.15+
    Signed-off-by: Bart Van Assche
    Signed-off-by: Petr Mladek

    Bart Van Assche
     

18 Jul, 2018

2 commits

  • Currently printing [hashed] pointers requires enough entropy to be
    available. Early in the boot sequence this may not be the case
    resulting in a dummy string '(____ptrval____)' being printed. This
    makes debugging the early boot sequence difficult. We can relax the
    requirement to use cryptographically secure hashing during debugging.
    This enables debugging while keeping development/production kernel
    behaviour the same.

    If new command line option debug_boot_weak_hash is enabled use
    cryptographically insecure hashing and hash pointer value immediately.

    Reviewed-by: Steven Rostedt (VMware)
    Signed-off-by: Tobin C. Harding
    Signed-off-by: Theodore Ts'o

    Tobin C. Harding
     
  • Currently we must wait for enough entropy to become available before
    hashed pointers can be printed. We can remove this wait by using the
    hw RNG if available.

    Use hw RNG to get keying material.

    Reviewed-by: Steven Rostedt (VMware)
    Suggested-by: Kees Cook
    Signed-off-by: Tobin C. Harding
    Signed-off-by: Theodore Ts'o

    Tobin C. Harding
     

07 Jun, 2018

1 commit

  • Pull printk updates from Petr Mladek:

    - Help userspace log daemons to catch up with a flood of messages. They
    will get woken after each message even if the console is far behind
    and handled by another process.

    - Flush printk safe buffers safely even when panic() happens in the
    normal context.

    - Fix possible va_list reuse when race happened in printk_safe().

    - Remove %pCr printf format to prevent sleeping in the atomic context.

    - Misc vsprintf code cleanup.

    * tag 'printk-for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk:
    printk: drop in_nmi check from printk_safe_flush_on_panic()
    lib/vsprintf: Remove atomic-unsafe support for %pCr
    serial: sh-sci: Stop using printk format %pCr
    thermal: bcm2835: Stop using printk format %pCr
    clk: renesas: cpg-mssr: Stop using printk format %pCr
    printk: fix possible reuse of va_list variable
    printk: wake up klogd in vprintk_emit
    vsprintf: Tweak pF/pf comment
    lib/vsprintf: Mark expected switch fall-through
    lib/vsprintf: Replace space with '_' before crng is ready
    lib/vsprintf: Deduplicate pointer_string()
    lib/vsprintf: Move pointer_string() upper
    lib/vsprintf: Make flag_spec global
    lib/vsprintf: Make strspec global
    lib/vsprintf: Make dec_spec global
    lib/test_printf: Mark big constant with UL

    Linus Torvalds
     

05 Jun, 2018

2 commits

  • Petr Mladek
     
  • "%pCr" formats the current rate of a clock, and calls clk_get_rate().
    The latter obtains a mutex, hence it must not be called from atomic
    context.

    Remove support for this rarely-used format, as vsprintf() (and e.g.
    printk()) must be callable from any context.

    Any remaining out-of-tree users will start seeing the clock's name
    printed instead of its rate.

    Reported-by: Jia-Ju Bai
    Fixes: 900cca2944254edd ("lib/vsprintf: add %pC{,n,r} format specifiers for clocks")
    Link: http://lkml.kernel.org/r/1527845302-12159-5-git-send-email-geert+renesas@glider.be
    To: Jia-Ju Bai
    To: Jonathan Corbet
    To: Michael Turquette
    To: Stephen Boyd
    To: Zhang Rui
    To: Eduardo Valentin
    To: Eric Anholt
    To: Stefan Wahren
    To: Greg Kroah-Hartman
    Cc: Sergey Senozhatsky
    Cc: Petr Mladek
    Cc: Linus Torvalds
    Cc: Steven Rostedt
    Cc: linux-doc@vger.kernel.org
    Cc: linux-clk@vger.kernel.org
    Cc: linux-pm@vger.kernel.org
    Cc: linux-serial@vger.kernel.org
    Cc: linux-arm-kernel@lists.infradead.org
    Cc: linux-renesas-soc@vger.kernel.org
    Cc: linux-kernel@vger.kernel.org
    Cc: Geert Uytterhoeven
    Cc: stable@vger.kernel.org # 4.1+
    Signed-off-by: Geert Uytterhoeven
    Signed-off-by: Petr Mladek

    Geert Uytterhoeven
     

16 May, 2018

1 commit

  • Reviewing Tobin's patches for getting pointers out early before
    entropy has been established, I noticed that there's a lone smp_mb() in
    the code. As with most lone memory barriers, this one appears to be
    incorrectly used.

    We currently basically have this:

    get_random_bytes(&ptr_key, sizeof(ptr_key));
    /*
    * have_filled_random_ptr_key==true is dependent on get_random_bytes().
    * ptr_to_id() needs to see have_filled_random_ptr_key==true
    * after get_random_bytes() returns.
    */
    smp_mb();
    WRITE_ONCE(have_filled_random_ptr_key, true);

    And later we have:

    if (unlikely(!have_filled_random_ptr_key))
    return string(buf, end, "(ptrval)", spec);

    /* Missing memory barrier here. */

    hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);

    As the CPU can perform speculative loads, we could have a situation
    with the following:

    CPU0 CPU1
    ---- ----
    load ptr_key = 0
    store ptr_key = random
    smp_mb()
    store have_filled_random_ptr_key

    load have_filled_random_ptr_key = true

    BAD BAD BAD! (you're so bad!)

    Because nothing prevents CPU1 from loading ptr_key before loading
    have_filled_random_ptr_key.

    But this race is very unlikely, but we can't keep an incorrect smp_mb() in
    place. Instead, replace the have_filled_random_ptr_key with a static_branch
    not_filled_random_ptr_key, that is initialized to true and changed to false
    when we get enough entropy. If the update happens in early boot, the
    static_key is updated immediately, otherwise it will have to wait till
    entropy is filled and this happens in an interrupt handler which can't
    enable a static_key, as that requires a preemptible context. In that case, a
    work_queue is used to enable it, as entropy already took too long to
    establish in the first place waiting a little more shouldn't hurt anything.

    The benefit of using the static key is that the unlikely branch in
    vsprintf() now becomes a nop.

    Link: http://lkml.kernel.org/r/20180515100558.21df515e@gandalf.local.home

    Cc: stable@vger.kernel.org
    Fixes: ad67b74d2469d ("printk: hash addresses printed with %p")
    Acked-by: Linus Torvalds
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

18 Apr, 2018

1 commit

  • Reflect changes that have happened to pf/pF (deprecation)
    specifiers in pointer() comment section.

    Link: http://lkml.kernel.org/r/20180414030005.25831-1-sergey.senozhatsky@gmail.com
    Cc: Steven Rostedt
    Cc: Andrew Morton
    Cc: Joe Perches
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     

12 Apr, 2018

1 commit

  • seq_put_decimal_ull_w(m, str, val, width) prints a decimal number with a
    specified minimal field width.

    It is equivalent of seq_printf(m, "%s%*d", str, width, val), but it
    works much faster.

    == test_smaps.py
    num = 0
    with open("/proc/1/smaps") as f:
    for x in xrange(10000):
    data = f.read()
    f.seek(0, 0)
    ==

    == Before patch ==
    $ time python test_smaps.py
    real 0m4.593s
    user 0m0.398s
    sys 0m4.158s

    == After patch ==
    $ time python test_smaps.py
    real 0m3.828s
    user 0m0.413s
    sys 0m3.408s

    $ perf -g record python test_smaps.py
    == Before patch ==
    - 79.01% 3.36% python [kernel.kallsyms] [k] show_smap.isra.33
    - 75.65% show_smap.isra.33
    + 48.85% seq_printf
    + 15.75% __walk_page_range
    + 9.70% show_map_vma.isra.23
    0.61% seq_puts

    == After patch ==
    - 75.51% 4.62% python [kernel.kallsyms] [k] show_smap.isra.33
    - 70.88% show_smap.isra.33
    + 24.82% seq_put_decimal_ull_w
    + 19.78% __walk_page_range
    + 12.74% seq_printf
    + 11.08% show_map_vma.isra.23
    + 1.68% seq_puts

    [akpm@linux-foundation.org: fix drivers/of/unittest.c build]
    Link: http://lkml.kernel.org/r/20180212074931.7227-1-avagin@openvz.org
    Signed-off-by: Andrei Vagin
    Cc: Alexey Dobriyan
    Cc: KAMEZAWA Hiroyuki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrei Vagin
     

11 Apr, 2018

7 commits

  • In preparation to enabling -Wimplicit-fallthrough, mark switch cases
    where we are expecting to fall through.

    Link: http://lkml.kernel.org/r/20180216210711.79901-9-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     
  • Before crng is ready, output of "%p" composes of "(ptrval)" and
    left padding spaces for alignment as no random address can be
    generated. This seems a little strange when default string width
    is larger than strlen("(ptrval)").

    For example, when irq domain names are built with "%p", the nodes
    under /sys/kernel/debug/irq/domains like this on AArch64 system,

    [root@y irq]# ls domains/
    default irqchip@ (ptrval)-2
    irqchip@ (ptrval)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3
    irqchip@ (ptrval) irqchip@ (ptrval)-3
    \_SB_.TCS0.QIC0 \_SB_.TCS0.QIC2

    The name "irqchip@ (ptrval)-2" is not so readable in console
    output.

    This patch replaces space with readable "_" when output needs padding.
    Following is the output after applying the patch,

    [root@y domains]# ls
    default irqchip@(____ptrval____)-2
    irqchip@(____ptrval____)-4 \_SB_.TCS0.QIC1 \_SB_.TCS0.QIC3
    irqchip@(____ptrval____) irqchip@(____ptrval____)-3 \_SB_.TCS0.QIC0
    \_SB_.TCS0.QIC2

    There is same problem in some subsystem's dmesg output. Moreover,
    someone may call "%p" in a similar case. In addition, the timing of
    crng initialization done may vary on different system. So, the change
    is made in vsprintf.c.

    Suggested-by: Rasmus Villemoes
    Link: http://lkml.kernel.org/r/20180216210711.79901-7-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
    Cc: Joey Zheng
    Signed-off-by: Shunyong Yang
    Signed-off-by: Andy Shevchenko
    Signed-off-by: Petr Mladek

    Shunyong Yang
     
  • There is an exact code at the end of ptr_to_id().
    Replace it by calling pointer_string() directly.

    This is followup to the commit ad67b74d2469 ("printk: hash addresses
    printed with %p").

    Cc: Tobin C. Harding
    Link: http://lkml.kernel.org/r/20180216210711.79901-6-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     
  • As preparatory patch to further clean up.

    No functional change.

    Link: http://lkml.kernel.org/r/20180216210711.79901-5-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     
  • There are places where default specification to print flags as number
    is in use.

    Make it global and convert existing users.

    Link: http://lkml.kernel.org/r/20180216210711.79901-4-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     
  • There are places where default specification to print strings
    is in use.

    Make it global and convert existing users.

    Link: http://lkml.kernel.org/r/20180216210711.79901-3-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     
  • There are places where default specification to print decimal numbers
    is in use.

    Make it global and convert existing users.

    Link: http://lkml.kernel.org/r/20180216210711.79901-2-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
    Signed-off-by: Petr Mladek

    Andy Shevchenko
     

06 Apr, 2018

1 commit

  • Commit 841a915d20c7b2 ("printf: Do not have bprintf dereference pointers")
    would preprocess various pointers that are dereferenced in the bprintf()
    because the recording and printing are done at two different times. Some
    pointers stayed dereferenced in the ring buffer because user space could
    handle them (namely "%pS" and friends). Pointers that are not dereferenced
    should not be processed immediately but instead just saved directly.

    Cc: stable@vger.kernel.org
    Fixes: 841a915d20c7b2 ("printf: Do not have bprintf dereference pointers")
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

08 Feb, 2018

1 commit

  • Like %pK already does, print "00000000" instead.

    This confused people -- the convention is that "(null)" means you tried to
    dereference a null pointer as opposed to printing the address.

    Link: http://lkml.kernel.org/r/20180204174521.21383-1-kilobyte@angband.pl
    To: Sergey Senozhatsky
    To: Steven Rostedt
    To: linux-kernel@vger.kernel.org
    Cc: Andrew Morton
    Cc: Joe Perches
    Cc: Kees Cook
    Cc: "Roberts, William C"
    Cc: Linus Torvalds
    Cc: David Laight
    Cc: Randy Dunlap
    Cc: Geert Uytterhoeven
    Signed-off-by: Adam Borowski
    Signed-off-by: Petr Mladek

    Adam Borowski
     

02 Feb, 2018

2 commits

  • Pull printk updates from Petr Mladek:

    - Add a console_msg_format command line option:

    The value "default" keeps the old "[time stamp] text\n" format. The
    value "syslog" allows to see the syslog-like "[timestamp] text" format.

    This feature was requested by people doing regression tests, for
    example, 0day robot. They want to have both filtered and full logs
    at hands.

    - Reduce the risk of softlockup:

    Pass the console owner in a busy loop.

    This is a new approach to the old problem. It was first proposed by
    Steven Rostedt on Kernel Summit 2017. It marks a context in which
    the console_lock owner calls console drivers and could not sleep.
    On the other side, printk() callers could detect this state and use
    a busy wait instead of a simple console_trylock(). Finally, the
    console_lock owner checks if there is a busy waiter at the end of
    the special context and eventually passes the console_lock to the
    waiter.

    The hand-off works surprisingly well and helps in many situations.
    Well, there is still a possibility of the softlockup, for example,
    when the flood of messages stops and the last owner still has too
    much to flush.

    There is increasing number of people having problems with
    printk-related softlockups. We might eventually need to get better
    solution. Anyway, this looks like a good start and promising
    direction.

    - Do not allow to schedule in console_unlock() called from printk():

    This reverts an older controversial commit. The reschedule helped
    to avoid softlockups. But it also slowed down the console output.
    This patch is obsoleted by the new console waiter logic described
    above. In fact, the reschedule made the hand-off less effective.

    - Deprecate "%pf" and "%pF" format specifier:

    It was needed on ia64, ppc64 and parisc64 to dereference function
    descriptors and show the real function address. It is done
    transparently by "%ps" and "pS" format specifier now.

    Sergey Senozhatsky found that all the function descriptors were in
    a special elf section and could be easily detected.

    - Remove printk_symbol() API:

    It has been obsoleted by "%pS" format specifier, and this change
    helped to remove few continuous lines and a less intuitive old API.

    - Remove redundant memsets:

    Sergey removed unnecessary memset when processing printk.devkmsg
    command line option.

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/pmladek/printk: (27 commits)
    printk: drop redundant devkmsg_log_str memsets
    printk: Never set console_may_schedule in console_trylock()
    printk: Hide console waiter logic into helpers
    printk: Add console owner and waiter logic to load balance console writes
    kallsyms: remove print_symbol() function
    checkpatch: add pF/pf deprecation warning
    symbol lookup: introduce dereference_symbol_descriptor()
    parisc64: Add .opd based function descriptor dereference
    powerpc64: Add .opd based function descriptor dereference
    ia64: Add .opd based function descriptor dereference
    sections: split dereference_function_descriptor()
    openrisc: Fix conflicting types for _exext and _stext
    lib: do not use print_symbol()
    irq debug: do not use print_symbol()
    sysfs: do not use print_symbol()
    drivers: do not use print_symbol()
    x86: do not use print_symbol()
    unicore32: do not use print_symbol()
    sh: do not use print_symbol()
    mn10300: do not use print_symbol()
    ...

    Linus Torvalds
     
  • Pull tracing updates from Steven Rostedt:
    "There's not much changes for the tracing system this release. Mostly
    small clean ups and fixes.

    The biggest change is to how bprintf works. bprintf is used by
    trace_printk() to just save the format and args of a printf call, and
    the formatting is done when the trace buffer is read. This is done to
    keep the formatting out of the fast path (this was recommended by
    you). The issue is when arguments are de-referenced.

    If a pointer is saved, and the format has something like "%*pbl", when
    the buffer is read, it will de-reference the argument then. The
    problem is if the data no longer exists. This can cause the kernel to
    oops.

    The fix for this was to make these de-reference pointes do the
    formatting at the time it is called (the fast path), as this
    guarantees that the data exists (and doesn't change later)"

    * tag 'trace-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
    vsprintf: Do not have bprintf dereference pointers
    ftrace: Mark function tracer test functions noinline/noclone
    trace_uprobe: Display correct offset in uprobe_events
    tracing: Make sure the parsed string always terminates with '\0'
    tracing: Clear parser->idx if only spaces are read
    tracing: Detect the string nul character when parsing user input string

    Linus Torvalds
     

24 Jan, 2018

1 commit

  • When trace_printk() was introduced, it was discussed that making it be as
    low overhead as possible, that the processing of the format string should be
    delayed until it is read. That is, a "trace_printk()" should not convert
    the %d into numbers and so on, but instead, save the fmt string and all the
    args in the buffer at the time of recording. When the trace_printk() data is
    read, it would then parse the format string and do the conversions of the
    saved arguments in the tracing buffer.

    The code to perform this was added to vsprintf where vbin_printf() would
    save the arguments of a specified format string in a buffer, then
    bstr_printf() could be used to convert the buffer with the same format
    string into the final output, as if vsprintf() was called in one go.

    The issue arises when dereferenced pointers are used. The problem is that
    something like %*pbl which reads a bitmask, will save the pointer to the
    bitmask in the buffer. Then the reading of the buffer via bstr_printf() will
    then look at the pointer to process the final output. Obviously the value of
    that pointer could have changed since the time it was recorded to the time
    the buffer is read. Worse yet, the bitmask could be unmapped, and the
    reading of the trace buffer could actually cause a kernel oops.

    Another problem is that user space tools such as perf and trace-cmd do not
    have access to the contents of these pointers, and they become useless when
    the tracing buffer is extracted.

    Instead of having vbin_printf() simply save the pointer in the buffer for
    later processing, have it perform the formatting at the time bin_printf() is
    called. This will fix the issue of dereferencing pointers at a later time,
    and has the extra benefit of having user space tools understand these
    values.

    Since perf and trace-cmd already can handle %p[sSfF] via saving kallsyms,
    their pointers are saved and not processed during vbin_printf(). If they
    were converted, it would break perf and trace-cmd, as they would not know
    how to deal with the conversion.

    Link: http://lkml.kernel.org/r/20171228204025.14a71d8f@gandalf.local.home

    Reported-by: Thomas Gleixner
    Signed-off-by: Steven Rostedt (VMware)

    Steven Rostedt (VMware)
     

09 Jan, 2018

1 commit

  • dereference_symbol_descriptor() invokes appropriate ARCH specific
    function descriptor dereference callbacks:
    - dereference_kernel_function_descriptor() if the pointer is a
    kernel symbol;

    - dereference_module_function_descriptor() if the pointer is a
    module symbol.

    This is the last step needed to make '%pS/%ps' smart enough to
    handle function descriptor dereference on affected ARCHs and
    to retire '%pF/%pf'.

    To refresh it:
    Some architectures (ia64, ppc64, parisc64) use an indirect pointer
    for C function pointers - the function pointer points to a function
    descriptor and we need to dereference it to get the actual function
    pointer.

    Function descriptors live in .opd elf section and all affected
    ARCHs (ia64, ppc64, parisc64) handle it properly for kernel and
    modules. So we, technically, can decide if the dereference is
    needed by simply looking at the pointer: if it belongs to .opd
    section then we need to dereference it.

    The kernel and modules have their own .opd sections, obviously,
    that's why we need to split dereference_function_descriptor()
    and use separate kernel and module dereference arch callbacks.

    Link: http://lkml.kernel.org/r/20171206043649.GB15885@jagdpanzerIV
    Cc: Fenghua Yu
    Cc: Benjamin Herrenschmidt
    Cc: Paul Mackerras
    Cc: Michael Ellerman
    Cc: James Bottomley
    Cc: Andrew Morton
    Cc: Jessica Yu
    Cc: Steven Rostedt
    Cc: linux-ia64@vger.kernel.org
    Cc: linux-parisc@vger.kernel.org
    Cc: linuxppc-dev@lists.ozlabs.org
    Cc: linux-kernel@vger.kernel.org
    Signed-off-by: Sergey Senozhatsky
    Tested-by: Tony Luck #ia64
    Tested-by: Santosh Sivaraj #powerpc
    Tested-by: Helge Deller #parisc64
    Signed-off-by: Petr Mladek

    Sergey Senozhatsky
     

22 Dec, 2017

2 commits

  • A reference to printk-formats.txt didn't get updated when the file moved;
    fix that.

    Signed-off-by: Jonathan Corbet

    Jonathan Corbet
     
  • Documentation/printk-formats.txt is a candidate for conversion to
    ReStructuredText format. Some effort has already been made to do this
    conversion even thought the suffix is currently .txt

    Changes required to complete conversion

    - Move printk-formats.txt to core-api/printk-formats.rst
    - Add entry to Documentation/core-api/index.rst
    - Remove entry from Documentation/00-INDEX
    - Fix minor grammatical errors.
    - Order heading adornments as suggested by rst docs.
    - Use 'Passed by reference' uniformly.
    - Update pointer documentation around %px specifier.
    - Fix erroneous double backticks (to commas).
    - Remove extraneous double backticks (suggested by Jonathan Corbet).
    - Simplify documentation for kobject.

    Signed-off-by: Tobin C. Harding
    [jc: downcased "kernel"]
    Signed-off-by: Jonathan Corbet

    Tobin C. Harding
     

30 Nov, 2017

1 commit

  • Instead, just fall back on the new '%p' behavior which hashes the
    pointer.

    Otherwise, '%pK' - that was intended to mark a pointer as restricted -
    just ends up leaking pointers that a normal '%p' wouldn't leak. Which
    just make the whole thing pointless.

    I suspect we should actually get rid of '%pK' entirely, and make it just
    work as '%p' regardless, but this is the minimal obvious fix. People
    who actually use 'kptr_restrict' should weigh in on which behavior they
    want.

    Cc: Tobin Harding
    Cc: Kees Cook
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

29 Nov, 2017

3 commits

  • printk specifier %p now hashes all addresses before printing. Sometimes
    we need to see the actual unmodified address. This can be achieved using
    %lx but then we face the risk that if in future we want to change the
    way the Kernel handles printing of pointers we will have to grep through
    the already existent 50 000 %lx call sites. Let's add specifier %px as a
    clear, opt-in, way to print a pointer and maintain some level of
    isolation from all the other hex integer output within the Kernel.

    Add printk specifier %px to print the actual unmodified address.

    Signed-off-by: Tobin C. Harding

    Tobin C. Harding
     
  • 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
     
  • Currently code to handle %pK is all within the switch statement in
    pointer(). This is the wrong level of abstraction. Each of the other switch
    clauses call a helper function, pK should do the same.

    Refactor code out of pointer() to new function restricted_pointer().

    Signed-off-by: Tobin C. Harding

    Tobin C. Harding
     

25 Oct, 2017

1 commit

  • …READ_ONCE()/WRITE_ONCE()

    Please do not apply this to mainline directly, instead please re-run the
    coccinelle script shown below and apply its output.

    For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
    preference to ACCESS_ONCE(), and new code is expected to use one of the
    former. So far, there's been no reason to change most existing uses of
    ACCESS_ONCE(), as these aren't harmful, and changing them results in
    churn.

    However, for some features, the read/write distinction is critical to
    correct operation. To distinguish these cases, separate read/write
    accessors must be used. This patch migrates (most) remaining
    ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
    coccinelle script:

    ----
    // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
    // WRITE_ONCE()

    // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch

    virtual patch

    @ depends on patch @
    expression E1, E2;
    @@

    - ACCESS_ONCE(E1) = E2
    + WRITE_ONCE(E1, E2)

    @ depends on patch @
    expression E;
    @@

    - ACCESS_ONCE(E)
    + READ_ONCE(E)
    ----

    Signed-off-by: Mark Rutland <mark.rutland@arm.com>
    Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: davem@davemloft.net
    Cc: linux-arch@vger.kernel.org
    Cc: mpe@ellerman.id.au
    Cc: shuah@kernel.org
    Cc: snitzer@redhat.com
    Cc: thor.thayer@linux.intel.com
    Cc: tj@kernel.org
    Cc: viro@zeniv.linux.org.uk
    Cc: will.deacon@arm.com
    Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
    Signed-off-by: Ingo Molnar <mingo@kernel.org>

    Mark Rutland
     

08 Jul, 2017

1 commit

  • Pull DeviceTree updates from Rob Herring:

    - vsprintf format specifier %pOF for device_node's. This will enable us
    to stop storing the full node names. Conversion of users will happen
    next cycle.

    - Update documentation to point to DT specification instead of ePAPR.

    - Split out graph and property functions to a separate file.

    - New of-graph functions for ALSA

    - Add vendor prefixes for RISC-V, Linksys, iWave Systems, Roofull,
    Itead, and BananaPi.

    - Improve dtx_diff utility filename printing.

    * tag 'devicetree-for-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux: (32 commits)
    of: document /sys/firmware/fdt
    dt-bindings: Add RISC-V vendor prefix
    vsprintf: Add %p extension "%pOF" for device tree
    of: find_node_by_full_name rewrite to compare each level
    of: use kbasename instead of open coding
    dt-bindings: thermal: add file extension to brcm,ns-thermal
    of: update ePAPR references to point to Devicetree Specification
    scripts/dtc: dtx_diff - Show real file names in diff header
    of: detect invalid phandle in overlay
    of: be consistent in form of file mode
    of: make __of_attach_node() static
    of: address.c header comment typo
    of: fdt.c header comment typo
    of: make of_fdt_is_compatible() static
    dt-bindings: display-timing.txt convert non-ascii characters to ascii
    Documentation: remove overlay-notes reference to non-existent file
    dt-bindings: usb: exynos-usb: Add missing required VDD properties
    dt-bindings: Add vendor prefix for Linksys
    MAINTAINERS: add device tree ABI documentation file
    of: Add vendor prefix for iWave Systems Technologies Pvt. Ltd
    ...

    Linus Torvalds
     

28 Jun, 2017

1 commit

  • 90% of the usage of device node's full_name is printing it out in a
    kernel message. However, storing the full path for every node is
    wasteful and redundant. With a custom format specifier, we can generate
    the full path at run-time and eventually remove the full path from every
    node.

    For instance typical use is:
    pr_info("Frobbing node %s\n", node->full_name);

    Which can be written now as:
    pr_info("Frobbing node %pOF\n", node);

    '%pO' is the base specifier to represent kobjects with '%pOF'
    representing struct device_node. Currently, struct device_node is the
    only supported type of kobject.

    More fine-grained control of formatting includes printing the name,
    flags, path-spec name and others, explained in the documentation entry.

    Originally written by Pantelis, but pretty much rewrote the core
    function using existing string/number functions. The 2 passes were
    unnecessary and have been removed. Also, updated the checkpatch.pl
    check. The unittest code was written by Grant Likely.

    Signed-off-by: Pantelis Antoniou
    Acked-by: Joe Perches
    Signed-off-by: Rob Herring

    Pantelis Antoniou
     

05 Jun, 2017

1 commit

  • Our "little endian" UUID really is a Wintel GUID, so rename it and its
    helpers such (guid_t). The big endian UUID is the only true one, so
    give it the name uuid_t. The uuid_le and uuid_be names are retained for
    now, but will hopefully go away soon. The exception to that are the _cmp
    helpers that will be replaced by better primitives ASAP and thus don't
    get the new names.

    Also the _to_bin helpers are named to match the better named uuid_parse
    routine in userspace.

    Also remove the existing typedef in XFS that's now been superceeded by
    the generic type name.

    Signed-off-by: Christoph Hellwig
    [andy: also update the UUID_LE/UUID_BE macros including fallout]
    Signed-off-by: Andy Shevchenko
    Reviewed-by: Amir Goldstein
    Reviewed-by: Darrick J. Wong
    Reviewed-by: Andy Shevchenko

    Signed-off-by: Christoph Hellwig

    Christoph Hellwig
     

09 May, 2017

1 commit

  • %pK was at least once misused at %pk in an out-of-tree module. This
    lead to some security concerns. Add the ability to track single and
    multiple line statements for misuses of %p.

    [akpm@linux-foundation.org: add helpful comment into lib/vsprintf.c]
    [akpm@linux-foundation.org: text tweak]
    Link: http://lkml.kernel.org/r/163a690510e636a23187c0dc9caa09ddac6d4cde.1488228427.git.joe@perches.com
    Signed-off-by: Joe Perches
    Acked-by: Kees Cook
    Acked-by: William Roberts
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

03 Apr, 2017

1 commit


28 Feb, 2017

1 commit

  • Now that %z is standartised in C99 there is no reason to support %Z.
    Unlike %L it doesn't even make format strings smaller.

    Use BUILD_BUG_ON in a couple ATM drivers.

    In case anyone didn't notice lib/vsprintf.o is about half of SLUB which
    is in my opinion is quite an achievement. Hopefully this patch inspires
    someone else to trim vsprintf.c more.

    Link: http://lkml.kernel.org/r/20170103230126.GA30170@avx2
    Signed-off-by: Alexey Dobriyan
    Cc: Andy Shevchenko
    Cc: Rasmus Villemoes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

21 May, 2016

2 commits

  • There are new helpers in this patch:

    uuid_is_valid checks if a UUID is valid
    uuid_be_to_bin converts from string to binary (big endian)
    uuid_le_to_bin converts from string to binary (little endian)

    They will be used in future, i.e. in the following patches in the series.

    This also moves the indices arrays to lib/uuid.c to be shared accross
    modules.

    [andriy.shevchenko@linux.intel.com: fix typo]
    Signed-off-by: Andy Shevchenko
    Reviewed-by: Matt Fleming
    Cc: Dmitry Kasatkin
    Cc: Mimi Zohar
    Cc: Rasmus Villemoes
    Cc: Arnd Bergmann
    Cc: "Theodore Ts'o"
    Cc: Al Viro
    Cc: Jens Axboe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     
  • There are few functions here and there along with type definitions that
    provide UUID API. This series consolidates everything under one hood
    and converts current users.

    This has been tested for a while internally, however it doesn't mean we
    covered all possible cases (especially accuracy of UUID constants after
    conversion). So, please test this as much as you can and provide your
    tag. We appreciate the effort.

    The ACPI conversion is postponed for now to sort more generic things out
    first.

    This patch (of 9):

    Since we have hex_byte_pack_upper() we may use it directly and avoid
    second loop.

    Signed-off-by: Andy Shevchenko
    Reviewed-by: Matt Fleming
    Cc: Dmitry Kasatkin
    Cc: Mimi Zohar
    Cc: Rasmus Villemoes
    Cc: Arnd Bergmann
    Cc: "Theodore Ts'o"
    Cc: Al Viro
    Cc: Jens Axboe
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Shevchenko
     

18 Mar, 2016

1 commit

  • Implement basic character sets for the '%[' conversion specifier.

    The '%[' conversion specifier matches a nonempty sequence of characters
    from the specified set of accepted (or with '^', rejected) characters
    between the brackets. The substring matched is to be made up of
    characters in (or not in) the set. This is useful for matching
    substrings that are delimited by something other than spaces.

    This implementation differs from its glibc counterpart in the following ways:
    (1) No support for character ranges (e.g., 'a-z' or '0-9')
    (2) The hyphen '-' is not a special character
    (3) The closing bracket ']' cannot be matched
    (4) No support (yet) for discarding matching input ('%*[')

    The bitmap code is largely based upon sample code which was provided by
    Rasmus.

    The motivation for adding character set support to sscanf originally
    stemmed from the kernel livepatching project. An ongoing patchset
    utilizes new livepatch Elf symbol and section names to store important
    metadata livepatch needs to properly apply its patches. Such metadata
    is stored in these section and symbol names as substrings delimited by
    periods '.' and commas ','. For example, a livepatch symbol name might
    look like this:

    .klp.sym.vmlinux.printk,0

    However, sscanf currently can only extract "substrings" delimited by
    whitespace using the "%s" specifier. Thus for the above symbol name,
    one cannot not use sscanf() to extract substrings "vmlinux" or
    "printk", for example. A number of discussions on the livepatch
    mailing list dealing with string parsing code for extracting these '.'
    and ',' delimited substrings eventually led to the conclusion that such
    code would be completely unnecessary if the kernel sscanf() supported
    character sets. Thus only a single sscanf() call would be necessary to
    extract these substrings. In addition, such an addition to sscanf()
    could benefit other areas of the kernel that might have a similar need
    in the future.

    [akpm@linux-foundation.org: 80-col tweaks]
    Signed-off-by: Jessica Yu
    Signed-off-by: Rasmus Villemoes
    Cc: Andy Shevchenko
    Cc: Kees Cook
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jessica Yu