Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 361880
b: refs/heads/master
c: 3151527
h: refs/heads/master
v: v3
  • Loading branch information
Eric W. Biederman committed Mar 27, 2013
1 parent 346a167 commit 3d89622
Show file tree
Hide file tree
Showing 4 changed files with 36 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: eddc0a3abff273842a94784d2d022bbc36dc9015
refs/heads/master: 3151527ee007b73a0ebd296010f1c0454a919c7d
24 changes: 24 additions & 0 deletions trunk/fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,30 @@ bool our_mnt(struct vfsmount *mnt)
return check_mnt(real_mount(mnt));
}

bool current_chrooted(void)
{
/* Does the current process have a non-standard root */
struct path ns_root;
struct path fs_root;
bool chrooted;

/* Find the namespace root */
ns_root.mnt = &current->nsproxy->mnt_ns->root->mnt;
ns_root.dentry = ns_root.mnt->mnt_root;
path_get(&ns_root);
while (d_mountpoint(ns_root.dentry) && follow_down_one(&ns_root))
;

get_fs_root(current->fs, &fs_root);

chrooted = !path_equal(&fs_root, &ns_root);

path_put(&fs_root);
path_put(&ns_root);

return chrooted;
}

static void *mntns_get(struct task_struct *task)
{
struct mnt_namespace *ns = NULL;
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/fs_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ static inline void get_fs_root_and_pwd(struct fs_struct *fs, struct path *root,
spin_unlock(&fs->lock);
}

extern bool current_chrooted(void);

#endif /* _LINUX_FS_STRUCT_H */
9 changes: 9 additions & 0 deletions trunk/kernel/user_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ int create_user_ns(struct cred *new)
kgid_t group = new->egid;
int ret;

/*
* Verify that we can not violate the policy of which files
* may be accessed that is specified by the root directory,
* by verifing that the root directory is at the root of the
* mount namespace which allows all files to be accessed.
*/
if (current_chrooted())
return -EPERM;

/* The creator needs a mapping in the parent user namespace
* or else we won't be able to reasonably tell userspace who
* created a user_namespace.
Expand Down

0 comments on commit 3d89622

Please sign in to comment.