mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
fs: port i_{g,u}id_into_vfs{g,u}id() to mnt_idmap
Convert to struct mnt_idmap.
Remove legacy file_mnt_user_ns() and mnt_user_ns().
Last cycle we merged the necessary infrastructure in
256c8aed2b ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.
Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.
Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.
Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner (Microsoft)
parent
0dbe12f2e4
commit
e67fe63341
24
fs/attr.c
24
fs/attr.c
@@ -36,15 +36,13 @@
|
||||
int setattr_should_drop_sgid(struct mnt_idmap *idmap,
|
||||
const struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
umode_t mode = inode->i_mode;
|
||||
|
||||
if (!(mode & S_ISGID))
|
||||
return 0;
|
||||
if (mode & S_IXGRP)
|
||||
return ATTR_KILL_SGID;
|
||||
if (!in_group_or_capable(idmap, inode,
|
||||
i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
if (!in_group_or_capable(idmap, inode, i_gid_into_vfsgid(idmap, inode)))
|
||||
return ATTR_KILL_SGID;
|
||||
return 0;
|
||||
}
|
||||
@@ -98,9 +96,7 @@ EXPORT_SYMBOL(setattr_should_drop_suidgid);
|
||||
static bool chown_ok(struct mnt_idmap *idmap,
|
||||
const struct inode *inode, vfsuid_t ia_vfsuid)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid()) &&
|
||||
vfsuid_eq(ia_vfsuid, vfsuid))
|
||||
return true;
|
||||
@@ -127,10 +123,8 @@ static bool chown_ok(struct mnt_idmap *idmap,
|
||||
static bool chgrp_ok(struct mnt_idmap *idmap,
|
||||
const struct inode *inode, vfsgid_t ia_vfsgid)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid())) {
|
||||
if (vfsgid_eq(ia_vfsgid, vfsgid))
|
||||
return true;
|
||||
@@ -169,7 +163,6 @@ static bool chgrp_ok(struct mnt_idmap *idmap,
|
||||
int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
struct iattr *attr)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode = d_inode(dentry);
|
||||
unsigned int ia_valid = attr->ia_valid;
|
||||
|
||||
@@ -207,7 +200,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
if (ia_valid & ATTR_GID)
|
||||
vfsgid = attr->ia_vfsgid;
|
||||
else
|
||||
vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
|
||||
/* Also check the setgid bit! */
|
||||
if (!in_group_or_capable(idmap, inode, vfsgid))
|
||||
@@ -308,7 +301,6 @@ EXPORT_SYMBOL(inode_newsize_ok);
|
||||
void setattr_copy(struct mnt_idmap *idmap, struct inode *inode,
|
||||
const struct iattr *attr)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
unsigned int ia_valid = attr->ia_valid;
|
||||
|
||||
i_uid_update(idmap, attr, inode);
|
||||
@@ -322,7 +314,7 @@ void setattr_copy(struct mnt_idmap *idmap, struct inode *inode,
|
||||
if (ia_valid & ATTR_MODE) {
|
||||
umode_t mode = attr->ia_mode;
|
||||
if (!in_group_or_capable(idmap, inode,
|
||||
i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
i_gid_into_vfsgid(idmap, inode)))
|
||||
mode &= ~S_ISGID;
|
||||
inode->i_mode = mode;
|
||||
}
|
||||
@@ -473,10 +465,10 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
* gids unless those uids & gids are being made valid.
|
||||
*/
|
||||
if (!(ia_valid & ATTR_UID) &&
|
||||
!vfsuid_valid(i_uid_into_vfsuid(mnt_userns, inode)))
|
||||
!vfsuid_valid(i_uid_into_vfsuid(idmap, inode)))
|
||||
return -EOVERFLOW;
|
||||
if (!(ia_valid & ATTR_GID) &&
|
||||
!vfsgid_valid(i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
!vfsgid_valid(i_gid_into_vfsgid(idmap, inode)))
|
||||
return -EOVERFLOW;
|
||||
|
||||
error = security_inode_setattr(idmap, dentry, attr);
|
||||
|
||||
@@ -645,7 +645,6 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
||||
}
|
||||
} else {
|
||||
struct mnt_idmap *idmap;
|
||||
struct user_namespace *mnt_userns;
|
||||
struct inode *inode;
|
||||
int open_flags = O_CREAT | O_RDWR | O_NOFOLLOW |
|
||||
O_LARGEFILE | O_EXCL;
|
||||
@@ -724,8 +723,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
||||
* filesystem.
|
||||
*/
|
||||
idmap = file_mnt_idmap(cprm.file);
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode),
|
||||
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode),
|
||||
current_fsuid())) {
|
||||
pr_info_ratelimited("Core dump to %s aborted: cannot preserve file owner\n",
|
||||
cn.corename);
|
||||
|
||||
@@ -1596,7 +1596,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
|
||||
static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
|
||||
{
|
||||
/* Handle suid and sgid on files */
|
||||
struct user_namespace *mnt_userns;
|
||||
struct mnt_idmap *idmap;
|
||||
struct inode *inode = file_inode(file);
|
||||
unsigned int mode;
|
||||
vfsuid_t vfsuid;
|
||||
@@ -1612,15 +1612,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
|
||||
if (!(mode & (S_ISUID|S_ISGID)))
|
||||
return;
|
||||
|
||||
mnt_userns = file_mnt_user_ns(file);
|
||||
idmap = file_mnt_idmap(file);
|
||||
|
||||
/* Be careful if suid/sgid is set */
|
||||
inode_lock(inode);
|
||||
|
||||
/* reload atomically mode/uid/gid now that lock held */
|
||||
mode = inode->i_mode;
|
||||
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
inode_unlock(inode);
|
||||
|
||||
/* We ignore suid/sgid if there are no mappings for them in the ns */
|
||||
|
||||
@@ -209,7 +209,6 @@ static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
|
||||
struct posix_acl **acl)
|
||||
{
|
||||
umode_t mode = inode->i_mode;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int error;
|
||||
|
||||
if (is_inode_flag_set(inode, FI_ACL_MODE))
|
||||
@@ -220,7 +219,7 @@ static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
|
||||
return error;
|
||||
if (error == 0)
|
||||
*acl = NULL;
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)) &&
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(idmap, inode)) &&
|
||||
!capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
|
||||
mode &= ~S_ISGID;
|
||||
*mode_p = mode;
|
||||
|
||||
@@ -907,7 +907,6 @@ static void __setattr_copy(struct mnt_idmap *idmap,
|
||||
struct inode *inode, const struct iattr *attr)
|
||||
{
|
||||
unsigned int ia_valid = attr->ia_valid;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
i_uid_update(idmap, attr, inode);
|
||||
i_gid_update(idmap, attr, inode);
|
||||
@@ -919,7 +918,7 @@ static void __setattr_copy(struct mnt_idmap *idmap,
|
||||
inode->i_ctime = attr->ia_ctime;
|
||||
if (ia_valid & ATTR_MODE) {
|
||||
umode_t mode = attr->ia_mode;
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
|
||||
if (!vfsgid_in_group_p(vfsgid) &&
|
||||
!capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
|
||||
|
||||
@@ -258,9 +258,9 @@ static int recover_quota_data(struct inode *inode, struct page *page)
|
||||
attr.ia_vfsuid = VFSUIDT_INIT(make_kuid(inode->i_sb->s_user_ns, i_uid));
|
||||
attr.ia_vfsgid = VFSGIDT_INIT(make_kgid(inode->i_sb->s_user_ns, i_gid));
|
||||
|
||||
if (!vfsuid_eq(attr.ia_vfsuid, i_uid_into_vfsuid(&init_user_ns, inode)))
|
||||
if (!vfsuid_eq(attr.ia_vfsuid, i_uid_into_vfsuid(&nop_mnt_idmap, inode)))
|
||||
attr.ia_valid |= ATTR_UID;
|
||||
if (!vfsgid_eq(attr.ia_vfsgid, i_gid_into_vfsgid(&init_user_ns, inode)))
|
||||
if (!vfsgid_eq(attr.ia_vfsgid, i_gid_into_vfsgid(&nop_mnt_idmap, inode)))
|
||||
attr.ia_valid |= ATTR_GID;
|
||||
|
||||
if (!attr.ia_valid)
|
||||
|
||||
@@ -456,14 +456,14 @@ static int fat_sanitize_mode(const struct msdos_sb_info *sbi,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fat_allow_set_time(struct user_namespace *mnt_userns,
|
||||
static int fat_allow_set_time(struct mnt_idmap *idmap,
|
||||
struct msdos_sb_info *sbi, struct inode *inode)
|
||||
{
|
||||
umode_t allow_utime = sbi->options.allow_utime;
|
||||
|
||||
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode),
|
||||
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode),
|
||||
current_fsuid())) {
|
||||
if (vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
if (vfsgid_in_group_p(i_gid_into_vfsgid(idmap, inode)))
|
||||
allow_utime >>= 3;
|
||||
if (allow_utime & MAY_WRITE)
|
||||
return 1;
|
||||
@@ -489,7 +489,7 @@ int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
/* Check for setting the inode time. */
|
||||
ia_valid = attr->ia_valid;
|
||||
if (ia_valid & TIMES_SET_FLAGS) {
|
||||
if (fat_allow_set_time(mnt_userns, sbi, inode))
|
||||
if (fat_allow_set_time(idmap, sbi, inode))
|
||||
attr->ia_valid &= ~TIMES_SET_FLAGS;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ int fuse_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(&init_user_ns, inode)) &&
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(&nop_mnt_idmap, inode)) &&
|
||||
!capable_wrt_inode_uidgid(&nop_mnt_idmap, inode, CAP_FSETID))
|
||||
extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
|
||||
|
||||
|
||||
@@ -2327,9 +2327,8 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap,
|
||||
{
|
||||
vfsuid_t vfsuid;
|
||||
struct user_namespace *ns;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
|
||||
return true;
|
||||
|
||||
@@ -2498,14 +2497,11 @@ bool in_group_or_capable(struct mnt_idmap *idmap,
|
||||
umode_t mode_strip_sgid(struct mnt_idmap *idmap,
|
||||
const struct inode *dir, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if ((mode & (S_ISGID | S_IXGRP)) != (S_ISGID | S_IXGRP))
|
||||
return mode;
|
||||
if (S_ISDIR(mode) || !dir || !(dir->i_mode & S_ISGID))
|
||||
return mode;
|
||||
if (in_group_or_capable(idmap, dir,
|
||||
i_gid_into_vfsgid(mnt_userns, dir)))
|
||||
if (in_group_or_capable(idmap, dir, i_gid_into_vfsgid(idmap, dir)))
|
||||
return mode;
|
||||
return mode & ~S_ISGID;
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ static int ndr_encode_posix_acl_entry(struct ndr *n, struct xattr_smb_acl *acl)
|
||||
}
|
||||
|
||||
int ndr_encode_posix_acl(struct ndr *n,
|
||||
struct user_namespace *user_ns,
|
||||
struct mnt_idmap *idmap,
|
||||
struct inode *inode,
|
||||
struct xattr_smb_acl *acl,
|
||||
struct xattr_smb_acl *def_acl)
|
||||
@@ -374,11 +374,11 @@ int ndr_encode_posix_acl(struct ndr *n,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
vfsuid = i_uid_into_vfsuid(user_ns, inode);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
ret = ndr_write_int64(n, from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid)));
|
||||
if (ret)
|
||||
return ret;
|
||||
vfsgid = i_gid_into_vfsgid(user_ns, inode);
|
||||
vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
ret = ndr_write_int64(n, from_kgid(&init_user_ns, vfsgid_into_kgid(vfsgid)));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@@ -14,7 +14,7 @@ struct ndr {
|
||||
|
||||
int ndr_encode_dos_attr(struct ndr *n, struct xattr_dos_attrib *da);
|
||||
int ndr_decode_dos_attr(struct ndr *n, struct xattr_dos_attrib *da);
|
||||
int ndr_encode_posix_acl(struct ndr *n, struct user_namespace *user_ns,
|
||||
int ndr_encode_posix_acl(struct ndr *n, struct mnt_idmap *idmap,
|
||||
struct inode *inode, struct xattr_smb_acl *acl,
|
||||
struct xattr_smb_acl *def_acl);
|
||||
int ndr_encode_v4_ntacl(struct ndr *n, struct xattr_ntacl *acl);
|
||||
|
||||
@@ -1608,9 +1608,9 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp)
|
||||
{
|
||||
struct create_posix_rsp *buf;
|
||||
struct inode *inode = file_inode(fp->filp);
|
||||
struct user_namespace *user_ns = file_mnt_user_ns(fp->filp);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(user_ns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(user_ns, inode);
|
||||
struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
|
||||
buf = (struct create_posix_rsp *)cc;
|
||||
memset(buf, 0, sizeof(struct create_posix_rsp));
|
||||
|
||||
@@ -2476,11 +2476,11 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,
|
||||
}
|
||||
|
||||
static void ksmbd_acls_fattr(struct smb_fattr *fattr,
|
||||
struct user_namespace *mnt_userns,
|
||||
struct mnt_idmap *idmap,
|
||||
struct inode *inode)
|
||||
{
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
|
||||
fattr->cf_uid = vfsuid_into_kuid(vfsuid);
|
||||
fattr->cf_gid = vfsgid_into_kgid(vfsgid);
|
||||
@@ -2985,7 +2985,7 @@ int smb2_open(struct ksmbd_work *work)
|
||||
struct smb_ntsd *pntsd;
|
||||
int pntsd_size, ace_num = 0;
|
||||
|
||||
ksmbd_acls_fattr(&fattr, user_ns, inode);
|
||||
ksmbd_acls_fattr(&fattr, idmap, inode);
|
||||
if (fattr.cf_acls)
|
||||
ace_num = fattr.cf_acls->a_count;
|
||||
if (fattr.cf_dacls)
|
||||
@@ -4725,9 +4725,9 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp,
|
||||
{
|
||||
struct smb311_posix_qinfo *file_info;
|
||||
struct inode *inode = file_inode(fp->filp);
|
||||
struct user_namespace *user_ns = file_mnt_user_ns(fp->filp);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(user_ns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(user_ns, inode);
|
||||
struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
u64 time;
|
||||
int out_buf_len = sizeof(struct smb311_posix_qinfo) + 32;
|
||||
|
||||
@@ -5178,7 +5178,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
|
||||
idmap = file_mnt_idmap(fp->filp);
|
||||
user_ns = mnt_idmap_owner(idmap);
|
||||
inode = file_inode(fp->filp);
|
||||
ksmbd_acls_fattr(&fattr, user_ns, inode);
|
||||
ksmbd_acls_fattr(&fattr, idmap, inode);
|
||||
|
||||
if (test_share_config_flag(work->tcon->share_conf,
|
||||
KSMBD_SHARE_FLAG_ACL_XATTR))
|
||||
|
||||
@@ -1468,7 +1468,7 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
|
||||
def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
|
||||
ACL_TYPE_DEFAULT);
|
||||
|
||||
rc = ndr_encode_posix_acl(&acl_ndr, user_ns, inode,
|
||||
rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode,
|
||||
smb_acl, def_smb_acl);
|
||||
if (rc) {
|
||||
pr_err("failed to encode ndr to posix acl\n");
|
||||
@@ -1531,7 +1531,7 @@ int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
|
||||
def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
|
||||
ACL_TYPE_DEFAULT);
|
||||
|
||||
rc = ndr_encode_posix_acl(&acl_ndr, user_ns, inode, smb_acl,
|
||||
rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode, smb_acl,
|
||||
def_smb_acl);
|
||||
if (rc) {
|
||||
pr_err("failed to encode ndr to posix acl\n");
|
||||
|
||||
50
fs/namei.c
50
fs/namei.c
@@ -335,12 +335,11 @@ static int check_acl(struct mnt_idmap *idmap,
|
||||
static int acl_permission_check(struct mnt_idmap *idmap,
|
||||
struct inode *inode, int mask)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
unsigned int mode = inode->i_mode;
|
||||
vfsuid_t vfsuid;
|
||||
|
||||
/* Are we the owner? If so, ACL's don't matter */
|
||||
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) {
|
||||
mask &= 7;
|
||||
mode >>= 6;
|
||||
@@ -363,7 +362,7 @@ static int acl_permission_check(struct mnt_idmap *idmap,
|
||||
* about? Need to check group ownership if so.
|
||||
*/
|
||||
if (mask & (mode ^ (mode >> 3))) {
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
if (vfsgid_in_group_p(vfsgid))
|
||||
mode >>= 3;
|
||||
}
|
||||
@@ -1095,14 +1094,14 @@ fs_initcall(init_fs_namei_sysctls);
|
||||
*/
|
||||
static inline int may_follow_link(struct nameidata *nd, const struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns;
|
||||
struct mnt_idmap *idmap;
|
||||
vfsuid_t vfsuid;
|
||||
|
||||
if (!sysctl_protected_symlinks)
|
||||
return 0;
|
||||
|
||||
mnt_userns = mnt_user_ns(nd->path.mnt);
|
||||
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
idmap = mnt_idmap(nd->path.mnt);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
/* Allowed if owner and follower match. */
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
|
||||
return 0;
|
||||
@@ -1181,12 +1180,11 @@ static bool safe_hardlink_source(struct mnt_idmap *idmap,
|
||||
*/
|
||||
int may_linkat(struct mnt_idmap *idmap, const struct path *link)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode = link->dentry->d_inode;
|
||||
|
||||
/* Inode writeback is not safe when the uid or gid are invalid. */
|
||||
if (!vfsuid_valid(i_uid_into_vfsuid(mnt_userns, inode)) ||
|
||||
!vfsgid_valid(i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
if (!vfsuid_valid(i_uid_into_vfsuid(idmap, inode)) ||
|
||||
!vfsgid_valid(i_gid_into_vfsgid(idmap, inode)))
|
||||
return -EOVERFLOW;
|
||||
|
||||
if (!sysctl_protected_hardlinks)
|
||||
@@ -1207,7 +1205,7 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link)
|
||||
* may_create_in_sticky - Check whether an O_CREAT open in a sticky directory
|
||||
* should be allowed, or not, on files that already
|
||||
* exist.
|
||||
* @mnt_userns: user namespace of the mount the inode was found from
|
||||
* @idmap: idmap of the mount the inode was found from
|
||||
* @nd: nameidata pathwalk data
|
||||
* @inode: the inode of the file to open
|
||||
*
|
||||
@@ -1222,15 +1220,15 @@ int may_linkat(struct mnt_idmap *idmap, const struct path *link)
|
||||
* the directory doesn't have to be world writable: being group writable will
|
||||
* be enough.
|
||||
*
|
||||
* If the inode has been found through an idmapped mount the user namespace of
|
||||
* the vfsmount must be passed through @mnt_userns. This function will then take
|
||||
* care to map the inode according to @mnt_userns before checking permissions.
|
||||
* If the inode has been found through an idmapped mount the idmap of
|
||||
* the vfsmount must be passed through @idmap. This function will then take
|
||||
* care to map the inode according to @idmap before checking permissions.
|
||||
* On non-idmapped mounts or if permission checking is to be performed on the
|
||||
* raw inode simply passs init_user_ns.
|
||||
* raw inode simply pass @nop_mnt_idmap.
|
||||
*
|
||||
* Returns 0 if the open is allowed, -ve on error.
|
||||
*/
|
||||
static int may_create_in_sticky(struct user_namespace *mnt_userns,
|
||||
static int may_create_in_sticky(struct mnt_idmap *idmap,
|
||||
struct nameidata *nd, struct inode *const inode)
|
||||
{
|
||||
umode_t dir_mode = nd->dir_mode;
|
||||
@@ -1239,8 +1237,8 @@ static int may_create_in_sticky(struct user_namespace *mnt_userns,
|
||||
if ((!sysctl_protected_fifos && S_ISFIFO(inode->i_mode)) ||
|
||||
(!sysctl_protected_regular && S_ISREG(inode->i_mode)) ||
|
||||
likely(!(dir_mode & S_ISVTX)) ||
|
||||
vfsuid_eq(i_uid_into_vfsuid(mnt_userns, inode), dir_vfsuid) ||
|
||||
vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), current_fsuid()))
|
||||
vfsuid_eq(i_uid_into_vfsuid(idmap, inode), dir_vfsuid) ||
|
||||
vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode), current_fsuid()))
|
||||
return 0;
|
||||
|
||||
if (likely(dir_mode & 0002) ||
|
||||
@@ -2256,13 +2254,11 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
||||
/* At this point we know we have a real path component. */
|
||||
for(;;) {
|
||||
struct mnt_idmap *idmap;
|
||||
struct user_namespace *mnt_userns;
|
||||
const char *link;
|
||||
u64 hash_len;
|
||||
int type;
|
||||
|
||||
idmap = mnt_idmap(nd->path.mnt);
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
err = may_lookup(idmap, nd);
|
||||
if (err)
|
||||
return err;
|
||||
@@ -2311,7 +2307,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
|
||||
OK:
|
||||
/* pathname or trailing symlink, done */
|
||||
if (!depth) {
|
||||
nd->dir_vfsuid = i_uid_into_vfsuid(mnt_userns, nd->inode);
|
||||
nd->dir_vfsuid = i_uid_into_vfsuid(idmap, nd->inode);
|
||||
nd->dir_mode = nd->inode->i_mode;
|
||||
nd->flags &= ~LOOKUP_PARENT;
|
||||
return 0;
|
||||
@@ -2888,11 +2884,10 @@ int __check_sticky(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct inode *inode)
|
||||
{
|
||||
kuid_t fsuid = current_fsuid();
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), fsuid))
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode), fsuid))
|
||||
return 0;
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, dir), fsuid))
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, dir), fsuid))
|
||||
return 0;
|
||||
return !capable_wrt_inode_uidgid(idmap, inode, CAP_FOWNER);
|
||||
}
|
||||
@@ -2921,7 +2916,6 @@ EXPORT_SYMBOL(__check_sticky);
|
||||
static int may_delete(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *victim, bool isdir)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode = d_backing_inode(victim);
|
||||
int error;
|
||||
|
||||
@@ -2932,8 +2926,8 @@ static int may_delete(struct mnt_idmap *idmap, struct inode *dir,
|
||||
BUG_ON(victim->d_parent->d_inode != dir);
|
||||
|
||||
/* Inode writeback is not safe when the uid or gid are invalid. */
|
||||
if (!vfsuid_valid(i_uid_into_vfsuid(mnt_userns, inode)) ||
|
||||
!vfsgid_valid(i_gid_into_vfsgid(mnt_userns, inode)))
|
||||
if (!vfsuid_valid(i_uid_into_vfsuid(idmap, inode)) ||
|
||||
!vfsgid_valid(i_gid_into_vfsgid(idmap, inode)))
|
||||
return -EOVERFLOW;
|
||||
|
||||
audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE);
|
||||
@@ -3522,7 +3516,6 @@ static int do_open(struct nameidata *nd,
|
||||
struct file *file, const struct open_flags *op)
|
||||
{
|
||||
struct mnt_idmap *idmap;
|
||||
struct user_namespace *mnt_userns;
|
||||
int open_flag = op->open_flag;
|
||||
bool do_truncate;
|
||||
int acc_mode;
|
||||
@@ -3536,13 +3529,12 @@ static int do_open(struct nameidata *nd,
|
||||
if (!(file->f_mode & FMODE_CREATED))
|
||||
audit_inode(nd->name, nd->path.dentry, 0);
|
||||
idmap = mnt_idmap(nd->path.mnt);
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
if (open_flag & O_CREAT) {
|
||||
if ((open_flag & O_EXCL) && !(file->f_mode & FMODE_CREATED))
|
||||
return -EEXIST;
|
||||
if (d_is_dir(nd->path.dentry))
|
||||
return -EISDIR;
|
||||
error = may_create_in_sticky(mnt_userns, nd,
|
||||
error = may_create_in_sticky(idmap, nd,
|
||||
d_backing_inode(nd->path.dentry));
|
||||
if (unlikely(error))
|
||||
return error;
|
||||
|
||||
@@ -230,32 +230,6 @@ struct user_namespace *mnt_idmap_owner(const struct mnt_idmap *idmap)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mnt_idmap_owner);
|
||||
|
||||
/**
|
||||
* mnt_user_ns - retrieve owner of an idmapped mount
|
||||
* @mnt: the relevant vfsmount
|
||||
*
|
||||
* This helper will go away once the conversion to use struct mnt_idmap
|
||||
* everywhere has finished at which point the helper will be unexported.
|
||||
*
|
||||
* Only code that needs to perform permission checks based on the owner of the
|
||||
* idmapping will get access to it. All other code will solely rely on
|
||||
* idmappings. This will get us type safety so it's impossible to conflate
|
||||
* filesystems idmappings with mount idmappings.
|
||||
*
|
||||
* Return: The owner of the idmapped.
|
||||
*/
|
||||
struct user_namespace *mnt_user_ns(const struct vfsmount *mnt)
|
||||
{
|
||||
struct mnt_idmap *idmap = mnt_idmap(mnt);
|
||||
|
||||
/* Return the actual owner of the filesystem instead of the nop. */
|
||||
if (idmap == &nop_mnt_idmap &&
|
||||
!initial_idmapping(mnt->mnt_sb->s_user_ns))
|
||||
return mnt->mnt_sb->s_user_ns;
|
||||
return mnt_idmap_owner(idmap);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mnt_user_ns);
|
||||
|
||||
/**
|
||||
* alloc_mnt_idmap - allocate a new idmapping for the mount
|
||||
* @mnt_userns: owning userns of the idmapping
|
||||
|
||||
@@ -1101,16 +1101,16 @@ void ovl_copyattr(struct inode *inode)
|
||||
{
|
||||
struct path realpath;
|
||||
struct inode *realinode;
|
||||
struct user_namespace *real_mnt_userns;
|
||||
struct mnt_idmap *real_idmap;
|
||||
vfsuid_t vfsuid;
|
||||
vfsgid_t vfsgid;
|
||||
|
||||
ovl_i_path_real(inode, &realpath);
|
||||
realinode = d_inode(realpath.dentry);
|
||||
real_mnt_userns = mnt_user_ns(realpath.mnt);
|
||||
real_idmap = mnt_idmap(realpath.mnt);
|
||||
|
||||
vfsuid = i_uid_into_vfsuid(real_mnt_userns, realinode);
|
||||
vfsgid = i_gid_into_vfsgid(real_mnt_userns, realinode);
|
||||
vfsuid = i_uid_into_vfsuid(real_idmap, realinode);
|
||||
vfsgid = i_gid_into_vfsgid(real_idmap, realinode);
|
||||
|
||||
inode->i_uid = vfsuid_into_kuid(vfsuid);
|
||||
inode->i_gid = vfsgid_into_kgid(vfsgid);
|
||||
|
||||
@@ -388,7 +388,7 @@ posix_acl_permission(struct mnt_idmap *idmap, struct inode *inode,
|
||||
switch(pa->e_tag) {
|
||||
case ACL_USER_OBJ:
|
||||
/* (May have been checked already) */
|
||||
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
|
||||
goto check_perm;
|
||||
break;
|
||||
@@ -399,7 +399,7 @@ posix_acl_permission(struct mnt_idmap *idmap, struct inode *inode,
|
||||
goto mask;
|
||||
break;
|
||||
case ACL_GROUP_OBJ:
|
||||
vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
if (vfsgid_in_group_p(vfsgid)) {
|
||||
found = 1;
|
||||
if ((pa->e_perm & want) == want)
|
||||
@@ -708,7 +708,6 @@ int posix_acl_update_mode(struct mnt_idmap *idmap,
|
||||
struct inode *inode, umode_t *mode_p,
|
||||
struct posix_acl **acl)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
umode_t mode = inode->i_mode;
|
||||
int error;
|
||||
|
||||
@@ -717,7 +716,7 @@ int posix_acl_update_mode(struct mnt_idmap *idmap,
|
||||
return error;
|
||||
if (error == 0)
|
||||
*acl = NULL;
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)) &&
|
||||
if (!vfsgid_in_group_p(i_gid_into_vfsgid(idmap, inode)) &&
|
||||
!capable_wrt_inode_uidgid(idmap, inode, CAP_FSETID))
|
||||
mode &= ~S_ISGID;
|
||||
*mode_p = mode;
|
||||
|
||||
@@ -420,14 +420,13 @@ EXPORT_SYMBOL(vfs_clone_file_range);
|
||||
static bool allow_file_dedupe(struct file *file)
|
||||
{
|
||||
struct mnt_idmap *idmap = file_mnt_idmap(file);
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode = file_inode(file);
|
||||
|
||||
if (capable(CAP_SYS_ADMIN))
|
||||
return true;
|
||||
if (file->f_mode & FMODE_WRITE)
|
||||
return true;
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), current_fsuid()))
|
||||
if (vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode), current_fsuid()))
|
||||
return true;
|
||||
if (!inode_permission(idmap, inode, MAY_WRITE))
|
||||
return true;
|
||||
|
||||
@@ -44,10 +44,8 @@
|
||||
void generic_fillattr(struct mnt_idmap *idmap, struct inode *inode,
|
||||
struct kstat *stat)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
|
||||
vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
|
||||
vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
|
||||
|
||||
stat->dev = inode->i_sb->s_dev;
|
||||
stat->ino = inode->i_ino;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user