From: Petr Tesarik Date: Tue, 19 Nov 2024 11:37:39 +0000 (+0100) Subject: mm/rodata_test: verify test data is unchanged, rather than non-zero X-Git-Tag: v6.14-rc1~77^2~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58d534c8c6aa5c5f09fbcb162afb85b91f200560;p=thirdparty%2Fkernel%2Flinux.git mm/rodata_test: verify test data is unchanged, rather than non-zero Verify that the test variable holds the initialization value, rather than any non-zero value. Link: https://lkml.kernel.org/r/386ffda192eb4a26f68c526c496afd48a5cd87ce.1732016064.git.ptesarik@suse.com Signed-off-by: Petr Tesarik Reviewed-by: Kees Cook Cc: Jinbum Park Signed-off-by: Andrew Morton --- diff --git a/mm/rodata_test.c b/mm/rodata_test.c index 3b60425d80fea..e7173fcd210ca 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -12,7 +12,8 @@ #include #include -static const int rodata_test_data = 0xC3; +#define TEST_VALUE 0xC3 +static const int rodata_test_data = TEST_VALUE; void rodata_test(void) { @@ -20,7 +21,7 @@ void rodata_test(void) /* test 1: read the value */ /* If this test fails, some previous testrun has clobbered the state */ - if (!READ_ONCE(rodata_test_data)) { + if (unlikely(READ_ONCE(rodata_test_data) != TEST_VALUE)) { pr_err("test 1 fails (start data)\n"); return; } @@ -33,7 +34,7 @@ void rodata_test(void) } /* test 3: check the value hasn't changed */ - if (READ_ONCE(rodata_test_data) == zero) { + if (unlikely(READ_ONCE(rodata_test_data) != TEST_VALUE)) { pr_err("test data was changed\n"); return; }