Skip to contentSkip to conversation

kernel/nsproxy.c: Fix memory leak of create_new_namespaces().

PATCH In review wzt 1 participant 2 messages Oct 18, 2011 1 message not in the archive

lore
Share & tools
lore

wzt

author
#0 lore raw

PATCH 1/1 kernel/nsproxy.c: Fix memory leak of create_new_namespaces().

copy_pid_ns() has allocted some memory via create_pid_namespace(), if copy_net_ns() failed via create_new_namespaces(), it will cause memory leak. The copy_utsname() have the same problem.

---
 kernel/nsproxy.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
kernel/nsproxy.c +6 -2
index 9aeab4b..fdcec31 100644
@@ -99,14 +99,18 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
 	return new_nsp;
 
 out_net:
-	if (new_nsp->pid_ns)
+	if (new_nsp->pid_ns) {
 		put_pid_ns(new_nsp->pid_ns);
+		free_pid_ns(&new_nsp->pid_ns->kref);
+	}
 out_pid:
 	if (new_nsp->ipc_ns)
 		put_ipc_ns(new_nsp->ipc_ns);
 out_ipc:
-	if (new_nsp->uts_ns)
+	if (new_nsp->uts_ns) {
 		put_uts_ns(new_nsp->uts_ns);
+		free_uts_ns(&new_nsp->pid_ns->kref);
+	}
 out_uts:
 	if (new_nsp->mnt_ns)
 		put_mnt_ns(new_nsp->mnt_ns);
Signature · 1 line
1.7.4.1
author
#2 lore raw
In reply to a message not in the archive

Sorry for the wrong patch, thanks Feng to point it out.

Quoted 60 lines · Xiaotian Feng
Quoted 21 lines · wzt

copy_pid_ns() has allocted some memory via create_pid_namespace(), if copy_net_ns()
failed via create_new_namespaces(), it will cause memory leak. The copy_utsname()
have the same problem.

---
 kernel/nsproxy.c |    8 ++++++--

 1 files changed, 6 insertions(+), 2 deletions(-)
kernel/nsproxy.c +0 -0
index 9aeab4b..fdcec31 100644
@@ -99,14 +99,18 @@ static struct nsproxy *create_new_namespaces(unsigned
 long flags,
        return new_nsp;
 
Quoted 5 lines

 out_net:
-       if (new_nsp->pid_ns)
+       if (new_nsp->pid_ns) { put_pid_ns(new_nsp->pid_ns);
+               free_pid_ns(&new_nsp->pid_ns->kref);

It is freed in put_pid_ns() if the last user is gone. Please check the implementation of put_pid_ns().

Quoted 10 lines

+       }
 out_pid:
       if (new_nsp->ipc_ns) put_ipc_ns(new_nsp->ipc_ns); out_ipc:
-       if (new_nsp->uts_ns)
+       if (new_nsp->uts_ns) { put_uts_ns(new_nsp->uts_ns);
+               free_uts_ns(&new_nsp->pid_ns->kref);

 same

Quoted 13 lines

+       }
 out_uts:
       if (new_nsp->mnt_ns)
               put_mnt_ns(new_nsp->mnt_ns);
--
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/