# Re: \[PATCH v2\] kasan: fix unit tests with CONFIG\_UBSAN\_LOCAL\_BOUNDS enabled

- From: Alexander Potapenko \<glider@google.com\>
- Date: 2021-05-07 07:16:06 
- List: linux-mm
- Page: https://ratatoskr.run/linux-mm/2021/05/6508093
- Thread: https://ratatoskr.run/linux-mm/2021/05/6508090/t.md

```text
On Fri, May 7, 2021 at 4:59 AM Peter Collingbourne [ref] wrote:
>
> These tests deliberately access these arrays out of bounds,
> which will cause the dynamic local bounds checks inserted by
> CONFIG_UBSAN_LOCAL_BOUNDS to fail and panic the kernel. To avoid this
> problem, access the arrays via volatile pointers, which will prevent
> the compiler from being able to determine the array bounds.

Thanks for tracking this down! These crashes have been puzzling me for a while.

> These accesses use volatile pointers to char (char *volatile) rather
> than the more conventional pointers to volatile char (volatile char *)
> because we want to prevent the compiler from making inferences about
> the pointer itself (i.e. its array bounds), not the data that it
> refers to.
>

> Signed-off-by: Peter Collingbourne <redacted>
Tested-by: Alexander Potapenko <glider@google.com>

(also note you are missing the Acked-by: here that Andrey gave)

```
