lkml.org 
[lkml]   [2018]   [Mar]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2/2] vsprintf: don't dereference pointers to the first or last page
From
Date
On Tue, 2018-03-06 at 19:11 +0100, Adam Borowski wrote:
> As old code to avoid so is inconsistent, let's unify it within a
> single
> macro.
>
>
> +#define IS_BAD_PTR(x) ((unsigned long)(x) >= (unsigned long)-
> PAGE_SIZE \
> + || (unsigned long)(x) < PAGE_SIZE)

Oh, no.

First of all, why it's a macro?

Next, what prevents us to do it in place using IS_ERR() instead? (Btw, I
have a patch for that, not published yet)

> #define BAD_PTR_STRING(x) (!(x) ? "(null)" : IS_ERR(x) ? "(err)" :
> "(invalid)")
>
> /**
> @@ -589,7 +591,7 @@ char *string(char *buf, char *end, const char *s,
> struct printf_spec spec)
> int len = 0;
> size_t lim = spec.precision;
>
> - if ((unsigned long)s < PAGE_SIZE)
> + if (IS_BAD_PTR(s))
> s = BAD_PTR_STRING(s);

I don't think it's a good idea to change current behaviour.

> @@ -1583,7 +1585,7 @@ char *device_node_string(char *buf, char *end,
> struct device_node *dn,
> if (!IS_ENABLED(CONFIG_OF))
> return string(buf, end, "(!OF)", spec);
>
> - if ((unsigned long)dn < PAGE_SIZE)
> + if (IS_BAD_PTR(dn))
> return string(buf, end, BAD_PTR_STRING(dn), spec);

This makes no sense. Explained in comment against patch 1.

>
> /* simple case without anything any more format specifiers */
> @@ -1851,7 +1853,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 (IS_BAD_PTR(ptr) && *fmt != 'K' && *fmt != 'x') {
> /*
> * Print (null)/etc 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-07 14:23    [W:0.978 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site