[PATCH] mm: kfence: export kfence_enabled as global variables

Marco Elver elver at google.com
Mon Feb 6 23:19:00 PST 2023


On Tue, 7 Feb 2023 at 07:15, Zhenhua Huang <quic_zhenhuah at quicinc.com> wrote:
>
> Export the variable to ease the judgement of whether kfence enabled
> at runtime. It should be more precise than through kernel config
> "CONFIG_KFENCE".
>
> For example We can disable kfence at runtime using bootargs
> "kfence.sample_interval=0" but CONFIG_KFENCE enabled.
> It was false positive.
>
> Signed-off-by: Zhenhua Huang <quic_zhenhuah at quicinc.com>
> ---
>  arch/arm64/mm/pageattr.c | 3 ++-
>  include/linux/kfence.h   | 2 ++
>  mm/kfence/core.c         | 2 +-
>  3 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index 79dd201..208d780 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -7,6 +7,7 @@
>  #include <linux/module.h>
>  #include <linux/sched.h>
>  #include <linux/vmalloc.h>
> +#include <linux/kfence.h>
>
>  #include <asm/cacheflush.h>
>  #include <asm/set_memory.h>
> @@ -27,7 +28,7 @@ bool can_set_direct_map(void)
>          * protect/unprotect single pages.
>          */
>         return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() ||
> -               IS_ENABLED(CONFIG_KFENCE);
> +               kfence_enabled;

Unfortunately this won't work, because it's possible to enable KFENCE
after the kernel has booted with e.g.: echo 100 >
/sys/module/kfence/parameters/sample_interval

What is the problem you have encountered? Is the page-granular direct
map causing issues?



More information about the linux-arm-kernel mailing list