From 02543a4e96760a347fb9733bc8a0506a19270ec2 Mon Sep 17 00:00:00 2001 From: Vasyl Gomonovych Date: Thu, 23 Nov 2017 17:00:42 +0100 Subject: [PATCH] lkdtm: Missing kmalloc check Handling a possible memory allocation failure. Signed-off-by: Vasyl Gomonovych Acked-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/misc/lkdtm_heap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/misc/lkdtm_heap.c b/drivers/misc/lkdtm_heap.c index f5494a6d4be5..65026d7de130 100644 --- a/drivers/misc/lkdtm_heap.c +++ b/drivers/misc/lkdtm_heap.c @@ -16,6 +16,8 @@ void lkdtm_OVERWRITE_ALLOCATION(void) { size_t len = 1020; u32 *data = kmalloc(len, GFP_KERNEL); + if (!data) + return; data[1024 / sizeof(u32)] = 0x12345678; kfree(data); @@ -33,6 +35,8 @@ void lkdtm_WRITE_AFTER_FREE(void) size_t offset = (len / sizeof(*base)) / 2; base = kmalloc(len, GFP_KERNEL); + if (!base) + return; pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]); pr_info("Attempting bad write to freed memory at %p\n", &base[offset]); -- 2.30.2