mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] KASan: test_kasan: hide buggy accesses from compiler
Date: Fri, 10 Nov 2023 14:08:13 +0100	[thread overview]
Message-ID: <20231110130813.GX3359458@pengutronix.de> (raw)
In-Reply-To: <20231109113807.1193935-1-a.fatoum@pengutronix.de>

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@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 |



      parent reply	other threads:[~2023-11-10 13:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231110130813.GX3359458@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox