Skip to contentSkip to conversation

Fixes: null pointer dereference in pfnmap_lockdep_assert

PATCH Applied Manas 2 participants 2 messages Oct 4, 2024 – Oct 7, 2024

Subsystems (2)
lore
Share & tools
lore

Manas

author
#0 lore raw

PATCH v4 1/1 Fixes: null pointer dereference in pfnmap_lockdep_assert

syzbot has pointed to a possible null pointer dereference in pfnmap_lockdep_assert. vm_file member of vm_area_struct is being dereferenced without any checks.

This fix assigns mapping only if vm_file is not NULL.

---
This bug[1] triggers a general protection fault in follow_pfnmap_start function. An assertion pfnmap_lockdep_assert inside this function dereferences vm_file member of vm_area_struct. And panic gets triggered when vm_file is NULL.

This patch assigns mapping only if vm_file is not NULL.

[1] https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b

---
Changes in v4:
- v4: simplify ternary conditional
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- v3: use assigned var instead of accessing member again
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- v2: use ternary operator according to feedback
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 mm/memory.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
mm/memory.c +5 -2
index 2366578015ad..4e4d598496a8 100644
@@ -6346,10 +6346,13 @@ static inline void pfnmap_args_setup(struct follow_pfnmap_args *args,
 static inline void pfnmap_lockdep_assert(struct vm_area_struct *vma)
 {
 #ifdef CONFIG_LOCKDEP
-	struct address_space *mapping = vma->vm_file->f_mapping;
+	struct address_space *mapping = NULL;
+
+	if (vma->vm_file)
+		mapping = vma->vm_file->f_mapping;
 
 	if (mapping)
-		lockdep_assert(lockdep_is_held(&vma->vm_file->f_mapping->i_mmap_rwsem) ||
+		lockdep_assert(lockdep_is_held(&mapping->i_mmap_rwsem) ||
 			       lockdep_is_held(&vma->vm_mm->mmap_lock));
 	else
 		lockdep_assert(lockdep_is_held(&vma->vm_mm->mmap_lock));

---
base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20241003-fix-null-deref-6bfa0337efc3

Best regards,

Signature · 1 line
Manas <[email protected]>
Reviewed-by on v4 1/1
#1 lore raw
Quoted 16 lines · On Fri, Oct 04, 2024 at 11:12:16PM +0530, Manas via B4 Relay wrote:

From: Manas <[email protected]>

syzbot has pointed to a possible null pointer dereference in pfnmap_lockdep_assert. vm_file member of vm_area_struct is being dereferenced without any checks.

This fix assigns mapping only if vm_file is not NULL.

---
This bug[1] triggers a general protection fault in follow_pfnmap_start function. An assertion pfnmap_lockdep_assert inside this function dereferences vm_file member of vm_area_struct. And panic gets triggered when vm_file is NULL.

Quoted 5 lines

This patch assigns mapping only if vm_file is not NULL.

[1] https://syzkaller.appspot.com/bug?extid=093d096417e7038a689b

Signature · 1 line
Peter Xu