lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260121145731.3623-15-david.laight.linux@gmail.com>
Date: Wed, 21 Jan 2026 14:57:31 +0000
From: david.laight.linux@...il.com
To: Nathan Chancellor <nathan@...nel.org>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	Arnd Bergmann <arnd@...db.de>,
	linux-arch@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Yury Norov <yury.norov@...il.com>,
	Lucas De Marchi <lucas.demarchi@...el.com>,
	Jani Nikula <jani.nikula@...el.com>,
	Vincent Mailhol <mailhol.vincent@...adoo.fr>,
	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
	Kees Cook <keescook@...omium.org>,
	Andrew Morton <akpm@...ux-foundation.org>
Cc: David Laight <david.laight.linux@...il.com>
Subject: [PATCH next 14/14] test_bits: include some invalid input tests for GENMASK_INPUT_CHECK()

From: David Laight <david.laight.linux@...il.com>

The check for invalid 'compile time constant' parameters can easily be
changed to return 'failed' rather than generating a compile time error.
Add some tests for negative, swapped and overlarge values.

Signed-off-by: David Laight <david.laight.linux@...il.com>
---
 lib/tests/test_bits.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
index 4d3a895f490c..9642c55f5487 100644
--- a/lib/tests/test_bits.c
+++ b/lib/tests/test_bits.c
@@ -144,6 +144,22 @@ static void genmask_input_check_test(struct kunit *test)
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0);
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0);
 	BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0);
+
+	/*
+	 * Invalid input
+	 * Change GENMASK_INPUT_CHECK() return 'fail' rather than
+	 * generating a compile-time error.
+	 */
+#define GENMASK_INPUT_CHECK_FAIL() 1
+	z = 0;
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 31, -1, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 0, 1, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 8, 0, 8) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 16, 0, 16) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 32, 0, 32) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 64, 0, 64) == 0);
+	BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 128, 0, 128) == 0);
+#undef GENMASK_INPUT_CHECK_FAIL
 }
 
 
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ