From: Petr Mladek <pmladek@suse.com>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vsprintf: Add test for restricted kernel pointers
Date: Fri, 16 Jan 2026 18:06:59 +0100 [thread overview]
Message-ID: <aWpwMyFEfpCNN297@pathway.suse.cz> (raw)
In-Reply-To: <20260114-restricted-pointers-kunit-test-v1-1-a9d8a49c6b6f@linutronix.de>
On Wed 2026-01-14 08:27:34, Thomas Weißschuh wrote:
> Fill out the tests for restricted kernel pointers, using the %pK format.
> This test can only be executed when built into the kernel, as modules
> do not have access to the kptr_restrict knob.
I think that we could export "kptr_restrict" like we did
with no_hash_pointers. AFAIK, it has been exported just because
of the test module as well.
> Please note that changes to the kptr_restrict sysctl from the kernel
> commandline are only applied *after* the boot-time KUnit tests run.
This is another motivation to export the symbol. Otherwise, it is
really hard to test the non-default variants.
BTW: I have recently heard about EXPORT_SYMBOL_NS(). It would allow
to export the symbol only for some specific modules.
I am not sure how exactly it works. I wonder if there already
exists a namespace for KUnit tests.
It would be nice to use it, even for "no_hash_pointers"...
> --- a/lib/tests/printf_kunit.c
> +++ b/lib/tests/printf_kunit.c
> @@ -316,7 +316,31 @@ symbol_ptr(struct kunit *kunittest)
> static void
> kernel_ptr(struct kunit *kunittest)
> {
> - /* We can't test this without access to kptr_restrict. */
> +#ifdef MODULE
> + kunit_skip(kunittest, "cannot access kptr_restrict from test module");
> + return;
> +#endif
> +
> + 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:
> + test(PTR_STR, "%pK", PTR);
Hmm, the behavior of %pK depends on capabilities of the caller.
The above code would work when the test is built in.
But we might need to check the capabilities when using test module.
If I get it correctly, the module loaded requires CAP_SYS_MODULE
while %pK behavior depends on CAP_SYSLOG...
> + break;
> + case 2:
> + default:
> + test(ZEROS "00000000", "%pK", PTR);
> + break;
> + }
> }
>
> static void
Anyway, thanks for working on this.
Best Regards,
Petr
next prev parent reply other threads:[~2026-01-16 17:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 7:27 [PATCH] vsprintf: Add test for restricted kernel pointers Thomas Weißschuh
2026-01-16 17:06 ` Petr Mladek [this message]
2026-01-19 7:34 ` Andy Shevchenko
2026-01-19 7:43 ` Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aWpwMyFEfpCNN297@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=thomas.weissschuh@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.