Skip to content

Commit

Permalink
exfat: handle idmapped mounts
Browse files Browse the repository at this point in the history
Pass the idmapped mount information to the different helper
functions. Adapt the uid/gid checks in exfat_setattr to use the
vfsuid/vfsgid helpers.

Based on the fat implementation in commit 4b7899368108
("fat: handle idmapped mounts") by Christian Brauner.

Signed-off-by: Michael Jeanson <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
mjeanson authored and namjaejeon committed Aug 7, 2024
1 parent 05b27be commit c8781ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ static int exfat_cont_expand(struct inode *inode, loff_t size)
return -EIO;
}

static bool exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode)
static bool exfat_allow_set_time(struct mnt_idmap *idmap,
struct exfat_sb_info *sbi, struct inode *inode)
{
mode_t allow_utime = sbi->options.allow_utime;

if (!uid_eq(current_fsuid(), inode->i_uid)) {
if (in_group_p(inode->i_gid))
if (!vfsuid_eq_kuid(i_uid_into_vfsuid(idmap, inode),
current_fsuid())) {
if (vfsgid_in_group_p(i_gid_into_vfsgid(idmap, inode)))
allow_utime >>= 3;
if (allow_utime & MAY_WRITE)
return true;
Expand Down Expand Up @@ -301,7 +303,7 @@ int exfat_getattr(struct user_namespace *mnt_uerns, const struct path *path,

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
generic_fillattr(idmap, request_mask, inode, stat);
#else
generic_fillattr(&nop_mnt_idmap, inode, stat);
#endif
Expand Down Expand Up @@ -340,13 +342,13 @@ int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
/* Check for setting the inode time. */
ia_valid = attr->ia_valid;
if ((ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)) &&
exfat_allow_set_time(sbi, inode)) {
exfat_allow_set_time(idmap, sbi, inode)) {
attr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET |
ATTR_TIMES_SET);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
error = setattr_prepare(&nop_mnt_idmap, dentry, attr);
error = setattr_prepare(idmap, dentry, attr);
#else
error = setattr_prepare(&init_user_ns, dentry, attr);
#endif
Expand All @@ -355,9 +357,11 @@ int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
goto out;

if (((attr->ia_valid & ATTR_UID) &&
!uid_eq(attr->ia_uid, sbi->options.fs_uid)) ||
(!uid_eq(from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid),
sbi->options.fs_uid))) ||
((attr->ia_valid & ATTR_GID) &&
!gid_eq(attr->ia_gid, sbi->options.fs_gid)) ||
(!gid_eq(from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid),
sbi->options.fs_gid))) ||
((attr->ia_valid & ATTR_MODE) &&
(attr->ia_mode & ~(S_IFREG | S_IFLNK | S_IFDIR | 0777)))) {
error = -EPERM;
Expand Down Expand Up @@ -385,7 +389,7 @@ int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
setattr_copy(&nop_mnt_idmap, inode, attr);
setattr_copy(idmap, inode, attr);
exfat_truncate_inode_atime(inode);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
Expand Down
2 changes: 1 addition & 1 deletion super.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ static struct file_system_type exfat_fs_type = {
.init_fs_context = exfat_init_fs_context,
.parameters = exfat_parameters,
.kill_sb = exfat_kill_sb,
.fs_flags = FS_REQUIRES_DEV,
.fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
};

static void exfat_inode_init_once(void *foo)
Expand Down

0 comments on commit c8781ac

Please sign in to comment.