[PATCH v2 4/4] lib/vsprintf: Always check interrupt context restrictions

From: Thomas Weißschuh

Date: Mon May 04 2026 - 06:48:48 EST


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());
+
switch (kptr_restrict) {
case 0:
/* Handle as %p, hash and do _not_ leak addresses. */

--
2.53.0