Re: [PATCH] lkdtm: Add kfence read after free crash type

From: Kees Cook
Date: Wed Nov 29 2023 - 15:22:33 EST


On Mon, Nov 27, 2023 at 03:49:45PM -0800, Stephen Boyd wrote:
> Add the ability to allocate memory from kfence and trigger a read after
> free on that memory to validate that kfence is working properly. This is
> used by ChromeOS integration tests to validate that kfence errors can be
> collected on user devices and parsed properly.

This looks really good; thanks for adding this!

>
> Signed-off-by: Stephen Boyd <swboyd@xxxxxxxxxxxx>
> ---
> drivers/misc/lkdtm/heap.c | 64 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c
> index 0ce4cbf6abda..608872bcc7e0 100644
> --- a/drivers/misc/lkdtm/heap.c
> +++ b/drivers/misc/lkdtm/heap.c
> @@ -4,6 +4,7 @@
> * page allocation and slab allocations.
> */
> #include "lkdtm.h"
> +#include <linux/kfence.h>
> #include <linux/slab.h>
> #include <linux/vmalloc.h>
> #include <linux/sched.h>
> @@ -132,6 +133,66 @@ static void lkdtm_READ_AFTER_FREE(void)
> kfree(val);
> }
>
> +#if IS_ENABLED(CONFIG_KFENCE)

I really try hard to avoid having tests disappear depending on configs,
and instead report the expected failure case (as you have). Can this be
built without the IS_ENABLED() tests?

--
Kees Cook