Skip to content

Commit e1212e9

Browse files
committed
Merge tag 'fs.vfsuid.conversion.v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping
Pull vfsuid updates from Christian Brauner: "Last cycle we introduced the vfs{g,u}id_t types and associated helpers to gain type safety when dealing with idmapped mounts. That initial work already converted a lot of places over but there were still some left, This converts all remaining places that still make use of non-type safe idmapping helpers to rely on the new type safe vfs{g,u}id based helpers. Afterwards it removes all the old non-type safe helpers" * tag 'fs.vfsuid.conversion.v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping: fs: remove unused idmapping helpers ovl: port to vfs{g,u}id_t and associated helpers fuse: port to vfs{g,u}id_t and associated helpers ima: use type safe idmapping helpers apparmor: use type safe idmapping helpers caps: use type safe idmapping helpers fs: use type safe idmapping helpers mnt_idmapping: add missing helpers
2 parents cf619f8 + eb7718c commit e1212e9

File tree

16 files changed

+150
-198
lines changed

16 files changed

+150
-198
lines changed

fs/coredump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,8 @@ void do_coredump(const kernel_siginfo_t *siginfo)
720720
* filesystem.
721721
*/
722722
mnt_userns = file_mnt_user_ns(cprm.file);
723-
if (!uid_eq(i_uid_into_mnt(mnt_userns, inode),
724-
current_fsuid())) {
723+
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode),
724+
current_fsuid())) {
725725
pr_info_ratelimited("Core dump to %s aborted: cannot preserve file owner\n",
726726
cn.corename);
727727
goto close_fail;

fs/exec.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,8 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
15991599
struct user_namespace *mnt_userns;
16001600
struct inode *inode = file_inode(file);
16011601
unsigned int mode;
1602-
kuid_t uid;
1603-
kgid_t gid;
1602+
vfsuid_t vfsuid;
1603+
vfsgid_t vfsgid;
16041604

16051605
if (!mnt_may_suid(file->f_path.mnt))
16061606
return;
@@ -1619,23 +1619,23 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
16191619

16201620
/* reload atomically mode/uid/gid now that lock held */
16211621
mode = inode->i_mode;
1622-
uid = i_uid_into_mnt(mnt_userns, inode);
1623-
gid = i_gid_into_mnt(mnt_userns, inode);
1622+
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
1623+
vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
16241624
inode_unlock(inode);
16251625

16261626
/* We ignore suid/sgid if there are no mappings for them in the ns */
1627-
if (!kuid_has_mapping(bprm->cred->user_ns, uid) ||
1628-
!kgid_has_mapping(bprm->cred->user_ns, gid))
1627+
if (!vfsuid_has_mapping(bprm->cred->user_ns, vfsuid) ||
1628+
!vfsgid_has_mapping(bprm->cred->user_ns, vfsgid))
16291629
return;
16301630

16311631
if (mode & S_ISUID) {
16321632
bprm->per_clear |= PER_CLEAR_ON_SETID;
1633-
bprm->cred->euid = uid;
1633+
bprm->cred->euid = vfsuid_into_kuid(vfsuid);
16341634
}
16351635

16361636
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
16371637
bprm->per_clear |= PER_CLEAR_ON_SETID;
1638-
bprm->cred->egid = gid;
1638+
bprm->cred->egid = vfsgid_into_kgid(vfsgid);
16391639
}
16401640
}
16411641

fs/fuse/acl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int fuse_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,
9999
return ret;
100100
}
101101

102-
if (!in_group_p(i_gid_into_mnt(&init_user_ns, inode)) &&
102+
if (!vfsgid_in_group_p(i_gid_into_vfsgid(&init_user_ns, inode)) &&
103103
!capable_wrt_inode_uidgid(&init_user_ns, inode, CAP_FSETID))
104104
extra_flags |= FUSE_SETXATTR_ACL_KILL_SGID;
105105

fs/inode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,15 +2323,15 @@ EXPORT_SYMBOL(inode_init_owner);
23232323
bool inode_owner_or_capable(struct user_namespace *mnt_userns,
23242324
const struct inode *inode)
23252325
{
2326-
kuid_t i_uid;
2326+
vfsuid_t vfsuid;
23272327
struct user_namespace *ns;
23282328

2329-
i_uid = i_uid_into_mnt(mnt_userns, inode);
2330-
if (uid_eq(current_fsuid(), i_uid))
2329+
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
2330+
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
23312331
return true;
23322332

23332333
ns = current_user_ns();
2334-
if (kuid_has_mapping(ns, i_uid) && ns_capable(ns, CAP_FOWNER))
2334+
if (vfsuid_has_mapping(ns, vfsuid) && ns_capable(ns, CAP_FOWNER))
23352335
return true;
23362336
return false;
23372337
}

fs/namei.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ static int acl_permission_check(struct user_namespace *mnt_userns,
336336
struct inode *inode, int mask)
337337
{
338338
unsigned int mode = inode->i_mode;
339-
kuid_t i_uid;
339+
vfsuid_t vfsuid;
340340

341341
/* Are we the owner? If so, ACL's don't matter */
342-
i_uid = i_uid_into_mnt(mnt_userns, inode);
343-
if (likely(uid_eq(current_fsuid(), i_uid))) {
342+
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
343+
if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) {
344344
mask &= 7;
345345
mode >>= 6;
346346
return (mask & ~mode) ? -EACCES : 0;
@@ -362,8 +362,8 @@ static int acl_permission_check(struct user_namespace *mnt_userns,
362362
* about? Need to check group ownership if so.
363363
*/
364364
if (mask & (mode ^ (mode >> 3))) {
365-
kgid_t kgid = i_gid_into_mnt(mnt_userns, inode);
366-
if (in_group_p(kgid))
365+
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
366+
if (vfsgid_in_group_p(vfsgid))
367367
mode >>= 3;
368368
}
369369

@@ -581,7 +581,7 @@ struct nameidata {
581581
struct nameidata *saved;
582582
unsigned root_seq;
583583
int dfd;
584-
kuid_t dir_uid;
584+
vfsuid_t dir_vfsuid;
585585
umode_t dir_mode;
586586
} __randomize_layout;
587587

@@ -1095,23 +1095,23 @@ fs_initcall(init_fs_namei_sysctls);
10951095
static inline int may_follow_link(struct nameidata *nd, const struct inode *inode)
10961096
{
10971097
struct user_namespace *mnt_userns;
1098-
kuid_t i_uid;
1098+
vfsuid_t vfsuid;
10991099

11001100
if (!sysctl_protected_symlinks)
11011101
return 0;
11021102

11031103
mnt_userns = mnt_user_ns(nd->path.mnt);
1104-
i_uid = i_uid_into_mnt(mnt_userns, inode);
1104+
vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
11051105
/* Allowed if owner and follower match. */
1106-
if (uid_eq(current_cred()->fsuid, i_uid))
1106+
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
11071107
return 0;
11081108

11091109
/* Allowed if parent directory not sticky and world-writable. */
11101110
if ((nd->dir_mode & (S_ISVTX|S_IWOTH)) != (S_ISVTX|S_IWOTH))
11111111
return 0;
11121112

11131113
/* Allowed if parent directory and link owner match. */
1114-
if (uid_valid(nd->dir_uid) && uid_eq(nd->dir_uid, i_uid))
1114+
if (vfsuid_valid(nd->dir_vfsuid) && vfsuid_eq(nd->dir_vfsuid, vfsuid))
11151115
return 0;
11161116

11171117
if (nd->flags & LOOKUP_RCU)
@@ -1183,8 +1183,8 @@ int may_linkat(struct user_namespace *mnt_userns, const struct path *link)
11831183
struct inode *inode = link->dentry->d_inode;
11841184

11851185
/* Inode writeback is not safe when the uid or gid are invalid. */
1186-
if (!uid_valid(i_uid_into_mnt(mnt_userns, inode)) ||
1187-
!gid_valid(i_gid_into_mnt(mnt_userns, inode)))
1186+
if (!vfsuid_valid(i_uid_into_vfsuid(mnt_userns, inode)) ||
1187+
!vfsgid_valid(i_gid_into_vfsgid(mnt_userns, inode)))
11881188
return -EOVERFLOW;
11891189

11901190
if (!sysctl_protected_hardlinks)
@@ -1232,13 +1232,13 @@ static int may_create_in_sticky(struct user_namespace *mnt_userns,
12321232
struct nameidata *nd, struct inode *const inode)
12331233
{
12341234
umode_t dir_mode = nd->dir_mode;
1235-
kuid_t dir_uid = nd->dir_uid;
1235+
vfsuid_t dir_vfsuid = nd->dir_vfsuid;
12361236

12371237
if ((!sysctl_protected_fifos && S_ISFIFO(inode->i_mode)) ||
12381238
(!sysctl_protected_regular && S_ISREG(inode->i_mode)) ||
12391239
likely(!(dir_mode & S_ISVTX)) ||
1240-
uid_eq(i_uid_into_mnt(mnt_userns, inode), dir_uid) ||
1241-
uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode)))
1240+
vfsuid_eq(i_uid_into_vfsuid(mnt_userns, inode), dir_vfsuid) ||
1241+
vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), current_fsuid()))
12421242
return 0;
12431243

12441244
if (likely(dir_mode & 0002) ||
@@ -2307,7 +2307,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
23072307
OK:
23082308
/* pathname or trailing symlink, done */
23092309
if (!depth) {
2310-
nd->dir_uid = i_uid_into_mnt(mnt_userns, nd->inode);
2310+
nd->dir_vfsuid = i_uid_into_vfsuid(mnt_userns, nd->inode);
23112311
nd->dir_mode = nd->inode->i_mode;
23122312
nd->flags &= ~LOOKUP_PARENT;
23132313
return 0;
@@ -2885,9 +2885,9 @@ int __check_sticky(struct user_namespace *mnt_userns, struct inode *dir,
28852885
{
28862886
kuid_t fsuid = current_fsuid();
28872887

2888-
if (uid_eq(i_uid_into_mnt(mnt_userns, inode), fsuid))
2888+
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), fsuid))
28892889
return 0;
2890-
if (uid_eq(i_uid_into_mnt(mnt_userns, dir), fsuid))
2890+
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, dir), fsuid))
28912891
return 0;
28922892
return !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FOWNER);
28932893
}
@@ -2926,8 +2926,8 @@ static int may_delete(struct user_namespace *mnt_userns, struct inode *dir,
29262926
BUG_ON(victim->d_parent->d_inode != dir);
29272927

29282928
/* Inode writeback is not safe when the uid or gid are invalid. */
2929-
if (!uid_valid(i_uid_into_mnt(mnt_userns, inode)) ||
2930-
!gid_valid(i_gid_into_mnt(mnt_userns, inode)))
2929+
if (!vfsuid_valid(i_uid_into_vfsuid(mnt_userns, inode)) ||
2930+
!vfsgid_valid(i_gid_into_vfsgid(mnt_userns, inode)))
29312931
return -EOVERFLOW;
29322932

29332933
audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE);

fs/overlayfs/util.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,13 +1104,18 @@ void ovl_copyattr(struct inode *inode)
11041104
struct path realpath;
11051105
struct inode *realinode;
11061106
struct user_namespace *real_mnt_userns;
1107+
vfsuid_t vfsuid;
1108+
vfsgid_t vfsgid;
11071109

11081110
ovl_i_path_real(inode, &realpath);
11091111
realinode = d_inode(realpath.dentry);
11101112
real_mnt_userns = mnt_user_ns(realpath.mnt);
11111113

1112-
inode->i_uid = i_uid_into_mnt(real_mnt_userns, realinode);
1113-
inode->i_gid = i_gid_into_mnt(real_mnt_userns, realinode);
1114+
vfsuid = i_uid_into_vfsuid(real_mnt_userns, realinode);
1115+
vfsgid = i_gid_into_vfsgid(real_mnt_userns, realinode);
1116+
1117+
inode->i_uid = vfsuid_into_kuid(vfsuid);
1118+
inode->i_gid = vfsgid_into_kgid(vfsgid);
11141119
inode->i_mode = realinode->i_mode;
11151120
inode->i_atime = realinode->i_atime;
11161121
inode->i_mtime = realinode->i_mtime;

fs/remap_range.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ static bool allow_file_dedupe(struct file *file)
429429
return true;
430430
if (file->f_mode & FMODE_WRITE)
431431
return true;
432-
if (uid_eq(current_fsuid(), i_uid_into_mnt(mnt_userns, inode)))
432+
if (vfsuid_eq_kuid(i_uid_into_vfsuid(mnt_userns, inode), current_fsuid()))
433433
return true;
434434
if (!inode_permission(mnt_userns, inode, MAY_WRITE))
435435
return true;

fs/stat.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
void generic_fillattr(struct user_namespace *mnt_userns, struct inode *inode,
4545
struct kstat *stat)
4646
{
47+
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
48+
vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
49+
4750
stat->dev = inode->i_sb->s_dev;
4851
stat->ino = inode->i_ino;
4952
stat->mode = inode->i_mode;
5053
stat->nlink = inode->i_nlink;
51-
stat->uid = i_uid_into_mnt(mnt_userns, inode);
52-
stat->gid = i_gid_into_mnt(mnt_userns, inode);
54+
stat->uid = vfsuid_into_kuid(vfsuid);
55+
stat->gid = vfsgid_into_kgid(vfsgid);
5356
stat->rdev = inode->i_rdev;
5457
stat->size = i_size_read(inode);
5558
stat->atime = inode->i_atime;

include/linux/fs.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,23 +1631,6 @@ static inline void i_gid_write(struct inode *inode, gid_t gid)
16311631
inode->i_gid = make_kgid(i_user_ns(inode), gid);
16321632
}
16331633

1634-
/**
1635-
* i_uid_into_mnt - map an inode's i_uid down into a mnt_userns
1636-
* @mnt_userns: user namespace of the mount the inode was found from
1637-
* @inode: inode to map
1638-
*
1639-
* Note, this will eventually be removed completely in favor of the type-safe
1640-
* i_uid_into_vfsuid().
1641-
*
1642-
* Return: the inode's i_uid mapped down according to @mnt_userns.
1643-
* If the inode's i_uid has no mapping INVALID_UID is returned.
1644-
*/
1645-
static inline kuid_t i_uid_into_mnt(struct user_namespace *mnt_userns,
1646-
const struct inode *inode)
1647-
{
1648-
return AS_KUIDT(make_vfsuid(mnt_userns, i_user_ns(inode), inode->i_uid));
1649-
}
1650-
16511634
/**
16521635
* i_uid_into_vfsuid - map an inode's i_uid down into a mnt_userns
16531636
* @mnt_userns: user namespace of the mount the inode was found from
@@ -1700,23 +1683,6 @@ static inline void i_uid_update(struct user_namespace *mnt_userns,
17001683
attr->ia_vfsuid);
17011684
}
17021685

1703-
/**
1704-
* i_gid_into_mnt - map an inode's i_gid down into a mnt_userns
1705-
* @mnt_userns: user namespace of the mount the inode was found from
1706-
* @inode: inode to map
1707-
*
1708-
* Note, this will eventually be removed completely in favor of the type-safe
1709-
* i_gid_into_vfsgid().
1710-
*
1711-
* Return: the inode's i_gid mapped down according to @mnt_userns.
1712-
* If the inode's i_gid has no mapping INVALID_GID is returned.
1713-
*/
1714-
static inline kgid_t i_gid_into_mnt(struct user_namespace *mnt_userns,
1715-
const struct inode *inode)
1716-
{
1717-
return AS_KGIDT(make_vfsgid(mnt_userns, i_user_ns(inode), inode->i_gid));
1718-
}
1719-
17201686
/**
17211687
* i_gid_into_vfsgid - map an inode's i_gid down into a mnt_userns
17221688
* @mnt_userns: user namespace of the mount the inode was found from

0 commit comments

Comments
 (0)