public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/vsprintf: Validate sleepable context during restrictred pointer formatting
@ 2026-03-17 11:41 Thomas Weißschuh
  2026-03-17 14:07 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Thomas Weißschuh @ 2026-03-17 11:41 UTC (permalink / raw)
  To: Andrew Morton, Petr Mladek, Steven Rostedt, Andy Shevchenko,
	Rasmus Villemoes, Sergey Senozhatsky
  Cc: linux-kernel, Thomas Weißschuh

Depending on the system configuration, the restricted pointer formatting
might call into the security subsystem which might sleep.
As %pK is intended to be only used from read handlers of virtual files,
which always run in task context, this should never happen in practice.
However, developers have used %pK before from atomic context without
realizing this restriction. While all existing user of %pK through
printk() have been removed, new ones might be reintroduced accidentally
in the future.

Add a might_sleep(), so that misuse of %pK from atomic context is
detected right away.

Link: https://lore.kernel.org/lkml/20250113171731-dc10e3c1-da64-4af0-b767-7c7070468023@linutronix.de/
Link: https://lore.kernel.org/lkml/20241217142032.55793-1-acarmina@redhat.com/
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
This depends on commit 5886cc8f895b ("drm/msm/dpu: Don't use %pK through
printk (again)"), which was merged in v7.0-rc2.
---
 lib/vsprintf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 800b8ac49f53..eb9dbb28fb9b 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -862,6 +862,9 @@ static noinline_for_stack
 char *restricted_pointer(char *buf, char *end, const void *ptr,
 			 struct printf_spec spec)
 {
+	/* Only usable from task context, The call to has_capability_noaudit() might sleep. */
+	might_sleep();
+
 	switch (kptr_restrict) {
 	case 0:
 		/* Handle as %p, hash and do _not_ leak addresses. */

---
base-commit: 2d1373e4246da3b58e1df058374ed6b101804e07
change-id: 20260107-restricted-pointers-final-cd24979fd752

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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-03-20  1:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 11:41 [PATCH] lib/vsprintf: Validate sleepable context during restrictred pointer formatting Thomas Weißschuh
2026-03-17 14:07 ` Andy Shevchenko
2026-03-17 14:26   ` Thomas Weißschuh
2026-03-17 17:24     ` Steven Rostedt
2026-03-18  8:48 ` Thomas Weißschuh
2026-03-18 11:01   ` Petr Mladek
2026-03-18 11:03   ` Petr Mladek
2026-03-18 13:59     ` Sebastian Andrzej Siewior
2026-03-18 14:45       ` Thomas Weißschuh
2026-03-18 14:57         ` Sebastian Andrzej Siewior
2026-03-18 15:10           ` Thomas Weißschuh
2026-03-19  8:17             ` Sebastian Andrzej Siewior
2026-03-20  1:53 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox