Skip to contentSkip to conversation

vmalloc: Fix NULL pointer dereference in is_vm_area_hugepages()

PATCH Applied Hui Zhu 3 participants 3 messages May 29 – Jun 1

Subsystems (2)
lore
Share & tools
lore

Hui Zhu

author
#0 lore raw

PATCH 1/1 vmalloc: Fix NULL pointer dereference in is_vm_area_hugepages()

From: Hui Zhu <[email protected]>

find_vm_area() can return NULL if the given address is not a valid vmalloc area. Check the return value before dereferencing it to avoid a kernel crash.

Fixes 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings")
---
 include/linux/vmalloc.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/vmalloc.h +3 -1
index 3b02c0c6b371..d87dc7f77f4e 100644
@@ -265,7 +265,9 @@ static inline bool is_vm_area_hugepages(const void *addr)
 	 * allocated in the vmalloc layer.
 	 */
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC
-	return find_vm_area(addr)->page_order > 0;
+	struct vm_struct *area = find_vm_area(addr);
+
+	return area && area->page_order > 0;
 #else
 	return false;
 #endif
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Hui Zhu

From: Hui Zhu <[email protected]>

find_vm_area() can return NULL if the given address is not a valid vmalloc area. Check the return value before dereferencing it to avoid a kernel crash.

Fixes 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings")

---

I think this makes sense from API PoV.

Quoted 18 lines
 include/linux/vmalloc.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/vmalloc.h +3 -1
index 3b02c0c6b371..d87dc7f77f4e 100644
@@ -265,7 +265,9 @@ static inline bool is_vm_area_hugepages(const void *addr)
 	 * allocated in the vmalloc layer.
 	 */
 #ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC
-	return find_vm_area(addr)->page_order > 0;
+	struct vm_struct *area = find_vm_area(addr);
+
+	return area && area->page_order > 0;
 #else
 	return false;
 #endif
maintainer Reviewed-by
#2 lore raw
Quoted 9 lines · Dev Jain
Quoted 6 lines · Hui Zhu

From: Hui Zhu <[email protected]>

find_vm_area() can return NULL if the given address is not a valid vmalloc area. Check the return value before dereferencing it to avoid a kernel crash.

Quoted 8 lines
Quoted 3 lines
Fixes 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings")

---

I think this makes sense from API PoV.

--
Uladzislau Rezki