]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vmalloc: fix NULL pointer dereference in is_vm_area_hugepages()
authorHui Zhu <zhuhui@kylinos.cn>
Fri, 29 May 2026 01:41:30 +0000 (09:41 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 9 Jun 2026 01:21:31 +0000 (18:21 -0700)
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.

Link: https://lore.kernel.org/20260529014130.671291-1-hui.zhu@linux.dev
Fixes: 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings")
Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/vmalloc.h

index 3b02c0c6b371871b2a62cb733725cc84289d5def..d87dc7f77f4e8a6f662fbdd39461de342626e378 100644 (file)
@@ -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