[PATCH v2 0/4] lib/vsprintf: Validate spinlock context during restricted pointer formatting

From: Thomas Weißschuh

Date: Mon May 04 2026 - 06:47:40 EST


Depending on the system configuration, the restricted pointer formatting
might call into the security subsystem which takes spinlocks, which
might sleep under PREEMPT_RT. As %pK is intended to be only used from
read handlers of virtual files, which always run in task context,
this should not be a problem in practice.
However, developers have used %pK before from atomic context without
realizing this restriction.

Add a lockdep annotation to unconditionally introduce a fake spinlock in
restricted_pointer(), so lockdep can detect misuse even if the current
test system configuration would not exhibit the issue.

---
Changes in v2:
- Use custom lock_map over might_sleep()
- Also assert IRQ context
- Link to v1: https://lore.kernel.org/r/20260317-restricted-pointers-final-v1-1-b4dca0ed6483@xxxxxxxxxxxxx

To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
To: Petr Mladek <pmladek@xxxxxxxx>
To: Steven Rostedt <rostedt@xxxxxxxxxxx>
To: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
To: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>
To: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
To: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: Ingo Molnar <mingo@xxxxxxxxxx>
To: Will Deacon <will@xxxxxxxxxx>
To: Boqun Feng <boqun@xxxxxxxxxx>
To: Waiman Long <longman@xxxxxxxxxx>
To: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
To: Clark Williams <clrkwllms@xxxxxxxxxx>
To: Kees Cook <kees@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-rt-devel@xxxxxxxxxxxxxxx
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>

---
Thomas Weißschuh (4):
locking/lockdep: Add a helper to validate the locking context without a lock
locking/lockdep: Add a guard for lock_map_acquire()
lib/vsprintf: Validate spinlock context during restricted pointer formatting
lib/vsprintf: Always check interrupt context restrictions

include/linux/lockdep.h | 11 +++++++++++
lib/vsprintf.c | 13 +++++++++++++
2 files changed, 24 insertions(+)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260107-restricted-pointers-final-cd24979fd752

Best regards,
--
Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>