Skip to content

Commit 036d523

Browse files
committed
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 <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 0bd23d0 commit 036d523

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/namei.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,16 +2814,22 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
28142814
* 1. We can't do it if child already exists (open has special treatment for
28152815
* this case, but since we are inlined it's OK)
28162816
* 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
2818-
* 4. We can't do it if dir is immutable (done in permission())
2817+
* 3. We can't do it if the fs can't represent the fsuid or fsgid.
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())
28192820
*/
28202821
static inline int may_create(struct inode *dir, struct dentry *child)
28212822
{
2823+
struct user_namespace *s_user_ns;
28222824
audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
28232825
if (child->d_inode)
28242826
return -EEXIST;
28252827
if (IS_DEADDIR(dir))
28262828
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;
28272833
return inode_permission(dir, MAY_WRITE | MAY_EXEC);
28282834
}
28292835

0 commit comments

Comments
 (0)