lkml.org 
[lkml]   [2018]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH] vsprintf: Make "null" pointer dereference more robust
    From
    Date
    On Fri, 2018-03-02 at 13:53 +0100, Petr Mladek wrote:
    > %p has many modifiers where the pointer is dereferenced. An invalid
    > pointer might cause kernel to crash silently.
    >
    > Note that printk() formats the string 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.
    >
    > In general, we should do our best to get useful message from printk().
    > All pointers to the first memory page must be invalid. Let's prevent
    > the dereference and print "(null)" in this case. This is already done
    > in many other situations, including "%s" format handling and many
    > page fault handlers.
    >


    With such explanation it makes at least clear for the reader why it's
    done.

    Thanks!

    Would you be okay if I take this one as a first in my series and
    resubmit the series based on it?

    > Signed-off-by: Petr Mladek <pmladek@suse.com>
    > ---
    > lib/vsprintf.c | 2 +-
    > 1 file changed, 1 insertion(+), 1 deletion(-)
    >
    > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
    > index d7a708f82559..5c2d1f44218a 100644
    > --- a/lib/vsprintf.c
    > +++ b/lib/vsprintf.c
    > @@ -1849,7 +1849,7 @@ char *pointer(const char *fmt, char *buf, char
    > *end, void *ptr,
    > {
    > const int default_width = 2 * sizeof(void *);
    >
    > - if (!ptr && *fmt != 'K' && *fmt != 'x') {
    > + if ((unsigned long)ptr < PAGE_SIZE && *fmt != 'K' && *fmt !=
    > 'x') {
    > /*
    > * Print (null) with the same width as a pointer so
    > it makes
    > * tabular output look nice.

    --
    Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Intel Finland Oy

    \
     
     \ /
      Last update: 2018-03-02 15:18    [W:4.189 / U:0.164 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site