[PATCH v4 4/5] lib/vsprintf: Always check interrupt context restrictions
From: Thomas Weißschuh
Date: Mon Jun 08 2026 - 10:27:56 EST
When kptr_restrict is set to '1' restricted pointers can only be used
in task context. As kptr_restrict can change at any time at runtime,
this means that restricted pointers can only be used from task context
in general.
Add an assertion to detect misuse early, independently of the
current runtime configuration.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
---
lib/vsprintf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6095b5f0d022..09e0e5194d41 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -29,6 +29,7 @@
#include <linux/hex.h>
#include <linux/kernel.h>
#include <linux/kallsyms.h>
+#include <linux/lockdep.h>
#include <linux/math64.h>
#include <linux/uaccess.h>
#include <linux/ioport.h>
@@ -863,6 +864,8 @@ static noinline_for_stack
char *restricted_pointer(char *buf, char *end, const void *ptr,
struct printf_spec spec)
{
+ lockdep_assert(in_task());
+
switch (kptr_restrict) {
case 0:
/* Handle as %p, hash and do _not_ leak addresses. */
--
2.54.0