* [PATCH] printf: add bad-pointer tests for %ptT and %ptS
@ 2026-03-16 10:58 Shuvam Pandey
2026-03-16 14:55 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Shuvam Pandey @ 2026-03-16 10:58 UTC (permalink / raw)
To: Petr Mladek, Steven Rostedt
Cc: Andy Shevchenko, Rasmus Villemoes, Sergey Senozhatsky,
Andrew Morton, linux-kernel
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.
Signed-off-by: Shuvam Pandey <shuvampandey1@gmail.com>
---
lib/tests/printf_kunit.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index f6f21b445ece..c64bfe79652e 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -509,6 +509,13 @@ time_and_date(struct kunit *kunittest)
struct timespec64 ts = { .tv_sec = t, .tv_nsec = 11235813 };
test("(%pt?)", "%pt", &tm);
+
+ /* %ptT and %ptS reject bad pointers before dereference. */
+ test("(null)", "%ptT", NULL);
+ test("(efault)", "%ptT", PTR_INVALID);
+ test("(null)", "%ptS", NULL);
+ test("(efault)", "%ptS", PTR_INVALID);
+
test("2018-11-26T05:35:43", "%ptR", &tm);
test("0118-10-26T05:35:43", "%ptRr", &tm);
test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] printf: add bad-pointer tests for %ptT and %ptS
2026-03-16 10:58 [PATCH] printf: add bad-pointer tests for %ptT and %ptS Shuvam Pandey
@ 2026-03-16 14:55 ` Andy Shevchenko
2026-03-20 8:54 ` Petr Mladek
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2026-03-16 14:55 UTC (permalink / raw)
To: Shuvam Pandey
Cc: Petr Mladek, Steven Rostedt, Rasmus Villemoes, Sergey Senozhatsky,
Andrew Morton, linux-kernel
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.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] printf: add bad-pointer tests for %ptT and %ptS
2026-03-16 14:55 ` Andy Shevchenko
@ 2026-03-20 8:54 ` Petr Mladek
2026-03-20 10:29 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Petr Mladek @ 2026-03-20 8:54 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Shuvam Pandey, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
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?".
Best Regards,
Petr
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] printf: add bad-pointer tests for %ptT and %ptS
2026-03-20 8:54 ` Petr Mladek
@ 2026-03-20 10:29 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2026-03-20 10:29 UTC (permalink / raw)
To: Petr Mladek
Cc: Shuvam Pandey, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton, linux-kernel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-20 10:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 10:58 [PATCH] printf: add bad-pointer tests for %ptT and %ptS Shuvam Pandey
2026-03-16 14:55 ` Andy Shevchenko
2026-03-20 8:54 ` Petr Mladek
2026-03-20 10:29 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.