* [PATCH] selftests/exec: reject zero as power-of-two alignment
@ 2026-09-04 15:40 Paul Dolan
0 siblings, 0 replies; only message in thread
From: Paul Dolan @ 2026-09-04 15:40 UTC (permalink / raw)
To: Kees Cook, Shuah Khan; +Cc: linux-mm, linux-kselftest, linux-kernel
The load_address test reports whether an alignment was found separately
from whether that alignment is a power of two. However, the usual
x & (x - 1) check also evaluates to zero when x is zero, causing a
missing alignment to be reported as a power of two.
Require the alignment to be non-zero when reporting the power-of-two
result.
Fixes: b57a2907c9d9 ("selftests/exec: Build both static and non-static load_address tests")
Signed-off-by: Paul Dolan <paul.dolan.dev@gmail.com>
---
tools/testing/selftests/exec/load_address.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/exec/load_address.c b/tools/testing/selftests/exec/load_address.c
index 55fd3732f029..e279d85e8f19 100644
--- a/tools/testing/selftests/exec/load_address.c
+++ b/tools/testing/selftests/exec/load_address.c
@@ -92,9 +92,10 @@ int main(int argc, char **argv)
/* Is the alignment sane? */
pow2 = extracted.alignment & (extracted.alignment - 1);
- ksft_test_result(pow2 == 0,
- "Alignment is%s a power of 2: %#llx\n",
- pow2 == 0 ? "" : " NOT", extracted.alignment);
+ ksft_test_result(extracted.alignment != 0 && pow2 == 0,
+ "Alignment is%s a power of 2: %#llx\n",
+ extracted.alignment != 0 && pow2 == 0 ? "" : " NOT",
+ extracted.alignment);
/* Is the load address aligned? */
misalign = extracted.load_address & (extracted.alignment - 1);
--
2.55.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-04 15:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-04 15:40 [PATCH] selftests/exec: reject zero as power-of-two alignment Paul Dolan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®