Skip to contentSkip to conversation

user namespace: fix copy_user_ns return value

PATCH New Serge E. Hallyn 1 participant 1 message Jul 19, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 user namespace: fix copy_user_ns return value

As found by [email protected], current -git, when compiled with CONFIG_USER_NS=n, can be crashed by doing

#include <sched.h>
#include <sys/types.h>
#include <unistd.h>

int main()

{
	unshare(CLONE_NEWNS);
	setuid(1000);
}

as root.

The dummy version of copy_user_ns was returning NULL instead of a valid namespace. The following patch fixes the problem. Please apply.

thanks,
-serge

Quoted 1 line

From 32f86740d27ef77160e438cd7dc4fcd5df159dd0 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Tue, 17 Jul 2007 15:28:17 -0400
Subject: [PATCH] user namespace: fix copy_user_ns return value

When a CONFIG_USER_NS=n and a user tries to unshare some namespace other than the user namespace, the dummy copy_user_ns returns NULL rather than the old_ns. This value then gets assigned to task->nsproxy->user_ns, so that a subsequent setuid, which uses task->nsproxy->user_ns, causes a NULL pointer deref.

Fix this by returning old_ns.

---
 include/linux/user_namespace.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/user_namespace.h +1 -1
index bb32057..1101b0c 100644
@@ -49,7 +49,7 @@ static inline struct user_namespace *copy_user_ns(int flags,
 	if (flags & CLONE_NEWUSER)
 		return ERR_PTR(-EINVAL);
 
-	return NULL;
+	return old_ns;
 }
 
 static inline void put_user_ns(struct user_namespace *ns)
Signature · 1 line
1.5.1.1.GIT