Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <ptesarik@suse.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Cc: Jinbum Park <jinb.park7@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Petr Tesarik and committed by
Andrew Morton
58d534c8 db27ad8b

+4 -3
+4 -3
mm/rodata_test.c
··· 12 12 #include <linux/mm.h> 13 13 #include <asm/sections.h> 14 14 15 - static const int rodata_test_data = 0xC3; 15 + #define TEST_VALUE 0xC3 16 + static const int rodata_test_data = TEST_VALUE; 16 17 17 18 void rodata_test(void) 18 19 { ··· 21 20 22 21 /* test 1: read the value */ 23 22 /* If this test fails, some previous testrun has clobbered the state */ 24 - if (!READ_ONCE(rodata_test_data)) { 23 + if (unlikely(READ_ONCE(rodata_test_data) != TEST_VALUE)) { 25 24 pr_err("test 1 fails (start data)\n"); 26 25 return; 27 26 } ··· 34 33 } 35 34 36 35 /* test 3: check the value hasn't changed */ 37 - if (READ_ONCE(rodata_test_data) == zero) { 36 + if (unlikely(READ_ONCE(rodata_test_data) != TEST_VALUE)) { 38 37 pr_err("test data was changed\n"); 39 38 return; 40 39 }