Re: [PATCH] printf: add bad-pointer tests for %ptT and %ptS

From: Andy Shevchenko

Date: Fri Mar 20 2026 - 06:33:43 EST


On Fri, Mar 20, 2026 at 09:54:17AM +0100, Petr Mladek wrote:
> On Mon 2026-03-16 16:55:36, Andy Shevchenko wrote:
> > On Mon, Mar 16, 2026 at 04:43:34PM +0545, Shuvam Pandey wrote:
> > > The printf KUnit suite exercises valid %ptR, %ptT, and %ptS inputs,
> > > but it does not cover bad pointers for the time64_t and timespec64
> > > paths.
> > >
> > > Add NULL and low-address pointer cases for %ptT and %ptS. The new
> > > checks verify that time_and_date() rejects bad pointers before
> > > dereferencing them and formats them as "(null)" or "(efault)".
> > >
> > > Validated with the printf KUnit suite on arm64 QEMU and an
> > > incremental W=1 build of lib/tests/printf_kunit.o.
> >
> > NAK.
> >
> > It has nothing to do with %pt.
>
> Let me play the devil advocate.
>
> There is no single check which would catch bad pointers for
> the various %p? format modifiers. It is because some of them
> handle them differently, for example, %pK, %pe, or plain %p.
>
> I want to say that wrong pointers passed to %pt? are caught only
> because of the explicit check in:
>
> static noinline_for_stack
> char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
> const char *fmt)
> {
> if (check_pointer(&buf, end, ptr, spec))
> return buf;
> [...]
> }
>
> So, pointer-modifier-specific checks of wrong input might make sense.
>
> Of course, it would be nice to create some generic solution for
> all affected pointer modifiers and not just for "%pt?".

We should have a check for check_pointer() then.

--
With Best Regards,
Andy Shevchenko