* [PATCH v2 0/2] vsprintf: Add test for restricted kernel pointers
@ 2026-05-04 10:43 Thomas Weißschuh
2026-05-04 10:43 ` [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module Thomas Weißschuh
2026-05-04 10:43 ` [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
0 siblings, 2 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2026-05-04 10:43 UTC (permalink / raw)
To: Andrew Morton, Petr Mladek, Steven Rostedt, Andy Shevchenko,
Rasmus Villemoes, Sergey Senozhatsky
Cc: linux-kernel, Thomas Weißschuh
Fill out the tests for restricted kernel pointers, using the %pK format.
---
Changes in v2:
- Restrict the visibility of no_hash_pointers.
- Handle printf_kunit being a module.
- Add note about KUnit capabilities for kptr_restrict==1.
- Link to v1: https://lore.kernel.org/r/20260114-restricted-pointers-kunit-test-v1-1-a9d8a49c6b6f@linutronix.de
To: Andrew Morton <akpm@linux-foundation.org>
To: Petr Mladek <pmladek@suse.com>
To: Steven Rostedt <rostedt@goodmis.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (2):
vsprintf: Only export no_hash_pointers to test module
vsprintf: Add test for restricted kernel pointers
lib/tests/printf_kunit.c | 22 +++++++++++++++++++++-
lib/vsprintf.c | 7 ++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
---
base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731
change-id: 20260109-restricted-pointers-kunit-test-ff4ec887bcd8
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module
2026-05-04 10:43 [PATCH v2 0/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
@ 2026-05-04 10:43 ` Thomas Weißschuh
2026-05-04 10:57 ` Andy Shevchenko
2026-05-04 10:43 ` [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
1 sibling, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-05-04 10:43 UTC (permalink / raw)
To: Andrew Morton, Petr Mladek, Steven Rostedt, Andy Shevchenko,
Rasmus Villemoes, Sergey Senozhatsky
Cc: linux-kernel, Thomas Weißschuh
Aside from the printf test module, no module should ever use this symbol.
Suggested-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/all/aWpwMyFEfpCNN297@pathway.suse.cz/
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/all/aW3em-KplLVofU5z@smile.fi.intel.com/
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
lib/vsprintf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9f359b31c8d1..f70d240a394c 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -59,7 +59,9 @@
/* Disable pointer hashing if requested */
bool no_hash_pointers __ro_after_init;
-EXPORT_SYMBOL_GPL(no_hash_pointers);
+#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
+EXPORT_SYMBOL_FOR_MODULES(no_hash_pointers, "printf_kunit");
+#endif
/*
* Hashed pointers policy selected by "hash_pointers=..." boot param
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers
2026-05-04 10:43 [PATCH v2 0/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
2026-05-04 10:43 ` [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module Thomas Weißschuh
@ 2026-05-04 10:43 ` Thomas Weißschuh
2026-05-04 10:58 ` Andy Shevchenko
1 sibling, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-05-04 10:43 UTC (permalink / raw)
To: Andrew Morton, Petr Mladek, Steven Rostedt, Andy Shevchenko,
Rasmus Villemoes, Sergey Senozhatsky
Cc: linux-kernel, Thomas Weißschuh
Fill out the tests for restricted kernel pointers, using the %pK format.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Please note that changes to the kptr_restrict sysctl from the kernel
commandline are only applied *after* the boot-time KUnit tests run.
---
lib/tests/printf_kunit.c | 22 +++++++++++++++++++++-
lib/vsprintf.c | 3 +++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index bb70b9cddadd..58e639b01e83 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -319,7 +319,27 @@ symbol_ptr(struct kunit *kunittest)
static void
kernel_ptr(struct kunit *kunittest)
{
- /* We can't test this without access to kptr_restrict. */
+ switch (kptr_restrict) {
+ case 0:
+ if (no_hash_pointers) {
+ test(PTR_STR, "%pK", PTR);
+ } else {
+ char buf[PLAIN_BUF_SIZE];
+
+ plain_hash_to_buffer(kunittest, PTR, buf, PLAIN_BUF_SIZE);
+ /* %pK behaves the same as hashing */
+ test(buf, "%pK", PTR);
+ }
+ break;
+ case 1:
+ /* The KUnit kthread has all capabilities, including CAP_SYSLOG */
+ test(PTR_STR, "%pK", PTR);
+ break;
+ case 2:
+ default:
+ test(ZEROS "00000000", "%pK", PTR);
+ break;
+ }
}
static void
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index f70d240a394c..dc7e012a6ed7 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -859,6 +859,9 @@ static char *default_pointer(char *buf, char *end, const void *ptr,
}
int kptr_restrict __read_mostly;
+#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
+EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit");
+#endif
static noinline_for_stack
char *restricted_pointer(char *buf, char *end, const void *ptr,
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module
2026-05-04 10:43 ` [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module Thomas Weißschuh
@ 2026-05-04 10:57 ` Andy Shevchenko
2026-05-04 11:53 ` Thomas Weißschuh
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2026-05-04 10:57 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andrew Morton, Petr Mladek, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, linux-kernel
On Mon, May 04, 2026 at 12:43:40PM +0200, Thomas Weißschuh wrote:
> Aside from the printf test module, no module should ever use this symbol.
...
> -EXPORT_SYMBOL_GPL(no_hash_pointers);
> +#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
> +EXPORT_SYMBOL_FOR_MODULES(no_hash_pointers, "printf_kunit");
> +#endif
But do we need that ugly ifdeffery? the infrastructure should handle that.
(Also, if I build a module separately after the kernel, it won't work.)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers
2026-05-04 10:43 ` [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
@ 2026-05-04 10:58 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-05-04 10:58 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andrew Morton, Petr Mladek, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, linux-kernel
On Mon, May 04, 2026 at 12:43:41PM +0200, Thomas Weißschuh wrote:
> Fill out the tests for restricted kernel pointers, using the %pK format.
...
> +#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
> +EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit");
> +#endif
Same Q here.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module
2026-05-04 10:57 ` Andy Shevchenko
@ 2026-05-04 11:53 ` Thomas Weißschuh
2026-05-04 14:11 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2026-05-04 11:53 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Andrew Morton, Petr Mladek, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, linux-kernel
On Mon, May 04, 2026 at 01:57:31PM +0300, Andy Shevchenko wrote:
> On Mon, May 04, 2026 at 12:43:40PM +0200, Thomas Weißschuh wrote:
> > Aside from the printf test module, no module should ever use this symbol.
>
> ...
>
> > -EXPORT_SYMBOL_GPL(no_hash_pointers);
>
> > +#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
> > +EXPORT_SYMBOL_FOR_MODULES(no_hash_pointers, "printf_kunit");
> > +#endif
>
> But do we need that ugly ifdeffery? the infrastructure should handle that.
Where does the generic infrastructure take the kconfig option into account?
> (Also, if I build a module separately after the kernel, it won't work.)
Only if it was not enabled when the kernel was built.
But if people are unhappy with the ifdeffery, I'm fine with dropping it.
It is not a hard requirement at all.
Thomas
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module
2026-05-04 11:53 ` Thomas Weißschuh
@ 2026-05-04 14:11 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-05-04 14:11 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Andrew Morton, Petr Mladek, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, linux-kernel
On Mon, May 04, 2026 at 01:53:47PM +0200, Thomas Weißschuh wrote:
> On Mon, May 04, 2026 at 01:57:31PM +0300, Andy Shevchenko wrote:
> > On Mon, May 04, 2026 at 12:43:40PM +0200, Thomas Weißschuh wrote:
...
> > > -EXPORT_SYMBOL_GPL(no_hash_pointers);
> >
> > > +#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST)
> > > +EXPORT_SYMBOL_FOR_MODULES(no_hash_pointers, "printf_kunit");
> > > +#endif
> >
> > But do we need that ugly ifdeffery? the infrastructure should handle that.
>
> Where does the generic infrastructure take the kconfig option into account?
Nowhere, but my point that it's taken care of at run-time.
> > (Also, if I build a module separately after the kernel, it won't work.)
>
> Only if it was not enabled when the kernel was built.
>
> But if people are unhappy with the ifdeffery, I'm fine with dropping it.
> It is not a hard requirement at all.
I think it's unnecessary to have. But I'm not a maintainer of this code.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-05-04 14:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 10:43 [PATCH v2 0/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
2026-05-04 10:43 ` [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module Thomas Weißschuh
2026-05-04 10:57 ` Andy Shevchenko
2026-05-04 11:53 ` Thomas Weißschuh
2026-05-04 14:11 ` Andy Shevchenko
2026-05-04 10:43 ` [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
2026-05-04 10:58 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox