summaryrefslogtreecommitdiffstats
path: root/lib/kasan/test_kasan.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-11-09 12:38:06 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-11-10 14:08:01 +0100
commit187b8536123615df7528dbb2e24915bd26971c38 (patch)
tree69de15e3a0f2443dd7dd5c7faf79c6e70cc24e3e /lib/kasan/test_kasan.c
parent37ec6d34b4b049241d788ba1f380b27c79f4a91a (diff)
downloadbarebox-187b8536123615df7528dbb2e24915bd26971c38.tar.gz
barebox-187b8536123615df7528dbb2e24915bd26971c38.tar.xz
KASan: test_kasan: hide buggy accesses from compiler
Once we add __alloc_size attributes to allocations, GCC will complain about violation of memory safety in test_kasan.c. That memory violation is intended though as test_kasan is meant to trigger kasan at runtime to verify correct operation. Silence the warnings by hiding the origin of ptr, so the compiler loses context about the size of the allocation. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231109113807.1193935-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib/kasan/test_kasan.c')
-rw-r--r--lib/kasan/test_kasan.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/kasan/test_kasan.c b/lib/kasan/test_kasan.c
index 14511cdb80..a74251a6d9 100644
--- a/lib/kasan/test_kasan.c
+++ b/lib/kasan/test_kasan.c
@@ -38,6 +38,8 @@ static noinline void malloc_oob_right(void)
return;
}
+ OPTIMIZER_HIDE_VAR(ptr);
+
ptr[size] = 'x';
free(ptr);
@@ -55,6 +57,8 @@ static noinline void malloc_oob_left(void)
return;
}
+ OPTIMIZER_HIDE_VAR(ptr);
+
*ptr = *(ptr - 1);
free(ptr);
}
@@ -75,6 +79,8 @@ static noinline void malloc_oob_realloc_more(void)
return;
}
+ OPTIMIZER_HIDE_VAR(ptr2);
+
ptr2[size2] = 'x';
free(ptr2);
@@ -95,6 +101,8 @@ static noinline void malloc_oob_realloc_less(void)
return;
}
+ OPTIMIZER_HIDE_VAR(ptr2);
+
ptr2[size2] = 'x';
free(ptr2);
@@ -115,6 +123,9 @@ static noinline void malloc_oob_16(void)
free(ptr2);
return;
}
+
+ OPTIMIZER_HIDE_VAR(ptr1);
+
*ptr1 = *ptr2;
free(ptr1);
free(ptr2);