lkdtm: Missing kmalloc check
authorVasyl Gomonovych <gomonovych@gmail.com>
Thu, 23 Nov 2017 16:00:42 +0000 (17:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2017 15:33:03 +0000 (16:33 +0100)
Handling a possible memory allocation failure.

Signed-off-by: Vasyl Gomonovych <gomonovych@gmail.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/lkdtm_heap.c

index f5494a6d4be5eee7c6eafa04789a09c0cf6e3667..65026d7de1307d32b9e060358dadcc04ef0bdf56 100644 (file)
@@ -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]);