aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2016-07-01 13:52:06 -0400
committerEric W. Biederman <ebiederm@xmission.com>2016-07-05 16:11:47 -0400
commit036d523641c66bef713042894a17f4335f199e49 (patch)
treee1d0b786d6da437c10245cd9665b1d3b6b6e246c
parent0bd23d09b874e53bd1a2fe2296030aa2720d7b08 (diff)
vfs: Don't create inodes with a uid or gid unknown to the vfs
It is expected that filesystems can not represent uids and gids from outside of their user namespace. Keep things simple by not even trying to create filesystem nodes with non-sense uids and gids. Acked-by: Seth Forshee <seth.forshee@canonical.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r--fs/namei.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 840201c4c290..629823f19a6a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2814,16 +2814,22 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
2814 * 1. We can't do it if child already exists (open has special treatment for 2814 * 1. We can't do it if child already exists (open has special treatment for
2815 * this case, but since we are inlined it's OK) 2815 * this case, but since we are inlined it's OK)
2816 * 2. We can't do it if dir is read-only (done in permission()) 2816 * 2. We can't do it if dir is read-only (done in permission())
2817 * 3. We should have write and exec permissions on dir 2817 * 3. We can't do it if the fs can't represent the fsuid or fsgid.
2818 * 4. We can't do it if dir is immutable (done in permission()) 2818 * 4. We should have write and exec permissions on dir
2819 * 5. We can't do it if dir is immutable (done in permission())
2819 */ 2820 */
2820static inline int may_create(struct inode *dir, struct dentry *child) 2821static inline int may_create(struct inode *dir, struct dentry *child)
2821{ 2822{
2823 struct user_namespace *s_user_ns;
2822 audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE); 2824 audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
2823 if (child->d_inode) 2825 if (child->d_inode)
2824 return -EEXIST; 2826 return -EEXIST;
2825 if (IS_DEADDIR(dir)) 2827 if (IS_DEADDIR(dir))
2826 return -ENOENT; 2828 return -ENOENT;
2829 s_user_ns = dir->i_sb->s_user_ns;
2830 if (!kuid_has_mapping(s_user_ns, current_fsuid()) ||
2831 !kgid_has_mapping(s_user_ns, current_fsgid()))
2832 return -EOVERFLOW;
2827 return inode_permission(dir, MAY_WRITE | MAY_EXEC); 2833 return inode_permission(dir, MAY_WRITE | MAY_EXEC);
2828} 2834}
2829 2835