Re: [PATCH v2 4/4] lib/vsprintf: Always check interrupt context restrictions
From: Thomas Weißschuh
Date: Mon May 04 2026 - 09:20:15 EST
On Mon, May 04, 2026 at 03:00:44PM +0200, Peter Zijlstra wrote:
> On Mon, May 04, 2026 at 12:47:20PM +0200, Thomas Weißschuh wrote:
> > When kptr_restrict is set to '1' restricted pointers can not be used
> > in IRQ context. As kptr_restrict can change at any time at runtime,
> > this means that restricted pointers can not be used from IRQ context
> > in general.
> >
> > Add some assertions to detect misuse early, independently of the
> > runtime configuration of the test system.
> >
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
> > ---
> > lib/vsprintf.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index 021db95087fe..185bd9e61144 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -871,6 +871,10 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,
> >
> > guard(lock_map_acquire)(&vsprintf_restricted_pointer_map);
> >
> > + lockdep_assert(!in_hardirq());
> > + lockdep_assert(!in_serving_softirq());
> > + lockdep_assert(!in_nmi());
> > +
>
> did that want to be:
>
> lockdep_assert(in_task());
Primarily it wants to be the inverse of the check further down the function:
if (in_hardirq() || in_serving_softirq() || in_nmi()) {
if (spec.field_width == -1)
spec.field_width = 2 * sizeof(ptr);
return error_string(buf, end, "pK-error", spec);
But in_task() looks like the better choice indeed, thanks!
I'll switch both locations to that for the next revision.
Unless Sebastian manages to get rid of it all, that is.
Thomas