Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lkdtm: Missing kmalloc check

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>

authored by

Vasyl Gomonovych and committed by
Greg Kroah-Hartman
02543a4e 148ade2c

+4
+4
drivers/misc/lkdtm_heap.c
··· 16 16 { 17 17 size_t len = 1020; 18 18 u32 *data = kmalloc(len, GFP_KERNEL); 19 + if (!data) 20 + return; 19 21 20 22 data[1024 / sizeof(u32)] = 0x12345678; 21 23 kfree(data); ··· 35 33 size_t offset = (len / sizeof(*base)) / 2; 36 34 37 35 base = kmalloc(len, GFP_KERNEL); 36 + if (!base) 37 + return; 38 38 pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]); 39 39 pr_info("Attempting bad write to freed memory at %p\n", 40 40 &base[offset]);