Skip to contentSkip to conversation

lkdtm: perms: Increase pointer assignment check

PATCH New Li zeming 1 participant 1 message Feb 16, 2023

Subsystems (2)
lore
Share & tools
lore

Li zeming

author
#0 lore raw

PATCH 1/1 lkdtm: perms: Increase pointer assignment check

Increase the check after the pointer allocates memory. If these two functions are used, at least increase some robustness.

---
 drivers/misc/lkdtm/perms.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/misc/lkdtm/perms.c +8 -4
index b93404d65650..a5d8dce5ce49 100644
@@ -180,15 +180,19 @@ static void lkdtm_EXEC_STACK(void)
 static void lkdtm_EXEC_KMALLOC(void)
 {
 	u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
-	execute_location(kmalloc_area, CODE_WRITE);
-	kfree(kmalloc_area);
+	if (kmalloc_area) {
+		execute_location(kmalloc_area, CODE_WRITE);
+		kfree(kmalloc_area);
+	}
 }
 
 static void lkdtm_EXEC_VMALLOC(void)
 {
 	u32 *vmalloc_area = vmalloc(EXEC_SIZE);
-	execute_location(vmalloc_area, CODE_WRITE);
-	vfree(vmalloc_area);
+	if (vmalloc_area) {
+		execute_location(vmalloc_area, CODE_WRITE);
+		vfree(vmalloc_area);
+	}
 }
 
 static void lkdtm_EXEC_RODATA(void)
Signature · 1 line
2.18.2