[PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler
Sascha Hauer
sha at pengutronix.de
Fri Nov 10 05:08:13 PST 2023
On Thu, Nov 09, 2023 at 12:38:06PM +0100, Ahmad Fatoum wrote:
> 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 at pengutronix.de>
> ---
> lib/kasan/test_kasan.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
Applied, thanks
Sascha
>
> 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
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list