Skip to content

Commit 1328c72

Browse files
Seth Forsheeebiederm
authored andcommitted
vfs: open() with O_CREAT should not create inodes with unknown ids
may_create() rejects creation of inodes with ids which lack a mapping into s_user_ns. However for O_CREAT may_o_create() is is used instead. Add a similar check there. Fixes: 036d523 ("vfs: Don't create inodes with a uid or gid unknown to the vfs") Signed-off-by: Seth Forshee <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 68eb94f commit 1328c72

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/namei.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,10 +2941,16 @@ static inline int open_to_namei_flags(int flag)
29412941

29422942
static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t mode)
29432943
{
2944+
struct user_namespace *s_user_ns;
29442945
int error = security_path_mknod(dir, dentry, mode, 0);
29452946
if (error)
29462947
return error;
29472948

2949+
s_user_ns = dir->dentry->d_sb->s_user_ns;
2950+
if (!kuid_has_mapping(s_user_ns, current_fsuid()) ||
2951+
!kgid_has_mapping(s_user_ns, current_fsgid()))
2952+
return -EOVERFLOW;
2953+
29482954
error = inode_permission(dir->dentry->d_inode, MAY_WRITE | MAY_EXEC);
29492955
if (error)
29502956
return error;

0 commit comments

Comments
 (0)