diff options
author | Seth Forshee <seth.forshee@canonical.com> | 2017-01-26 15:33:46 -0500 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2017-02-01 00:17:05 -0500 |
commit | 1328c727004d432bbdfba0ffa02a166df04c7305 (patch) | |
tree | 93c51d5133b18cfdc6660669e15e266133360d2a | |
parent | 68eb94f16227336a5773b83ecfa8290f1d6b78ce (diff) |
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: 036d523641c6 ("vfs: Don't create inodes with a uid or gid unknown to the vfs")
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r-- | fs/namei.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/namei.c b/fs/namei.c index ad74877e1442..6fa3e9138fe4 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -2941,10 +2941,16 @@ static inline int open_to_namei_flags(int flag) | |||
2941 | 2941 | ||
2942 | static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t mode) | 2942 | static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t mode) |
2943 | { | 2943 | { |
2944 | struct user_namespace *s_user_ns; | ||
2944 | int error = security_path_mknod(dir, dentry, mode, 0); | 2945 | int error = security_path_mknod(dir, dentry, mode, 0); |
2945 | if (error) | 2946 | if (error) |
2946 | return error; | 2947 | return error; |
2947 | 2948 | ||
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 | |||
2948 | error = inode_permission(dir->dentry->d_inode, MAY_WRITE | MAY_EXEC); | 2954 | error = inode_permission(dir->dentry->d_inode, MAY_WRITE | MAY_EXEC); |
2949 | if (error) | 2955 | if (error) |
2950 | return error; | 2956 | return error; |