forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basically, it will allow a process to unshare its user_struct table, resetting at the same time its own user_struct and all the associated accounting. A new root user (uid == 0) is added to the user namespace upon creation. Such root users have full privileges and it seems that theses privileges should be controlled through some means (process capabilities ?) The unshare is not included in this patch. Changes since [try #4]: - Updated get_user_ns and put_user_ns to accept NULL, and get_user_ns to return the namespace. Changes since [try #3]: - moved struct user_namespace to files user_namespace.{c,h} Changes since [try #2]: - removed struct user_namespace* argument from find_user() Changes since [try #1]: - removed struct user_namespace* argument from find_user() - added a root_user per user namespace Signed-off-by: Cedric Le Goater <[email protected]> Signed-off-by: Serge E. Hallyn <[email protected]> Acked-by: Pavel Emelianov <[email protected]> Cc: Herbert Poetzl <[email protected]> Cc: Kirill Korotaev <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Chris Wright <[email protected]> Cc: Stephen Smalley <[email protected]> Cc: James Morris <[email protected]> Cc: Andrew Morgan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Cedric Le Goater
authored and
Linus Torvalds
committed
Jul 16, 2007
1 parent
7d69a1f
commit acce292
Showing
11 changed files
with
137 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef _LINUX_USER_NAMESPACE_H | ||
#define _LINUX_USER_NAMESPACE_H | ||
|
||
#include <linux/kref.h> | ||
#include <linux/nsproxy.h> | ||
#include <linux/sched.h> | ||
|
||
#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8) | ||
#define UIDHASH_SZ (1 << UIDHASH_BITS) | ||
|
||
struct user_namespace { | ||
struct kref kref; | ||
struct list_head uidhash_table[UIDHASH_SZ]; | ||
struct user_struct *root_user; | ||
}; | ||
|
||
extern struct user_namespace init_user_ns; | ||
|
||
#ifdef CONFIG_USER_NS | ||
|
||
static inline struct user_namespace *get_user_ns(struct user_namespace *ns) | ||
{ | ||
if (ns) | ||
kref_get(&ns->kref); | ||
return ns; | ||
} | ||
|
||
extern struct user_namespace *copy_user_ns(int flags, | ||
struct user_namespace *old_ns); | ||
extern void free_user_ns(struct kref *kref); | ||
|
||
static inline void put_user_ns(struct user_namespace *ns) | ||
{ | ||
if (ns) | ||
kref_put(&ns->kref, free_user_ns); | ||
} | ||
|
||
#else | ||
|
||
static inline struct user_namespace *get_user_ns(struct user_namespace *ns) | ||
{ | ||
return &init_user_ns; | ||
} | ||
|
||
static inline struct user_namespace *copy_user_ns(int flags, | ||
struct user_namespace *old_ns) | ||
{ | ||
return NULL; | ||
} | ||
|
||
static inline void put_user_ns(struct user_namespace *ns) | ||
{ | ||
} | ||
|
||
#endif | ||
|
||
#endif /* _LINUX_USER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, version 2 of the | ||
* License. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/version.h> | ||
#include <linux/nsproxy.h> | ||
#include <linux/user_namespace.h> | ||
|
||
struct user_namespace init_user_ns = { | ||
.kref = { | ||
.refcount = ATOMIC_INIT(2), | ||
}, | ||
.root_user = &root_user, | ||
}; | ||
|
||
EXPORT_SYMBOL_GPL(init_user_ns); | ||
|
||
#ifdef CONFIG_USER_NS | ||
|
||
struct user_namespace * copy_user_ns(int flags, struct user_namespace *old_ns) | ||
{ | ||
struct user_namespace *new_ns; | ||
|
||
BUG_ON(!old_ns); | ||
get_user_ns(old_ns); | ||
|
||
new_ns = old_ns; | ||
return new_ns; | ||
} | ||
|
||
void free_user_ns(struct kref *kref) | ||
{ | ||
struct user_namespace *ns; | ||
|
||
ns = container_of(kref, struct user_namespace, kref); | ||
kfree(ns); | ||
} | ||
|
||
#endif /* CONFIG_USER_NS */ |