finish port to new vfs*id helpers
Subsystems (11)
Christian Brauner
maintainercover finish port to new vfs*id helpers
From: "Christian Brauner (Microsoft)" <[email protected]>
Hey,
A while ago we converted all filesystems and a good chunk of the vfs to rely on the new vfs{g,u}id_t type and the associated type safe helpers. After this change all places where idmapped mounts matter deal with the dedicated new type and can't be easily confused with filesystem wide k{g,u}id_t types. This small series converts the remaining places and removes the old helpers. The series does not contain functional changes. xfstests, LTP, and the libcap testsuite pass without any regressions.
(The series is based on the setgid changes sitting in my tree. It
removes a bunch of open-coding and thus makes the change here simpler as well.)
Thanks!
Christian
Christian Brauner (8):
mnt_idmapping: add missing helpers
fs: use type safe idmapping helpers
caps: use type safe idmapping helpers
apparmor: use type safe idmapping helpers
ima: use type safe idmapping helpers
fuse: port to vfs{g,u}id_t and associated helpers
ovl: port to vfs{g,u}id_t and associated helpers
fs: remove unused idmapping helpers
fs/coredump.c | 4 +- fs/exec.c | 16 ++--- fs/fuse/acl.c | 2 +- fs/inode.c | 8 +-- fs/namei.c | 40 +++++------ fs/overlayfs/util.c | 9 ++- fs/remap_range.c | 2 +- fs/stat.c | 7 +- include/linux/fs.h | 34 ---------- include/linux/mnt_idmapping.h | 100 +++++++++------------------- kernel/capability.c | 4 +- security/apparmor/domain.c | 8 +-- security/apparmor/file.c | 4 +- security/apparmor/lsm.c | 24 ++++--- security/commoncap.c | 51 +++++++------- security/integrity/ima/ima_policy.c | 34 +++++----- 16 files changed, 149 insertions(+), 198 deletions(-)
base-commit: 23a8ce16419a3066829ad4a8b7032a75817af65b
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 1/8 mnt_idmapping: add missing helpers
Add missing helpers needed to convert all remaining places to the type safe idmapped mount helpers. After the conversion we will remove all the old helpers.
---
Notes:
include/linux/mnt_idmapping.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
include/linux/mnt_idmapping.h +32 -0
@@ -98,6 +98,26 @@ static inline bool vfsgid_eq_kgid(vfsgid_t vfsgid, kgid_t kgid)return vfsgid_valid (vfsgid) &&__vfsgid_val (vfsgid) ==__kgid_val (kgid); } +static inline bool vfsuid_gt_kuid (vfsuid_t vfsuid,kuid_t kuid) +{ +return __vfsuid_val (vfsuid) >__kuid_val (kuid); +} + +static inline bool vfsgid_gt_kgid (vfsgid_t vfsgid,kgid_t kgid) +{ +return __vfsgid_val (vfsgid) >__kgid_val (kgid); +} + +static inline bool vfsuid_lt_kuid (vfsuid_t vfsuid,kuid_t kuid) +{ +return __vfsuid_val (vfsuid) <__kuid_val (kuid); +} + +static inline bool vfsgid_lt_kgid (vfsgid_t vfsgid,kgid_t kgid) +{ +return __vfsgid_val (vfsgid) <__kgid_val (kgid); +} +/* * vfs{g,u}ids are created from k{g,u}ids. * We don't allow them to be created from regular {u,g}id.
@@ -333,6 +353,12 @@ static inline bool vfsuid_has_fsmapping(struct user_namespace *mnt_userns,return uid_valid (from_vfsuid (mnt_userns, fs_userns, vfsuid)); } +static inline bool vfsuid_has_mapping (struct user_namespace *userns, +vfsuid_t vfsuid) +{ +return from_kuid (userns,AS_KUIDT (vfsuid)) != (uid_t)-1 ; +} +/** * vfsuid_into_kuid - convert vfsuid into kuid * @vfsuid: the vfsuid to convert
@@ -419,6 +445,12 @@ static inline bool vfsgid_has_fsmapping(struct user_namespace *mnt_userns,return gid_valid (from_vfsgid (mnt_userns, fs_userns, vfsgid)); } +static inline bool vfsgid_has_mapping (struct user_namespace *userns, +vfsgid_t vfsgid) +{ +return from_kgid (userns,AS_KGIDT (vfsgid)) != (gid_t)-1 ; +} +/** * vfsgid_into_kgid - convert vfsgid into kgid * @vfsgid: the vfsgid to convert
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 2/8 fs: use type safe idmapping helpers
In reply to Christian BraunerWe already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.
---
Notes:
fs/coredump.c | 4 ++-- fs/exec.c | 16 ++++++++-------- fs/inode.c | 8 ++++---- fs/namei.c | 40 ++++++++++++++++++++-------------------- fs/remap_range.c | 2 +- fs/stat.c | 7 +++++-- 6 files changed, 40 insertions(+), 37 deletions(-)
fs/coredump.c +2 -2
@@ -716,8 +716,8 @@ void do_coredump(const kernel_siginfo_t *siginfo)* filesystem. */ mnt_userns =file_mnt_user_ns (cprm.file); -if (!uid_eq (i_uid_into_mnt (mnt_userns, inode), -current_fsuid ())) { +if (!vfsuid_eq_kuid (i_uid_into_vfsuid (mnt_userns, inode), +current_fsuid ())) {pr_info_ratelimited ("Core dump to %s aborted: cannot preserve file owner\n" , cn.corename); goto close_fail;
fs/exec.c +8 -8
@@ -1591,8 +1591,8 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)struct user_namespace *mnt_userns;struct inode *inode =file_inode (file);unsigned int mode; -kuid_t uid; -kgid_t gid; +vfsuid_t vfsuid; +vfsgid_t vfsgid;if (!mnt_may_suid (file->f_path.mnt))return ;
@@ -1611,23 +1611,23 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)/* reload atomically mode/uid/gid now that lock held */ mode = inode->i_mode; - uid =i_uid_into_mnt (mnt_userns, inode); - gid =i_gid_into_mnt (mnt_userns, inode); + vfsuid =i_uid_into_vfsuid (mnt_userns, inode); + vfsgid =i_gid_into_vfsgid (mnt_userns, inode);inode_unlock (inode);/* We ignore suid/sgid if there are no mappings for them in the ns */ -if (!kuid_has_mapping (bprm->cred->user_ns, uid) || - !kgid_has_mapping (bprm->cred->user_ns, gid)) +if (!vfsuid_has_mapping (bprm->cred->user_ns, vfsuid) || + !vfsgid_has_mapping (bprm->cred->user_ns, vfsgid))return ;if (mode &S_ISUID ) { bprm->per_clear |=PER_CLEAR_ON_SETID ; - bprm->cred->euid = uid; + bprm->cred->euid =vfsuid_into_kuid (vfsuid); }if ((mode & (S_ISGID |S_IXGRP )) == (S_ISGID |S_IXGRP )) { bprm->per_clear |=PER_CLEAR_ON_SETID ; - bprm->cred->egid = gid; + bprm->cred->egid =vfsgid_into_kgid (vfsgid); } }
fs/inode.c +4 -4
@@ -2326,15 +2326,15 @@ EXPORT_SYMBOL(inode_init_owner);bool inode_owner_or_capable (struct user_namespace *mnt_userns,const struct inode *inode) { -kuid_t i_uid; +vfsuid_t vfsuid;struct user_namespace *ns; - i_uid =i_uid_into_mnt (mnt_userns, inode); -if (uid_eq (current_fsuid (), i_uid)) + vfsuid =i_uid_into_vfsuid (mnt_userns, inode); +if (vfsuid_eq_kuid (vfsuid,current_fsuid ()))return true; ns =current_user_ns (); -if (kuid_has_mapping (ns, i_uid) &&ns_capable (ns,CAP_FOWNER )) +if (vfsuid_has_mapping (ns, vfsuid) &&ns_capable (ns,CAP_FOWNER ))return true;return false; }
fs/namei.c +20 -20
@@ -336,11 +336,11 @@ static int acl_permission_check(struct user_namespace *mnt_userns, struct inode *inode, int mask) {unsigned int mode = inode->i_mode; -kuid_t i_uid; +vfsuid_t vfsuid;/* Are we the owner? If so, ACL's don't matter */ - i_uid =i_uid_into_mnt (mnt_userns, inode); -if (likely (uid_eq (current_fsuid (), i_uid))) { + vfsuid =i_uid_into_vfsuid (mnt_userns, inode); +if (likely (vfsuid_eq_kuid (vfsuid,current_fsuid ()))) { mask &=7 ; mode >>=6 ;return (mask & ~mode) ? -EACCES :0 ;
@@ -362,8 +362,8 @@ static int acl_permission_check(struct user_namespace *mnt_userns,* about? Need to check group ownership if so. */ if (mask & (mode ^ (mode >>3 ))) { -kgid_t kgid =i_gid_into_mnt (mnt_userns, inode); -if (in_group_p (kgid)) +vfsgid_t vfsgid =i_gid_into_vfsgid (mnt_userns, inode); +if (vfsgid_in_group_p (vfsgid)) mode >>=3 ; }
@@ -581,7 +581,7 @@ struct nameidata {struct nameidata *saved;unsigned root_seq;int dfd; -kuid_t dir_uid; +vfsuid_t dir_vfsuid;umode_t dir_mode; } __randomize_layout;
@@ -1095,15 +1095,15 @@ fs_initcall(init_fs_namei_sysctls);static inline int may_follow_link (struct nameidata *nd,const struct inode *inode) {struct user_namespace *mnt_userns; -kuid_t i_uid; +vfsuid_t vfsuid;if (!sysctl_protected_symlinks)return 0 ; mnt_userns =mnt_user_ns (nd->path.mnt); - i_uid =i_uid_into_mnt (mnt_userns, inode); + vfsuid =i_uid_into_vfsuid (mnt_userns, inode);/* Allowed if owner and follower match. */ -if (uid_eq (current_cred ()->fsuid, i_uid)) +if (vfsuid_eq_kuid (vfsuid,current_fsuid ()))return 0 ;/* Allowed if parent directory not sticky and world-writable. */
@@ -1111,7 +1111,7 @@ static inline int may_follow_link(struct nameidata *nd, const struct inode *inodreturn 0 ;/* Allowed if parent directory and link owner match. */ -if (uid_valid (nd->dir_uid) &&uid_eq (nd->dir_uid, i_uid)) +if (vfsuid_valid (nd->dir_vfsuid) &&vfsuid_eq (nd->dir_vfsuid, vfsuid))return 0 ;if (nd->flags &LOOKUP_RCU )
@@ -1183,8 +1183,8 @@ int may_linkat(struct user_namespace *mnt_userns, const struct path *link)struct inode *inode = link->dentry->d_inode;/* Inode writeback is not safe when the uid or gid are invalid. */ -if (!uid_valid (i_uid_into_mnt (mnt_userns, inode)) || - !gid_valid (i_gid_into_mnt (mnt_userns, inode))) +if (!vfsuid_valid (i_uid_into_vfsuid (mnt_userns, inode)) || + !vfsgid_valid (i_gid_into_vfsgid (mnt_userns, inode)))return -EOVERFLOW ;if (!sysctl_protected_hardlinks)
@@ -1232,13 +1232,13 @@ static int may_create_in_sticky(struct user_namespace *mnt_userns, struct nameidata *nd, struct inode *const inode) { umode_t dir_mode = nd->dir_mode; -kuid_t dir_uid = nd->dir_uid; +vfsuid_t dir_vfsuid = nd->dir_vfsuid;if ((!sysctl_protected_fifos &&S_ISFIFO (inode->i_mode)) || (!sysctl_protected_regular &&S_ISREG (inode->i_mode)) ||likely (!(dir_mode &S_ISVTX )) || -uid_eq (i_uid_into_mnt (mnt_userns, inode), dir_uid) || -uid_eq (current_fsuid (),i_uid_into_mnt (mnt_userns, inode))) +vfsuid_eq (i_uid_into_vfsuid (mnt_userns, inode), dir_vfsuid) || +vfsuid_eq_kuid (i_uid_into_vfsuid (mnt_userns, inode),current_fsuid ()))return 0 ; if (likely(dir_mode & 0002) ||
@@ -2307,7 +2307,7 @@ static int link_path_walk(const char *name, struct nameidata *nd) OK:/* pathname or trailing symlink, done */ if (!depth) { - nd->dir_uid =i_uid_into_mnt (mnt_userns, nd->inode); + nd->dir_vfsuid =i_uid_into_vfsuid (mnt_userns, nd->inode); nd->dir_mode = nd->inode->i_mode; nd->flags &= ~LOOKUP_PARENT ;return 0 ;
@@ -2885,9 +2885,9 @@ int __check_sticky(struct user_namespace *mnt_userns, struct inode *dir, {kuid_t fsuid =current_fsuid (); -if (uid_eq (i_uid_into_mnt (mnt_userns, inode), fsuid)) +if (vfsuid_eq_kuid (i_uid_into_vfsuid (mnt_userns, inode), fsuid))return 0 ; -if (uid_eq (i_uid_into_mnt (mnt_userns, dir), fsuid)) +if (vfsuid_eq_kuid (i_uid_into_vfsuid (mnt_userns, dir), fsuid))return 0 ;return !capable_wrt_inode_uidgid (mnt_userns, inode,CAP_FOWNER ); }
@@ -2926,8 +2926,8 @@ static int may_delete(struct user_namespace *mnt_userns, struct inode *dir,BUG_ON (victim->d_parent->d_inode != dir);/* Inode writeback is not safe when the uid or gid are invalid. */ -if (!uid_valid (i_uid_into_mnt (mnt_userns, inode)) || - !gid_valid (i_gid_into_mnt (mnt_userns, inode))) +if (!vfsuid_valid (i_uid_into_vfsuid (mnt_userns, inode)) || + !vfsgid_valid (i_gid_into_vfsgid (mnt_userns, inode)))return -EOVERFLOW ;audit_inode_child (dir, victim,AUDIT_TYPE_CHILD_DELETE );
fs/remap_range.c +1 -1
@@ -429,7 +429,7 @@ static bool allow_file_dedupe(struct file *file)return true;if (file->f_mode &FMODE_WRITE )return true; -if (uid_eq (current_fsuid (),i_uid_into_mnt (mnt_userns, inode))) +if (vfsuid_eq_kuid (i_uid_into_vfsuid (mnt_userns, inode),current_fsuid ()))return true;if (!inode_permission (mnt_userns, inode,MAY_WRITE ))return true;
fs/stat.c +5 -2
@@ -44,12 +44,15 @@void generic_fillattr (struct user_namespace *mnt_userns,struct inode *inode,struct kstat *stat) { +vfsuid_t vfsuid =i_uid_into_vfsuid (mnt_userns, inode); +vfsgid_t vfsgid =i_gid_into_vfsgid (mnt_userns, inode); + stat->dev = inode->i_sb->s_dev; stat->ino = inode->i_ino; stat->mode = inode->i_mode; stat->nlink = inode->i_nlink; - stat->uid =i_uid_into_mnt (mnt_userns, inode); - stat->gid =i_gid_into_mnt (mnt_userns, inode); + stat->uid =vfsuid_into_kuid (vfsuid); + stat->gid =vfsgid_into_kgid (vfsgid); stat->rdev = inode->i_rdev; stat->size =i_size_read (inode); stat->atime = inode->i_atime;
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 3/8 caps: use type safe idmapping helpers
In reply to Christian BraunerWe already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.
---
Notes:
kernel/capability.c | 4 ++-- security/commoncap.c | 51 ++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 27 deletions(-)
kernel/capability.c +2 -2
@@ -489,8 +489,8 @@ bool privileged_wrt_inode_uidgid(struct user_namespace *ns, struct user_namespace *mnt_userns, const struct inode *inode) { - return kuid_has_mapping(ns, i_uid_into_mnt(mnt_userns, inode)) && - kgid_has_mapping(ns, i_gid_into_mnt(mnt_userns, inode)); + return vfsuid_has_mapping(ns, i_uid_into_vfsuid(mnt_userns, inode)) && + vfsgid_has_mapping(ns, i_gid_into_vfsgid(mnt_userns, inode)); }/**
security/commoncap.c +26 -25
130 lines not on this page · raw message
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 5/8 ima: use type safe idmapping helpers
In reply to Christian BraunerWe already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.
---
Notes:
security/integrity/ima/ima_policy.c | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-)
security/integrity/ima/ima_policy.c +18 -16
@@ -85,8 +85,8 @@ struct ima_rule_entry {kgid_t fgroup;bool (*uid_op)(kuid_t cred_uid,kuid_t rule_uid);/* Handlers for operators */ bool (*gid_op)(kgid_t cred_gid,kgid_t rule_gid); -bool (*fowner_op)(kuid_t cred_uid,kuid_t rule_uid);/* uid_eq(), uid_gt(), uid_lt() */ -bool (*fgroup_op)(kgid_t cred_gid,kgid_t rule_gid);/* gid_eq(), gid_gt(), gid_lt() */ +bool (*fowner_op)(vfsuid_t vfsuid,kuid_t rule_uid);/* vfsuid_eq_kuid(), vfsuid_gt_kuid(), vfsuid_lt_kuid() */ +bool (*fgroup_op)(vfsgid_t vfsgid,kgid_t rule_gid);/* vfsgid_eq_kgid(), vfsgid_gt_kgid(), vfsgid_lt_kgid() */ int pcr;unsigned int allowed_algos;/* bitfield of allowed hash algorithms */ struct {
@@ -186,11 +186,11 @@ static struct ima_rule_entry default_appraise_rules[] __ro_after_init = { .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},#endif #ifndef CONFIG_IMA_APPRAISE_SIGNED_INIT - {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq, + {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &vfsuid_eq_kuid, .flags = IMA_FOWNER}, #else /* force signature */ - {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &uid_eq, + {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .fowner_op = &vfsuid_eq_kuid, .flags = IMA_FOWNER | IMA_DIGSIG_REQUIRED}, #endif };
@@ -601,10 +601,12 @@ static bool ima_match_rules(struct ima_rule_entry *rule,return false; }if ((rule->flags &IMA_FOWNER ) && - !rule->fowner_op (i_uid_into_mnt (mnt_userns, inode), rule->fowner)) + !rule->fowner_op (i_uid_into_vfsuid (mnt_userns, inode), + rule->fowner))return false;if ((rule->flags &IMA_FGROUP ) && - !rule->fgroup_op (i_gid_into_mnt (mnt_userns, inode), rule->fgroup)) + !rule->fgroup_op (i_gid_into_vfsgid (mnt_userns, inode), + rule->fgroup))return false;for (i =0 ; i <MAX_LSM_RULES ; i++) {int rc =0 ;
@@ -1371,8 +1373,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) entry->fgroup =INVALID_GID ; entry->uid_op = &uid_eq; entry->gid_op = &gid_eq; - entry->fowner_op = &uid_eq; - entry->fgroup_op = &gid_eq; + entry->fowner_op = &vfsuid_eq_kuid; + entry->fgroup_op = &vfsgid_eq_kgid; entry->action =UNKNOWN ;while ((p =strsep (&rule," \t" )) !=NULL ) {substring_t args[MAX_OPT_ARGS ];
@@ -1650,11 +1652,11 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) }break ;case Opt_fowner_gt: - entry->fowner_op = &uid_gt; + entry->fowner_op = &vfsuid_gt_kuid; fallthrough;case Opt_fowner_lt:if (token == Opt_fowner_lt) - entry->fowner_op = &uid_lt; + entry->fowner_op = &vfsuid_lt_kuid; fallthrough;case Opt_fowner_eq:ima_log_string_op (ab,"fowner" , args[0 ].from, token);
@@ -1676,11 +1678,11 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) }break ;case Opt_fgroup_gt: - entry->fgroup_op = &gid_gt; + entry->fgroup_op = &vfsgid_gt_kgid; fallthrough;case Opt_fgroup_lt:if (token == Opt_fgroup_lt) - entry->fgroup_op = &gid_lt; + entry->fgroup_op = &vfsgid_lt_kgid; fallthrough;case Opt_fgroup_eq:ima_log_string_op (ab,"fgroup" , args[0 ].from, token);
@@ -2151,9 +2153,9 @@ int ima_policy_show(struct seq_file *m, void *v)if (entry->flags &IMA_FOWNER ) {snprintf (tbuf,sizeof (tbuf),"%d" ,__kuid_val (entry->fowner)); -if (entry->fowner_op == &uid_gt) +if (entry->fowner_op == &vfsuid_gt_kuid)seq_printf (m,pt (Opt_fowner_gt), tbuf); -else if (entry->fowner_op == &uid_lt) +else if (entry->fowner_op == &vfsuid_lt_kuid)seq_printf (m,pt (Opt_fowner_lt), tbuf);else seq_printf (m,pt (Opt_fowner_eq), tbuf);
@@ -2162,9 +2164,9 @@ int ima_policy_show(struct seq_file *m, void *v)if (entry->flags &IMA_FGROUP ) {snprintf (tbuf,sizeof (tbuf),"%d" ,__kgid_val (entry->fgroup)); -if (entry->fgroup_op == &gid_gt) +if (entry->fgroup_op == &vfsgid_gt_kgid)seq_printf (m,pt (Opt_fgroup_gt), tbuf); -else if (entry->fgroup_op == &gid_lt) +else if (entry->fgroup_op == &vfsgid_lt_kgid)seq_printf (m,pt (Opt_fgroup_lt), tbuf);else seq_printf (m,pt (Opt_fgroup_eq), tbuf);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 4/8 apparmor: use type safe idmapping helpers
In reply to Christian BraunerWe already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.
---
Notes:
security/apparmor/domain.c | 8 ++++---- security/apparmor/file.c | 4 +++- security/apparmor/lsm.c | 24 ++++++++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-)
security/apparmor/domain.c +4 -4
@@ -859,10 +859,10 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm)const char *info =NULL ;int error =0 ;bool unsafe = false; -kuid_t i_uid =i_uid_into_mnt (file_mnt_user_ns (bprm->file), -file_inode (bprm->file)); +vfsuid_t vfsuid =i_uid_into_vfsuid (file_mnt_user_ns (bprm->file), +file_inode (bprm->file));struct path_cond cond = { - i_uid, +vfsuid_into_kuid (vfsuid),file_inode (bprm->file)->i_mode };
@@ -970,7 +970,7 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm) error =fn_for_each (label, profile,aa_audit_file (profile, &nullperms,OP_EXEC ,MAY_EXEC , bprm->filename,NULL , new, - i_uid, info, error)); +vfsuid_into_kuid (vfsuid), info, error));aa_put_label (new); goto done; }
security/apparmor/file.c +3 -1
@@ -510,8 +510,10 @@ static int __file_path_perm(const char *op, struct aa_label *label, {struct aa_profile *profile;struct aa_perms perms = {}; +vfsuid_t vfsuid =i_uid_into_vfsuid (file_mnt_user_ns (file), +file_inode (file));struct path_cond cond = { - .uid =i_uid_into_mnt (file_mnt_user_ns (file),file_inode (file)), + .uid =vfsuid_into_kuid (vfsuid), .mode =file_inode (file)->i_mode };char *buffer;
security/apparmor/lsm.c +16 -8
@@ -225,8 +225,10 @@ static int common_perm(const char *op, const struct path *path, u32 mask,static int common_perm_cond (const char *op,const struct path *path,u32 mask) {struct user_namespace *mnt_userns =mnt_user_ns (path->mnt); +vfsuid_t vfsuid =i_uid_into_vfsuid (mnt_userns, +d_backing_inode (path->dentry));struct path_cond cond = { -i_uid_into_mnt (mnt_userns,d_backing_inode (path->dentry)), +vfsuid_into_kuid (vfsuid),d_backing_inode (path->dentry)->i_mode };
@@ -270,11 +272,12 @@ static int common_perm_rm(const char *op, const struct path *dir,struct inode *inode =d_backing_inode (dentry);struct user_namespace *mnt_userns =mnt_user_ns (dir->mnt);struct path_cond cond = { }; +vfsuid_t vfsuid =i_uid_into_vfsuid (mnt_userns, inode);if (!inode || !path_mediated_fs (dentry))return 0 ; - cond.uid =i_uid_into_mnt (mnt_userns, inode); + cond.uid =vfsuid_into_kuid (vfsuid); cond.mode = inode->i_mode;return common_perm_dir_dentry (op, dir, dentry, mask, &cond);
@@ -368,20 +371,23 @@ static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_d label =begin_current_label_crit_section ();if (!unconfined (label)) {struct user_namespace *mnt_userns =mnt_user_ns (old_dir->mnt); +vfsuid_t vfsuid;struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };struct path_cond cond = { -i_uid_into_mnt (mnt_userns,d_backing_inode (old_dentry)), -d_backing_inode (old_dentry)->i_mode + .mode =d_backing_inode (old_dentry)->i_mode }; + vfsuid =i_uid_into_vfsuid (mnt_userns,d_backing_inode (old_dentry)); + cond.uid =vfsuid_into_kuid (vfsuid);if (flags &RENAME_EXCHANGE ) {struct path_cond cond_exchange = { -i_uid_into_mnt (mnt_userns,d_backing_inode (new_dentry)), -d_backing_inode (new_dentry)->i_mode + .mode =d_backing_inode (new_dentry)->i_mode, }; + vfsuid =i_uid_into_vfsuid (mnt_userns,d_backing_inode (old_dentry)); + cond_exchange.uid =vfsuid_into_kuid (vfsuid); error = aa_path_perm(OP_RENAME_SRC, label, &new_path, 0, MAY_READ | AA_MAY_GETATTR | MAY_WRITE |
@@ -447,10 +453,12 @@ static int apparmor_file_open(struct file *file)if (!unconfined (label)) {struct user_namespace *mnt_userns =file_mnt_user_ns (file);struct inode *inode =file_inode (file); +vfsuid_t vfsuid;struct path_cond cond = { -i_uid_into_mnt (mnt_userns, inode), - inode->i_mode + .mode = inode->i_mode, }; + vfsuid =i_uid_into_vfsuid (mnt_userns, inode); + cond.uid =vfsuid_into_kuid (vfsuid); error =aa_path_perm (OP_OPEN , label, &file->f_path,0 ,aa_map_file_to_perms (file), &cond);
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 6/8 fuse: port to vfs{g,u}id_t and associated helpers
In reply to Christian BraunerA while ago we introduced a dedicated vfs{g,u}id_t type in commit 1e5267cd0895 ("mnt_idmapping: add vfs{g,u}id_t"). We already switched over a good part of the VFS. Ultimately we will remove all legacy idmapped mount helpers that operate only on k{g,u}id_t in favor of the new type safe helpers that operate on vfs{g,u}id_t.
---
Notes:
Note that this patch is currently also in Miklos tree.
fs/fuse/acl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/acl.c +1 -1
@@ -98,7 +98,7 @@ int fuse_set_acl(struct user_namespace *mnt_userns, struct inode *inode,return ret; } -if (!in_group_p (i_gid_into_mnt (&init_user_ns, inode)) && +if (!vfsgid_in_group_p (i_gid_into_vfsgid (&init_user_ns, inode)) && !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) extra_flags |=FUSE_SETXATTR_ACL_KILL_SGID ;
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 7/8 ovl: port to vfs{g,u}id_t and associated helpers
In reply to Christian BraunerA while ago we introduced a dedicated vfs{g,u}id_t type in commit 1e5267cd0895 ("mnt_idmapping: add vfs{g,u}id_t"). We already switched over a good part of the VFS. Ultimately we will remove all legacy idmapped mount helpers that operate only on k{g,u}id_t in favor of the new type safe helpers that operate on vfs{g,u}id_t.
---
Notes:
Note that this patch is currently also in Miklos tree.
fs/overlayfs/util.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/overlayfs/util.c +7 -2
@@ -1104,13 +1104,18 @@ void ovl_copyattr(struct inode *inode)struct path realpath;struct inode *realinode;struct user_namespace *real_mnt_userns; +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); - inode->i_uid =i_uid_into_mnt (real_mnt_userns, realinode); - inode->i_gid =i_gid_into_mnt (real_mnt_userns, realinode); + vfsuid =i_uid_into_vfsuid (real_mnt_userns, realinode); + vfsgid =i_gid_into_vfsgid (real_mnt_userns, realinode); + + inode->i_uid =vfsuid_into_kuid (vfsuid); + inode->i_gid =vfsgid_into_kgid (vfsgid); inode->i_mode = realinode->i_mode; inode->i_atime = realinode->i_atime; inode->i_mtime = realinode->i_mtime;
Signature · 1 line
2.34.1
Christian Brauner
maintainerPATCH 8/8 fs: remove unused idmapping helpers
In reply to Christian BraunerNow that all places can deal with the new type safe helpers remove all of the old helpers.
---
Notes:
include/linux/fs.h | 34 ------------------ include/linux/mnt_idmapping.h | 68 ----------------------------------- 2 files changed, 102 deletions(-)
include/linux/fs.h +0 -34
@@ -1612,23 +1612,6 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid =make_kgid (i_user_ns (inode), gid); } -/** -* i_uid_into_mnt - map an inode's i_uid down into a mnt_userns -* @mnt_userns: user namespace of the mount the inode was found from -* @inode: inode to map -* -* Note, this will eventually be removed completely in favor of the type-safe -* i_uid_into_vfsuid(). -* -* Return: the inode's i_uid mapped down according to @mnt_userns. -* If the inode's i_uid has no mapping INVALID_UID is returned. -*/ -static inline kuid_t i_uid_into_mnt (struct user_namespace *mnt_userns, -const struct inode *inode) -{ -return AS_KUIDT (make_vfsuid (mnt_userns,i_user_ns (inode), inode->i_uid)); -} -/** * i_uid_into_vfsuid - map an inode's i_uid down into a mnt_userns * @mnt_userns: user namespace of the mount the inode was found from
@@ -1681,23 +1664,6 @@ static inline void i_uid_update(struct user_namespace *mnt_userns, attr->ia_vfsuid); } -/** -* i_gid_into_mnt - map an inode's i_gid down into a mnt_userns -* @mnt_userns: user namespace of the mount the inode was found from -* @inode: inode to map -* -* Note, this will eventually be removed completely in favor of the type-safe -* i_gid_into_vfsgid(). -* -* Return: the inode's i_gid mapped down according to @mnt_userns. -* If the inode's i_gid has no mapping INVALID_GID is returned. -*/ -static inline kgid_t i_gid_into_mnt (struct user_namespace *mnt_userns, -const struct inode *inode) -{ -return AS_KGIDT (make_vfsgid (mnt_userns,i_user_ns (inode), inode->i_gid)); -} -/** * i_gid_into_vfsgid - map an inode's i_gid down into a mnt_userns * @mnt_userns: user namespace of the mount the inode was found from
include/linux/mnt_idmapping.h +0 -68
92 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 12 lines · Christian Brauner
From: "Christian Brauner (Microsoft)" <[email protected]>
Hey,
A while ago we converted all filesystems and a good chunk of the vfs to rely on the new vfs{g,u}id_t type and the associated type safe helpers. After this change all places where idmapped mounts matter deal with the dedicated new type and can't be easily confused with filesystem wide k{g,u}id_t types. This small series converts the remaining places and removes the old helpers. The series does not contain functional changes. xfstests, LTP, and the libcap testsuite pass without any regressions.
Quoted 6 lines
(The series is based on the setgid changes sitting in my tree. It
removes a bunch of open-coding and thus makes the change here simpler as well.)Thanks!
Christian
Looks good to me.
Re: [apparmor] [PATCH 4/8] apparmor: use type safe idmapping helpers
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
We already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.Signed-off-by Christian Brauner (Microsoft) <[email protected]>
I have pulled this into my tree
Quoted 125 lines
---
Notes:
security/apparmor/domain.c | 8 ++++---- security/apparmor/file.c | 4 +++- security/apparmor/lsm.c | 24 ++++++++++++++++-------- 3 files changed, 23 insertions(+), 13 deletions(-)security/apparmor/domain.c +4
-4@@ -859,10 +859,10 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm)const char *info =NULL ;int error =0 ;bool unsafe = false; -kuid_t i_uid =i_uid_into_mnt (file_mnt_user_ns (bprm->file), -file_inode (bprm->file)); +vfsuid_t vfsuid =i_uid_into_vfsuid (file_mnt_user_ns (bprm->file), +file_inode (bprm->file));struct path_cond cond = { - i_uid, +vfsuid_into_kuid (vfsuid),file_inode (bprm->file)->i_mode };@@ -970,7 +970,7 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm) error =fn_for_each (label, profile,aa_audit_file (profile, &nullperms,OP_EXEC ,MAY_EXEC , bprm->filename,NULL , new, - i_uid, info, error)); +vfsuid_into_kuid (vfsuid), info, error));aa_put_label (new); goto done; }security/apparmor/file.c +3
-1@@ -510,8 +510,10 @@ static int __file_path_perm(const char *op, struct aa_label *label, {struct aa_profile *profile;struct aa_perms perms = {}; +vfsuid_t vfsuid =i_uid_into_vfsuid (file_mnt_user_ns (file), +file_inode (file));struct path_cond cond = { - .uid =i_uid_into_mnt (file_mnt_user_ns (file),file_inode (file)), + .uid =vfsuid_into_kuid (vfsuid), .mode =file_inode (file)->i_mode };char *buffer;security/apparmor/lsm.c +16
-8@@ -225,8 +225,10 @@ static int common_perm(const char *op, const struct path *path, u32 mask,static int common_perm_cond (const char *op,const struct path *path,u32 mask) {struct user_namespace *mnt_userns =mnt_user_ns (path->mnt); +vfsuid_t vfsuid =i_uid_into_vfsuid (mnt_userns, +d_backing_inode (path->dentry));struct path_cond cond = { -i_uid_into_mnt (mnt_userns,d_backing_inode (path->dentry)), +vfsuid_into_kuid (vfsuid),d_backing_inode (path->dentry)->i_mode };@@ -270,11 +272,12 @@ static int common_perm_rm(const char *op, const struct path *dir,struct inode *inode =d_backing_inode (dentry);struct user_namespace *mnt_userns =mnt_user_ns (dir->mnt);struct path_cond cond = { }; +vfsuid_t vfsuid =i_uid_into_vfsuid (mnt_userns, inode);if (!inode || !path_mediated_fs (dentry))return 0 ; - cond.uid =i_uid_into_mnt (mnt_userns, inode); + cond.uid =vfsuid_into_kuid (vfsuid); cond.mode = inode->i_mode;return common_perm_dir_dentry (op, dir, dentry, mask, &cond);@@ -368,20 +371,23 @@ static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_d label =begin_current_label_crit_section ();if (!unconfined (label)) {struct user_namespace *mnt_userns =mnt_user_ns (old_dir->mnt); +vfsuid_t vfsuid;struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };struct path_cond cond = { -i_uid_into_mnt (mnt_userns,d_backing_inode (old_dentry)), -d_backing_inode (old_dentry)->i_mode + .mode =d_backing_inode (old_dentry)->i_mode }; + vfsuid =i_uid_into_vfsuid (mnt_userns,d_backing_inode (old_dentry)); + cond.uid =vfsuid_into_kuid (vfsuid);if (flags &RENAME_EXCHANGE ) {struct path_cond cond_exchange = { -i_uid_into_mnt (mnt_userns,d_backing_inode (new_dentry)), -d_backing_inode (new_dentry)->i_mode + .mode =d_backing_inode (new_dentry)->i_mode, }; + vfsuid =i_uid_into_vfsuid (mnt_userns,d_backing_inode (old_dentry)); + cond_exchange.uid =vfsuid_into_kuid (vfsuid); error = aa_path_perm(OP_RENAME_SRC, label, &new_path, 0, MAY_READ | AA_MAY_GETATTR | MAY_WRITE |@@ -447,10 +453,12 @@ static int apparmor_file_open(struct file *file)if (!unconfined (label)) {struct user_namespace *mnt_userns =file_mnt_user_ns (file);struct inode *inode =file_inode (file); +vfsuid_t vfsuid;struct path_cond cond = { -i_uid_into_mnt (mnt_userns, inode), - inode->i_mode + .mode = inode->i_mode, }; + vfsuid =i_uid_into_vfsuid (mnt_userns, inode); + cond.uid =vfsuid_into_kuid (vfsuid); error =aa_path_perm (OP_OPEN , label, &file->f_path,0 ,aa_map_file_to_perms (file), &cond);
Christian Brauner
maintainerRe: [apparmor] [PATCH 4/8] apparmor: use type safe idmapping helpers
Quoted 9 lines · John Johansen
Quoted 6 lines · Christian Brauner
We already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.Signed-off-by Christian Brauner (Microsoft) <[email protected]>Acked-by John Johansen <[email protected]>
Would you mind if I carry this patch together with the other conversion patches in my tree? This would make the whole conversion a lot simpler because we're removing a bunch of old helpers at the end.
John Johansen
maintainerRe: [apparmor] [PATCH 4/8] apparmor: use type safe idmapping helpers
Quoted 7 lines · Christian Brauner
Quoted 6 lines · John Johansen
Quoted 5 lines · Christian Brauner
We already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Christian Brauner (Microsoft) <[email protected]>Acked-by John Johansen <[email protected]>Would you mind if I carry this patch together with the other conversion patches in my tree? This would make the whole conversion a lot simpler because we're removing a bunch of old helpers at the end.
Not at all. I almost asked which tree you wanted it in, and then got distracted and when I came back to it ...
Christian Brauner
maintainerRe: [apparmor] [PATCH 4/8] apparmor: use type safe idmapping helpers
Quoted 10 lines · John Johansen
Quoted 9 lines · Christian Brauner
Quoted 8 lines · John Johansen
Quoted 6 lines · Christian Brauner
We already ported most parts and filesystems over for v6.0 to the new vfs{g,u}id_t type and associated helpers for v6.0. Convert the remaining places so we can remove all the old helpers.
This is a non-functional change.Signed-off-by Christian Brauner (Microsoft) <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Acked-by John Johansen <[email protected]>Would you mind if I carry this patch together with the other conversion patches in my tree? This would make the whole conversion a lot simpler because we're removing a bunch of old helpers at the end.
Not at all. I almost asked which tree you wanted it in, and then got distracted and when I came back to it ...
Thank you! I appreciate it.