Skip to contentSkip to conversation

Modify the check condition

PATCH In review [email protected] 2 participants 2 messages Sep 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modify the check condition

From: Yang Guang <[email protected]>

The vma may be NULL, and accessing the member of vma like "vma->vm_start" in calling follow_phys may occur segmentation fault.
So it should check vma at beginning. If vma is null, it will return. And the if condition won't execute "vm->vm_flags".

---
 arch/x86/mm/pat/memtype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/pat/memtype.c +1 -1
index 4ba2a3ee4bce..b7108b37b754 100644
@@ -1089,7 +1089,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
 	resource_size_t paddr;
 	unsigned long prot;
 
-	if (vma && !(vma->vm_flags & VM_PAT))
+	if (!(vma) || !(vma->vm_flags & VM_PAT))
 		return;
 
 	/* free the chunk starting from pfn or the whole chunk */
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 17 lines · On Sat, Sep 18, 2021 at 06:52:32AM +0000, [email protected] wrote:

From: Yang Guang <[email protected]>

The vma may be NULL, and accessing the member of vma like "vma->vm_start" in calling follow_phys may occur segmentation fault.
So it should check vma at beginning. If vma is null, it will return. And the if condition won't execute "vm->vm_flags".

---
 arch/x86/mm/pat/memtype.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/pat/memtype.c +0 -0
index 4ba2a3ee4bce..b7108b37b754 100644

arch/x86/mm/pat/memtype.c void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn, · line 1093

Quoted 6 lines
arch/x86/mm/pat/memtype.c +1 -1
@@ -1089,7 +1089,7 @@ void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
 	resource_size_t paddr;
 	unsigned long prot;
 
-	if (vma && !(vma->vm_flags & VM_PAT))
+	if (!(vma) || !(vma->vm_flags & VM_PAT))
 		return;

Yet another braindead patch that shows you don't actually understand C.