diff options
author | Vasyl Gomonovych <gomonovych@gmail.com> | 2017-11-23 11:00:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-11-28 10:33:03 -0500 |
commit | 02543a4e96760a347fb9733bc8a0506a19270ec2 (patch) | |
tree | c0531043cf9875fe376720b4d98ffc29242ebde3 | |
parent | 148ade2c4d4f46b3ecc1ddad1c762371e8708e35 (diff) |
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>
-rw-r--r-- | drivers/misc/lkdtm_heap.c | 4 |
1 files changed, 4 insertions, 0 deletions
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) | |||
16 | { | 16 | { |
17 | size_t len = 1020; | 17 | size_t len = 1020; |
18 | u32 *data = kmalloc(len, GFP_KERNEL); | 18 | u32 *data = kmalloc(len, GFP_KERNEL); |
19 | if (!data) | ||
20 | return; | ||
19 | 21 | ||
20 | data[1024 / sizeof(u32)] = 0x12345678; | 22 | data[1024 / sizeof(u32)] = 0x12345678; |
21 | kfree(data); | 23 | kfree(data); |
@@ -33,6 +35,8 @@ void lkdtm_WRITE_AFTER_FREE(void) | |||
33 | size_t offset = (len / sizeof(*base)) / 2; | 35 | size_t offset = (len / sizeof(*base)) / 2; |
34 | 36 | ||
35 | base = kmalloc(len, GFP_KERNEL); | 37 | base = kmalloc(len, GFP_KERNEL); |
38 | if (!base) | ||
39 | return; | ||
36 | pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]); | 40 | pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]); |
37 | pr_info("Attempting bad write to freed memory at %p\n", | 41 | pr_info("Attempting bad write to freed memory at %p\n", |
38 | &base[offset]); | 42 | &base[offset]); |