From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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ßschuh --- 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