From nobody Sun Jun 14 02:33:37 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96E7C21CC4F for ; Mon, 4 May 2026 10:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777891429; cv=none; b=CQRQFtsJVAPU+6rjFZyYVC7zsP1KZvSt/ut0xUjDB5h/Mwr3e263MBj9BiWhuBfwozErODVfJo6Oa1I7hwy7xXTzqzxc+PeZtymMuXCNQ92mV3z/NbI6vbgY0FbKe4z6SWJLP/TseNhAU0a40RCHWycNS57d0q9VUmZW22w84/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777891429; c=relaxed/simple; bh=G/NwhjonqqSmR/FirRofYlGNb0Txdq6OZWjiRo75Ikw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rsPx9PGFIBf0SK77WwQ4Gbmj7USpYOICf8wsHWBRrqzeIEm3LBh55ZSfZiomeefL2kSHq1aaJnTG65aZE5G8uEUn8XBsYYmfQl4QY3M9KiYdVWZtbcsRbRxAQzLEF9Uq+bUv/2mG7vJ9l9DcVQdZb2ub+9/moWomrLfFf15RfM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MqI3WyZ0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b/OhIxPD; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MqI3WyZ0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b/OhIxPD" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777891427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=889+Bze4fxhZZCKhr16iohDBKenwN0EM/ivLny0IVjs=; b=MqI3WyZ0M5nKmzlhdIu7zDu2D/ggmZ+ZY+J9A75yWXhwFiiDUjJ1GRGxHGKEJztFD5Sk+o 56ZDsnVPcOQt0wtpg9liHcbK5vGTFtiA5q8hmyMWMplFj/zfJg50Na581zS32Q/Ef2BKtM J43+Mdq9KOJA2P0xZPN341KAr7jFc3xCi8X+oa8lUkLUeWuE47eSs032vbgFCNu4vFbOI+ 1IyDRQWP0wf5zrCHBiM0BjvyDkn6JYD8764C3jgIpRsV6PVgnTfroeaoAwR/frF0u/U6WX 8SnTukr8Vi+i32xxLxuRDu8V/24ijN+AtxePWc/cpW4+Qf1hl/OxZCCGEyb8GQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777891427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=889+Bze4fxhZZCKhr16iohDBKenwN0EM/ivLny0IVjs=; b=b/OhIxPDxz9iO6Fg+sh8Crc5MsI3LyNaIz0gXOM44YSY1mzPrMnBWoIahESQHSJC6Ou7Fq LURchqKEYf5ltdAQ== Date: Mon, 04 May 2026 12:43:40 +0200 Subject: [PATCH v2 1/2] vsprintf: Only export no_hash_pointers to test module Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260504-restricted-pointers-kunit-test-v2-1-19e8b1c0fbeb@linutronix.de> References: <20260504-restricted-pointers-kunit-test-v2-0-19e8b1c0fbeb@linutronix.de> In-Reply-To: <20260504-restricted-pointers-kunit-test-v2-0-19e8b1c0fbeb@linutronix.de> To: Andrew Morton , Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1777891425; l=967; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=G/NwhjonqqSmR/FirRofYlGNb0Txdq6OZWjiRo75Ikw=; b=zHO+cXAPIdfsGADmgPu3+97KDqKighxH3RxsThRmSzqvwFEqYH6zfm3mQ/nP2N27wbt+dZnlL V1CzmBoMoLeBO1S4gJiiiHUCSObAFdhvv+7vYoUDj4C1vg9p6L8qb5r X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Aside from the printf test module, no module should ever use this symbol. Suggested-by: Petr Mladek Link: https://lore.kernel.org/all/aWpwMyFEfpCNN297@pathway.suse.cz/ Suggested-by: Andy Shevchenko Link: https://lore.kernel.org/all/aW3em-KplLVofU5z@smile.fi.intel.com/ Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- 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 @@ =20 /* 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 =20 /* * Hashed pointers policy selected by "hash_pointers=3D..." boot param --=20 2.53.0 From nobody Sun Jun 14 02:33:37 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93E28399369 for ; Mon, 4 May 2026 10:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777891430; cv=none; b=QPKwp2apvB1DLVNl0g0+arWKceC6ZepfOZ5FnMwlS9rlEld7F1v/UmrZ42lZ7pRZcKrLN7m0S6S0RsLjqkfDgL8FEADQIjp+InFLYN2l77UKYnGFt8lNBMD2eUEjt9XjYV4kmCoUEBZroG+FvoqY9pFg/smSVYcxB7C7HNmJ1kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777891430; c=relaxed/simple; bh=hV/2VoC7YZGzAKaSF1oygrU1hu9Mjj2m1ZbEfcs7TIc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SmHP3kniHrqN5cTNp6DI6d2Nu+k0ckFsvKKh4saRd7UZr6ur7pWDpHfVk84Y5Nq8XNGTPL17Aznr1nZdIaw8W3M0lx7fyV5tK+TkoHW1tJ4x5Ba+2+wh0i4/VJKiJ/ME130W3F0XeNa2hfXxpBTq/uST2d3C1TwLj+Z97jgagBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I9ATFEXn; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nbyymvId; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I9ATFEXn"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nbyymvId" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777891427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZhtklVNSbQ8uJDq+/N7vMIkq1zkig4Zok5WZ4jqPHM=; b=I9ATFEXndHJOc/g+hUz2RrZSzZ8VBaSOJGAbNWI9F17KvYNthIm4EERroMzdxGJWWhuxj3 VgCZWoStLIXS8bgi16ivJ+D/oJLkcD3aivs4mm+2xNhPiYMvhR55zipAHloP9M+cSmaklW bESKmvkEck/cXTM1nKZj5pLzzfmnBbhwbX7PeisyPxO/XVjKb8B1znh0JffoVvgEaIBmGI /YExSuzAqpyzqmnnPddOxPHs0TnKsJ1TSRxOSCftD6cy7OmrVmrhrMZKNfVNZi40Hc1MBo E23ynv+sg+gGn8C1waQfvkvF/S/5c0GMDzWVKXdbiN2cOcZ+3a79/rTa6L41Ug== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777891427; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZhtklVNSbQ8uJDq+/N7vMIkq1zkig4Zok5WZ4jqPHM=; b=nbyymvIdlyzJMSnOMmkOhYcR8r65PZ5lHGmdlCEUds4+p1rsgl66qYjP24mHywM2xg5lKS wxjIBL2WsPrdldCQ== Date: Mon, 04 May 2026 12:43:41 +0200 Subject: [PATCH v2 2/2] vsprintf: Add test for restricted kernel pointers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260504-restricted-pointers-kunit-test-v2-2-19e8b1c0fbeb@linutronix.de> References: <20260504-restricted-pointers-kunit-test-v2-0-19e8b1c0fbeb@linutronix.de> In-Reply-To: <20260504-restricted-pointers-kunit-test-v2-0-19e8b1c0fbeb@linutronix.de> To: Andrew Morton , Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1777891425; l=1792; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=hV/2VoC7YZGzAKaSF1oygrU1hu9Mjj2m1ZbEfcs7TIc=; b=sdoTmfN3dyXuBXUj6qFTjhzmTozW3wLHYuDroaayLGnurvIuMUaibCdOXFhgIywrIQLnkc7R4 1ud+1ijfjieD6pj17se+E7t9/oT5vK6RFhRGorRg94qOfsEmW0hdeAB X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Fill out the tests for restricted kernel pointers, using the %pK format. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- 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; + } } =20 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, cons= t void *ptr, } =20 int kptr_restrict __read_mostly; +#if IS_MODULE(CONFIG_PRINTF_KUNIT_TEST) +EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit"); +#endif =20 static noinline_for_stack char *restricted_pointer(char *buf, char *end, const void *ptr, --=20 2.53.0