瀏覽代碼

[PATCH] uts: copy nsproxy only when needed

The nsproxy was being copied in unshare() when anything was being unshared,
even if it was something not referenced from nsproxy.  This should end up
in some cases with far more memory usage than necessary.

Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Andrey Savochkin <saw@sw.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Serge Hallyn 18 年之前
父節點
當前提交
c0b2fc3165
共有 1 個文件被更改,包括 14 次插入6 次删除
  1. 14 6
      kernel/fork.c

+ 14 - 6
kernel/fork.c

@@ -1606,7 +1606,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
 	struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
 	struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
 	struct files_struct *fd, *new_fd = NULL;
 	struct files_struct *fd, *new_fd = NULL;
 	struct sem_undo_list *new_ulist = NULL;
 	struct sem_undo_list *new_ulist = NULL;
-	struct nsproxy *new_nsproxy, *old_nsproxy;
+	struct nsproxy *new_nsproxy = NULL, *old_nsproxy = NULL;
 	struct uts_namespace *uts, *new_uts = NULL;
 	struct uts_namespace *uts, *new_uts = NULL;
 
 
 	check_unshare_flags(&unshare_flags);
 	check_unshare_flags(&unshare_flags);
@@ -1634,18 +1634,24 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
 	if ((err = unshare_utsname(unshare_flags, &new_uts)))
 	if ((err = unshare_utsname(unshare_flags, &new_uts)))
 		goto bad_unshare_cleanup_semundo;
 		goto bad_unshare_cleanup_semundo;
 
 
-	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist ||
-				new_uts) {
-
+	if (new_ns || new_uts) {
 		old_nsproxy = current->nsproxy;
 		old_nsproxy = current->nsproxy;
 		new_nsproxy = dup_namespaces(old_nsproxy);
 		new_nsproxy = dup_namespaces(old_nsproxy);
 		if (!new_nsproxy) {
 		if (!new_nsproxy) {
 			err = -ENOMEM;
 			err = -ENOMEM;
 			goto bad_unshare_cleanup_uts;
 			goto bad_unshare_cleanup_uts;
 		}
 		}
+	}
+
+	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist ||
+				new_uts) {
 
 
 		task_lock(current);
 		task_lock(current);
-		current->nsproxy = new_nsproxy;
+
+		if (new_nsproxy) {
+			current->nsproxy = new_nsproxy;
+			new_nsproxy = old_nsproxy;
+		}
 
 
 		if (new_fs) {
 		if (new_fs) {
 			fs = current->fs;
 			fs = current->fs;
@@ -1687,9 +1693,11 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
 		}
 		}
 
 
 		task_unlock(current);
 		task_unlock(current);
-		put_nsproxy(old_nsproxy);
 	}
 	}
 
 
+	if (new_nsproxy)
+		put_nsproxy(new_nsproxy);
+
 bad_unshare_cleanup_uts:
 bad_unshare_cleanup_uts:
 	if (new_uts)
 	if (new_uts)
 		put_uts_ns(new_uts);
 		put_uts_ns(new_uts);