Skip to content

lib/vsprintf: Validate spinlock context during restricted pointer formatting

Thomas Weißschuh linux-rt-devel lkml 4 versions – In review

Get series with b4
b4 am 20260608-restricted-pointers-final-v4-0-9a436615799e@linutronix.de change-id 20260107-restricted-pointers-final-cd24979fd752

Versions newest first

  1. v4 Latest5 patches 7 repliesIn review
  2. v35 patches 2 repliesSuperseded
  3. v24 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch11 repliesSuperseded

Changes in v4 from the cover letter

- Pick up review from Petr.
- Check in_task() before LD_WAIT_CONFIG.
- Make commit message slightly clearer.
- Reorder patches to avoid problematic temporary states.
- Link to v3: https://patch.msgid.link/20260520-restricted-pointers-final-v3-0-76bca6a6ab3f@linutronix.de

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5locking/lockdep: Add a helper to validate the locking context without a lockinclude/linux/lockdep.h+8 -00 replies
2/5locking/lockdep: Add a guard for lock_map_acquire()include/linux/lockdep.h+3 -00 replies
3/5lib/vsprintf: Use in_task() for restricted pointer context checklib/vsprintf.c+1 -10 replies
4/5lib/vsprintf: Always check interrupt context restrictionslib/vsprintf.c+3 -00 replies
5/5lib/vsprintf: Validate spinlock context during restricted pointer formattinglib/vsprintf.c+7 -07 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchPetr Mladek
1/5
2/5
3/5
4/5
5/5R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/5] lib/vsprintf: Validate spinlock context during restricted pointer formatting

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 v4:
- Pick up review from Petr.
- Check in_task() before LD_WAIT_CONFIG.
- Make commit message slightly clearer.
- Reorder patches to avoid problematic temporary states.
- Link to v3: https://patch.msgid.link/20260520-restricted-pointers-final-v3-0-76bca6a6ab3f@linutronix.de

Changes in v3:
- Use in_task() over its open-coded inverse.
- Also switch the existing check over to it.
- Link to v2: https://patch.msgid.link/20260504-restricted-pointers-final-v2-0-4934933503e5@linutronix.de

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@linutronix.de

To: Andrew Morton <[email protected]>
To: Petr Mladek <[email protected]>
To: Steven Rostedt <[email protected]>
To: Andy Shevchenko <[email protected]>
To: Rasmus Villemoes <[email protected]>
To: Sergey Senozhatsky <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>
To: Will Deacon <[email protected]>
To: Boqun Feng <[email protected]>
To: Waiman Long <[email protected]>
To: Sebastian Andrzej Siewior <[email protected]>
To: Clark Williams <[email protected]>
To: Kees Cook <[email protected]>

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

 include/linux/lockdep.h | 11 +++++++++++
 lib/vsprintf.c          | 12 +++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

---
base-commit: d870b998ed2e4184cbe312f4a4e2fd60d1360caf
change-id: 20260107-restricted-pointers-final-cd24979fd752

Best regards,

Signature · 1 line
Thomas Weißschuh <[email protected]>