mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 19:07:52 +00:00
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>
This commit is contained in:
parent
148ade2c4d
commit
02543a4e96
1 changed files with 4 additions and 0 deletions
|
@ -16,6 +16,8 @@ void lkdtm_OVERWRITE_ALLOCATION(void)
|
||||||
{
|
{
|
||||||
size_t len = 1020;
|
size_t len = 1020;
|
||||||
u32 *data = kmalloc(len, GFP_KERNEL);
|
u32 *data = kmalloc(len, GFP_KERNEL);
|
||||||
|
if (!data)
|
||||||
|
return;
|
||||||
|
|
||||||
data[1024 / sizeof(u32)] = 0x12345678;
|
data[1024 / sizeof(u32)] = 0x12345678;
|
||||||
kfree(data);
|
kfree(data);
|
||||||
|
@ -33,6 +35,8 @@ void lkdtm_WRITE_AFTER_FREE(void)
|
||||||
size_t offset = (len / sizeof(*base)) / 2;
|
size_t offset = (len / sizeof(*base)) / 2;
|
||||||
|
|
||||||
base = kmalloc(len, GFP_KERNEL);
|
base = kmalloc(len, GFP_KERNEL);
|
||||||
|
if (!base)
|
||||||
|
return;
|
||||||
pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
|
pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
|
||||||
pr_info("Attempting bad write to freed memory at %p\n",
|
pr_info("Attempting bad write to freed memory at %p\n",
|
||||||
&base[offset]);
|
&base[offset]);
|
||||||
|
|
Loading…
Reference in a new issue