lkml.org 
[lkml]   [2018]   [May]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v5 09/11] vsprintf: Prevent crash when dereferencing invalid pointers
From
Date
On Fri, 2018-04-27 at 14:47 +0200, Petr Mladek wrote:
> On Wed 2018-04-25 18:10:54, Andy Shevchenko wrote:
> > On Wed, 2018-04-25 at 13:12 +0200, Petr Mladek wrote:
> > > 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.
> > > +static const char *check_pointer_access(const void *ptr)
> > > +{
> > > + char byte;
> > > +
> > > + if (!ptr)
> > > + return "(null)";
> > > +
> > > + if (probe_kernel_address(ptr, byte))
> > > + return "(efault)";
> > > +
> > > + return NULL;
> > > +}
> > > +
> > > +static bool valid_pointer_access(char **buf, char *end, const
> > > void
> > > *ptr,
> > > + struct printf_spec spec)
> > > +{
> > > + const char *err_msg;
> > > +
> > > + err_msg = check_pointer_access(ptr);
> > > + if (err_msg) {
> > > + *buf = valid_string(*buf, end, err_msg, spec);
> > > + return false;
> > > + }
> > > +
> > > + return true;
> > > +}
> >
> > I would preserve similar style of buf pointer handling, i.e.
> >
> > static char *valid_pointer_access(char **buf, char *end,
> > const void *ptr, struct printf_spec
> > spec)
> > {
> > const char *err_msg;
> >
> > err_msg = check_pointer_access(ptr);
> > if (err_msg)
> > return = valid_string(*buf, end, err_msg, spec);
> >
> > return NULL;
> > }
>
> Heh, I actually started with exactly this code. But it caused
> confusion.
> The name suggests that it should return true on success and NULL
> is false:
>
> if (!valid_pointer_access())
> return err;

Confusion is already created by valid_string() to return char *.

> Any better naming/code is welcome.

Have nothing in my mind currently.

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

\
 
 \ /
  Last update: 2018-05-03 13:57    [W:0.073 / U:1.888 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site