exfat: attr: handle idmapped mounts

When file attributes are changed most filesystems rely on the
setattr_prepare(), setattr_copy(), and notify_change() helpers for
initialization and permission checking. Let them handle idmapped mounts.
If the inode is accessed through an idmapped mount map it into the
mount's user namespace. Afterwards the checks are identical to
non-idmapped mounts. If the initial user namespace is passed nothing
changes so non-idmapped mounts will see identical behavior as before.

Helpers that perform checks on the ia_uid and ia_gid fields in struct
iattr assume that ia_uid and ia_gid are intended values and have already
been mapped correctly at the userspace-kernelspace boundary as we
already do today. If the initial user namespace is passed nothing
changes so non-idmapped mounts will see identical behavior as before.

Link: https://lore.kernel.org/r/20210121131959.646623-8-christian.brauner@ubuntu.com
Cc: Christoph Hellwig <hch@lst.de>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
This commit is contained in:
Namjae Jeon 2021-03-24 11:57:43 +09:00
parent 4728c613cf
commit df7fdcfcbf

8
file.c
View File

@ -344,7 +344,11 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
#if ((LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)) && \
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 37))) || \
(LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
error = setattr_prepare(&init_user_ns, dentry, attr);
#else
error = setattr_prepare(dentry, attr);
#endif
#else
error = inode_change_ok(inode, attr);
#endif
@ -382,7 +386,11 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)
up_write(&EXFAT_I(inode)->truncate_lock);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
setattr_copy(&init_user_ns, inode, attr);
#else
setattr_copy(inode, attr);
#endif
exfat_truncate_atime(&inode->i_atime);
mark_inode_dirty(inode);