Skip to contentSkip to conversation

nsproxy cloning error path fix

PATCH In review Pavel 2 participants 2 messages Aug 31, 2006

lore
Share & tools
lore

Pavel

author
#0 lore raw

PATCH 1/1 nsproxy cloning error path fix

This patch fixes copy_namespaces()'s error path.

when new nsproxy (new_ns) is created pointers to namespaces (ipc, uts) are copied from the old nsproxy. Later in copy_utsname, copy_ipcs, etc. according namespaces are get-ed. On error path needed namespaces are put-ed, so there's no need to put new nsproxy itelf as it woud cause putting namespaces for the second time.

Found when incorporating namespaces into OpenVZ kernel.

---

 nsproxy.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
kernel/nsproxy.c renamed from kernel/nsproxy.c.veboot +1 -1
@@ -115,7 +115,7 @@ out_uts:
 		put_namespace(new_ns->namespace);
 out_ns:
 	tsk->nsproxy = old_ns;
-	put_nsproxy(new_ns);
+	kfree(new_ns);
 	goto out;
 }
 
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Pavel

This patch fixes copy_namespaces()'s error path.

when new nsproxy (new_ns) is created pointers to namespaces (ipc, uts) are copied from the old nsproxy. Later in copy_utsname, copy_ipcs, etc. according namespaces are get-ed. On error path needed namespaces are put-ed, so there's no need to put new nsproxy itelf as it woud cause putting namespaces for the second time.

Found when incorporating namespaces into OpenVZ kernel.

Quoted 8 lines

---

 nsproxy.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

kernel/nsproxy.c out_uts: · line 120

Quoted 7 lines
kernel/nsproxy.c renamed from kernel/nsproxy.c.veboot +1 -1
@@ -115,7 +115,7 @@ out_uts:
 		put_namespace(new_ns->namespace);
 out_ns:
 	tsk->nsproxy = old_ns;
-	put_nsproxy(new_ns);
+	kfree(new_ns);
 	goto out;
 }

Yes, thanks.

The logic has subtly changed since the last version I'd sent out. I have tests which should have caught this, and need to start firing off jobs to periodically test them against -mm.

In fact I notice that it is currently no longer putting old_ns on the error path. Seems to me the following patch should be needed on top of yours.

Meanwhile I'll start firing off a test against v2.6.18-rc4-mm3.

thanks,
-serge

Quoted 1 line

From c4d187c3c1534c22e7879d52eeceed55412c9559 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Thu, 31 Aug 2006 06:54:15 -0500
Subject: [PATCH 1/1] nsproxy: free the old_ns on copy_namespaces error

copy_namespaces increments the usage count on old_ns at top. On successful exit it properly decrements that usage count. On error path it failed to do so.

---
 kernel/nsproxy.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
kernel/nsproxy.c +1 -0
index e25d97c..575155a 100644
@@ -121,6 +121,7 @@ out_uts:
 out_ns:
 	tsk->nsproxy = old_ns;
 	kfree(new_ns);
+	put_nsproxy(old_ns);
 	goto out;
 }
 
Signature · 1 line
1.4.2