On 7/9/26 3:01 AM, Alexis Lothoré (eBPF Foundation) wrote:
> Add two simple helpers to allow checking whether KASAN for eBPF tests
> should be executed:
> - one helper to check if BPF_JIT_KASAN is enabled in kernel
>   configuration
> - one helper to check if the kernel is running with kasan_multi_shot
>   (otherwise only the first test will be able to trigger a report)
> 
> Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]>
> ---
> Changes in v5:
> - add kasan_multi_shot helper
> 
> Changes in v2:
> - fix condition
> ---
>  tools/testing/selftests/bpf/unpriv_helpers.c | 10 ++++++++++
>  tools/testing/selftests/bpf/unpriv_helpers.h |  2 ++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/unpriv_helpers.c 
> b/tools/testing/selftests/bpf/unpriv_helpers.c
> index f997d7ec8fd0..95be83937883 100644
> --- a/tools/testing/selftests/bpf/unpriv_helpers.c
> +++ b/tools/testing/selftests/bpf/unpriv_helpers.c
> @@ -142,3 +142,13 @@ bool get_unpriv_disabled(void)
>       }
>       return mitigations_off;
>  }
> +
> +bool get_kasan_jit_enabled(void)
> +{
> +     return config_contains("CONFIG_BPF_JIT_KASAN=y") == 1;
> +}
> +
> +bool get_kasan_multi_shot_enabled(void)
> +{
> +     return cmdline_contains("kasan_multi_shot");
> +}

Acked-by: Ihor Solodrai <[email protected]>

> diff --git a/tools/testing/selftests/bpf/unpriv_helpers.h 
> b/tools/testing/selftests/bpf/unpriv_helpers.h
> index 151f67329665..a7ceb51577cd 100644
> --- a/tools/testing/selftests/bpf/unpriv_helpers.h
> +++ b/tools/testing/selftests/bpf/unpriv_helpers.h
> @@ -5,3 +5,5 @@
>  #define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
>  
>  bool get_unpriv_disabled(void);
> +bool get_kasan_jit_enabled(void);
> +bool get_kasan_multi_shot_enabled(void);
> 


Reply via email to