Skip to contentSkip to conversation

rmap: validate pointer in anon_vma_clone

PATCH In review Leon Ma 2 participants 3 messages May 7, 2014

Subsystems (2)
lore
Share & tools
lore

Leon Ma

author
#0 lore raw

PATCH 1/1 rmap: validate pointer in anon_vma_clone

If memory allocation failed in first loop, root will be NULL and will lead to kernel panic.

---
 mm/rmap.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/rmap.c +4 -2
index 9c3e773..6e53aed 100644
@@ -246,8 +246,10 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
 
 		avc = anon_vma_chain_alloc(GFP_NOWAIT | __GFP_NOWARN);
 		if (unlikely(!avc)) {
-			unlock_anon_vma_root(root);
-			root = NULL;
+			if (!root) {
+				unlock_anon_vma_root(root);
+				root = NULL;
+			}
 			avc = anon_vma_chain_alloc(GFP_KERNEL);
 			if (!avc)
 				goto enomem_failure;
Signature · 1 line
1.7.9.5
#1 lore raw

Sorry, my fault. It's already validated in unlock_anon_vma_root().

BR
Leon

-----Original Message-----
From: Ma, Xindong
Sent: Wednesday, May 07, 2014 10:32 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Ma, Xindong
Subject: [PATCH] rmap: validate pointer in anon_vma_clone

If memory allocation failed in first loop, root will be NULL and will lead to kernel panic.

---
 mm/rmap.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
mm/rmap.c +4 -2
index 9c3e773..6e53aed 100644
@@ -246,8 +246,10 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
 
 		avc = anon_vma_chain_alloc(GFP_NOWAIT | __GFP_NOWARN);
 		if (unlikely(!avc)) {
-			unlock_anon_vma_root(root);
-			root = NULL;
+			if (!root) {
+				unlock_anon_vma_root(root);
+				root = NULL;
+			}
 			avc = anon_vma_chain_alloc(GFP_KERNEL);
 			if (!avc)
 				goto enomem_failure;

--
1.7.9.5

#2 lore raw
In reply to Leon Ma
Quoted 2 lines · Leon Ma

If memory allocation failed in first loop, root will be NULL and will lead to kernel panic.

Hello, Leon,

I am afraid not. unlock_anon_vma_root() has a sanity check NULLness of root, so it is impossible to panic for a dangling root pointer.

Thanks,
Jianyu Zhan

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>