[PATCH v3 5/5] lib/vsprintf: Always check interrupt context restrictions

From: Thomas Weißschuh

Date: Wed May 20 2026 - 04:44:41 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 | 2 ++
1 file changed, 2 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 69dbd22f0e9e..c48a771a3ac3 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -871,6 +871,8 @@ char *restricted_pointer(char *buf, char *end, const void *ptr,

guard(lock_map_acquire)(&vsprintf_restricted_pointer_map);

+ lockdep_assert(in_task());
+
switch (kptr_restrict) {
case 0:
/* Handle as %p, hash and do _not_ leak addresses. */

--
2.54.0