aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-08-06 13:38:55 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-11 21:35:25 -0400
commitc98ebcb618645d40cfec14b0534ff32126c114ce (patch)
treeff10fbc7e13727792d1b16107616368e0c5ad194 /kernel
parent73b8bd6de83c0ca182622f83d31a1b0a137281fe (diff)
userns: unshare_userns(&cred) should not populate cred on failure
commit 6160968cee8b90a5dd95318d716e31d7775c4ef3 upstream. unshare_userns(new_cred) does *new_cred = prepare_creds() before create_user_ns() which can fail. However, the caller expects that it doesn't need to take care of new_cred if unshare_userns() fails. We could change the single caller, sys_unshare(), but I think it would be more clean to avoid the side effects on failure, so with this patch unshare_userns() does put_cred() itself and initializes *new_cred only if create_user_ns() succeeeds. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/user_namespace.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index d8c30db06c5b..6e50a44610ee 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -105,16 +105,21 @@ int create_user_ns(struct cred *new)
105int unshare_userns(unsigned long unshare_flags, struct cred **new_cred) 105int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
106{ 106{
107 struct cred *cred; 107 struct cred *cred;
108 int err = -ENOMEM;
108 109
109 if (!(unshare_flags & CLONE_NEWUSER)) 110 if (!(unshare_flags & CLONE_NEWUSER))
110 return 0; 111 return 0;
111 112
112 cred = prepare_creds(); 113 cred = prepare_creds();
113 if (!cred) 114 if (cred) {
114 return -ENOMEM; 115 err = create_user_ns(cred);
116 if (err)
117 put_cred(cred);
118 else
119 *new_cred = cred;
120 }
115 121
116 *new_cred = cred; 122 return err;
117 return create_user_ns(cred);
118} 123}
119 124
120void free_user_ns(struct user_namespace *ns) 125void free_user_ns(struct user_namespace *ns)