mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler
@ 2023-11-09 11:38 Ahmad Fatoum
  2023-11-09 11:38 ` [PATCH 2/2] malloc: use __attribute((alloc_size)) for dynamic memory allocation Ahmad Fatoum
  2023-11-10 13:08 ` [PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-11-09 11:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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>
---
 lib/kasan/test_kasan.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/kasan/test_kasan.c b/lib/kasan/test_kasan.c
index 14511cdb80bd..a74251a6d9ad 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);
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-10 13:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 11:38 [PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler Ahmad Fatoum
2023-11-09 11:38 ` [PATCH 2/2] malloc: use __attribute((alloc_size)) for dynamic memory allocation Ahmad Fatoum
2023-11-10 13:08 ` [PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox