Re: [PATCH] lib/vsprintf: Validate sleepable context during restrictred pointer formatting

From: Steven Rostedt

Date: Tue Mar 17 2026 - 13:38:36 EST


On Tue, 17 Mar 2026 15:26:13 +0100
Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx> wrote:

> >
> > > + /* Only usable from task context, The call to has_capability_noaudit() might sleep. */
> > > + might_sleep();
> >
> > Yeah, but for kptr_restrict != 1 it's not true. Perhaps might_sleep_if() ?
>
> kptr_restrict can change any time at runtime. The whole point of this patch
> is to detect the API misuse independently from the system configuration.
> Developers probably don't test against kptr_restrict == 1 and therefore
> it will only blow up on users system.

Agreed. Those that add a printk with %pK in an atomic context may have
kprt_restrict == 0, and will not know they just added a potential bug.

We want it to warn if it is used in any problematic way, even if the
current settings do not trigger it.

Similarly, like we have lockdep in tracepoints:

include/linux/tracepoint.h:

static inline void trace_##name(proto) \
{ \
if (static_branch_unlikely(&__tracepoint_##name.key)) \
__do_trace_##name(args); \
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
WARN_ONCE(!rcu_is_watching(), \
"RCU not watching for tracepoint"); \
} \
}

Where lockdep will warn if RCU isn't watching at the call site of the
tracepoint regardless if that tracepoint is enabled or not.

-- Steve