Messages in this thread Patch in this message | | | From | Ren Yu <> | Subject | [PATCH 2/3] lkdtm/perms: Check possible NULL pointer returned by kmalloc(),vmalloc() | Date | Mon, 25 Jul 2022 16:11:53 +0800 |
| |
As the possible alloc failure of the kmalloc() and vmalloc(),the return pointer could be NULL.therefore it should be better to check it.
Signed-off-by: Ren Yu <renyu@nfschina.com> --- drivers/misc/lkdtm/perms.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index b93404d65650..34b43b9ea1f1 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -180,6 +180,9 @@ static void lkdtm_EXEC_STACK(void) static void lkdtm_EXEC_KMALLOC(void) { u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL); + if (!kmalloc_area) + return; + execute_location(kmalloc_area, CODE_WRITE); kfree(kmalloc_area); } @@ -187,6 +190,9 @@ static void lkdtm_EXEC_KMALLOC(void) static void lkdtm_EXEC_VMALLOC(void) { u32 *vmalloc_area = vmalloc(EXEC_SIZE); + if (!vmalloc_area) + return; + execute_location(vmalloc_area, CODE_WRITE); vfree(vmalloc_area); } -- 2.11.0
| |