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>] [day] [month] [year] [list]
Date: Sun,  9 Jun 2024 16:35:13 +0900
From: Vincent Mailhol <mailhol.vincent@...adoo.fr>
To: Yury Norov <yury.norov@...il.com>,
	Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: linux-kernel@...r.kernel.org,
	Vincent Mailhol <mailhol.vincent@...adoo.fr>
Subject: [PATCH] linux/bits: simplify GENMASK_INPUT_CHECK()

The __builtin_choose_expr() works with a wide range of expressions.
When these are Boolean expressions, some logical simplifications can
be applied.

This is the case of:

  __builtin_choose_expr(condition, boolean_expression, false);

which can be simplified to:

  condition && boolean_expression;

Because of the shortcut logic of the && operator, this works even if
the condition is, for example, __is_constexpr().

Apply above simplification to GENMASK_INPUT_CHECK().

This change passes the unit tests from CONFIG_BITS_TEST, including the
extra negative tests provided under #ifdef TEST_GENMASK_FAILURES [1].

[1] commit 6d511020e13d ("lib/test_bits.c: add tests of GENMASK")
Link: https://git.kernel.org/torvalds/c/6d511020e13d

Signed-off-by: Vincent Mailhol <mailhol.vincent@...adoo.fr>
---
 include/linux/bits.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/bits.h b/include/linux/bits.h
index 0eb24d21aac2..4cf27f329579 100644
--- a/include/linux/bits.h
+++ b/include/linux/bits.h
@@ -21,8 +21,7 @@
 #if !defined(__ASSEMBLY__)
 #include <linux/build_bug.h>
 #define GENMASK_INPUT_CHECK(h, l) \
-	(BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
-		__is_constexpr((l) > (h)), (l) > (h), 0)))
+	BUILD_BUG_ON_ZERO(__is_constexpr((l) > (h)) && (l) > (h))
 #else
 /*
  * BUILD_BUG_ON_ZERO is not available in h files included from asm files,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ