vsprintf: Add test for restricted kernel pointers

Fill out the tests for restricted kernel pointers, using the %pK format.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://patch.msgid.link/20260504-restricted-pointers-kunit-test-v2-2-19e8b1c0fbeb@linutronix.de
[pmladek@suse.com: Removed questionable ifdeffery.]
Signed-off-by: Petr Mladek <pmladek@suse.com>
This commit is contained in:
Thomas Weißschuh
2026-05-04 12:43:41 +02:00
committed by Petr Mladek
parent d1c9b60b6d
commit 4d56efe69d
2 changed files with 22 additions and 1 deletions

View File

@@ -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

View File

@@ -857,6 +857,7 @@ static char *default_pointer(char *buf, char *end, const void *ptr,
}
int kptr_restrict __read_mostly;
EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit");
static noinline_for_stack
char *restricted_pointer(char *buf, char *end, const void *ptr,