Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 202973
b: refs/heads/master
c: 5c1469d
h: refs/heads/master
i:
  202971: e44b0b5
v: v3
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Jun 16, 2010
1 parent b0c22e4 commit 76bb918
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 812e876e842488221aa54cb4587a8a33445cfa9e
refs/heads/master: 5c1469de7545a35a16ff2b902e217044a7d2f8a5
14 changes: 14 additions & 0 deletions trunk/include/linux/user_namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ static inline void put_user_ns(struct user_namespace *ns)
kref_put(&ns->kref, free_user_ns);
}

uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);

#else

static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
Expand All @@ -52,6 +55,17 @@ static inline void put_user_ns(struct user_namespace *ns)
{
}

static inline uid_t user_ns_map_uid(struct user_namespace *to,
const struct cred *cred, uid_t uid)
{
return uid;
}
static inline gid_t user_ns_map_gid(struct user_namespace *to,
const struct cred *cred, gid_t gid)
{
return gid;
}

#endif

#endif /* _LINUX_USER_H */
44 changes: 44 additions & 0 deletions trunk/kernel/user_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/nsproxy.h>
#include <linux/slab.h>
#include <linux/user_namespace.h>
#include <linux/highuid.h>
#include <linux/cred.h>

/*
Expand Down Expand Up @@ -82,3 +83,46 @@ void free_user_ns(struct kref *kref)
schedule_work(&ns->destroyer);
}
EXPORT_SYMBOL(free_user_ns);

uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid)
{
struct user_namespace *tmp;

if (likely(to == cred->user->user_ns))
return uid;


/* Is cred->user the creator of the target user_ns
* or the creator of one of it's parents?
*/
for ( tmp = to; tmp != &init_user_ns;
tmp = tmp->creator->user_ns ) {
if (cred->user == tmp->creator) {
return (uid_t)0;
}
}

/* No useful relationship so no mapping */
return overflowuid;
}

gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid)
{
struct user_namespace *tmp;

if (likely(to == cred->user->user_ns))
return gid;

/* Is cred->user the creator of the target user_ns
* or the creator of one of it's parents?
*/
for ( tmp = to; tmp != &init_user_ns;
tmp = tmp->creator->user_ns ) {
if (cred->user == tmp->creator) {
return (gid_t)0;
}
}

/* No useful relationship so no mapping */
return overflowgid;
}

0 comments on commit 76bb918

Please sign in to comment.