Re: [PATCH v4 2/2] kallsyms: Don't leak pointers for unresolved symbols

From: Sebastian Andrzej Siewior

Date: Mon Oct 19 2026 - 08:19:54 EST


On 2026-10-19 14:05:55 [+0300], Andy Shevchenko wrote:
> On Mon, Oct 19, 2026 at 12:50:25PM +0200, Sebastian Andrzej Siewior wrote:
> > On 2026-10-19 13:34:35 [+0300], Andy Shevchenko wrote:
> > > > +int snprintf_default_pointer(char *buf, unsigned int len, const void *ptr)
> > > > +{
> > > > + struct printf_spec spec = {
> > > > + .base = 10,
> > > > + .precision = -1,
> > > > + .field_width = -1,
> > > > + };
> > >
> > > Isn't it the same as default_dec_spec?
>
> > Except for .field_width, yes.
>
> You can update it there. I think in all other cases (I briefly checked, but
> haven't run any smoke test with KUnit) it should be an equivalent.

Okay. So lets give it a try.

> > > > + unsigned int w;
> > > > + char *endp;
> > > > +
> > > > + endp = default_pointer(buf, buf + len, ptr, spec);
> > > > + w = min_t(unsigned int, len - 1, endp - buf);
>
> This also won't properly work for len = 0, I assume? So one can't make
> something like kasprintf() on top of this.
>
> > > May we avoid min_t()?
> >
> > min() complains about signedness (len unsigned and ptr diff signed).
> > endp is >= buf so it will be unsigned.
> > An alternative would be manual comparison if the buffer size has been
> > exceeded or not and act upon it but this looks simpler.
>
> It looks simpler, it looks wrong :-)

Could we then exclude len == 0 and keep the remaining bits as-is?

> > > > + buf[w] = '\0';
> > > > + return endp - buf;
> > > > +}

Sebastian