From ddc275ccb4e32078f2a2e267ee6d5df9b740de63 Mon Sep 17 00:00:00 2001 From: Namjae Jeon Date: Wed, 24 Mar 2021 12:07:41 +0900 Subject: [PATCH] exfat: fs: make helpers idmap mount aware Extend some inode methods with an additional user namespace argument. A filesystem that is aware of idmapped mounts will receive the user namespace the mount has been marked with. This can be used for additional permission checking and also to enable filesystems to translate between uids and gids if they need to. We have implemented all relevant helpers in earlier patches. As requested we simply extend the exisiting inode method instead of introducing new ones. This is a little more code churn but it's mostly mechanical and doesnt't leave us with additional inode methods. Link: https://lore.kernel.org/r/20210121131959.646623-25-christian.brauner@ubuntu.com Cc: Christoph Hellwig Cc: David Howells Cc: Al Viro Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner Signed-off-by: Namjae Jeon --- exfat_fs.h | 9 +++++++++ file.c | 12 +++++++++++- namei.c | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/exfat_fs.h b/exfat_fs.h index f38a061e082b..e4b3a933c79b 100644 --- a/exfat_fs.h +++ b/exfat_fs.h @@ -431,6 +431,14 @@ int exfat_trim_fs(struct inode *inode, struct fstrim_range *range); extern const struct file_operations exfat_file_operations; int __exfat_truncate(struct inode *inode, loff_t new_size); void exfat_truncate(struct inode *inode, loff_t size); + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, + struct iattr *attr); +int exfat_getattr(struct user_namespace *mnt_userns, const struct path *path, + struct kstat *stat, unsigned int request_mask, + unsigned int query_flags); +#else int exfat_setattr(struct dentry *dentry, struct iattr *attr); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) int exfat_getattr(const struct path *path, struct kstat *stat, @@ -439,6 +447,7 @@ int exfat_getattr(const struct path *path, struct kstat *stat, int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat); #endif +#endif int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync); long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long exfat_compat_ioctl(struct file *filp, unsigned int cmd, diff --git a/file.c b/file.c index 4ddd911f3c9e..1a4ffb0358b3 100644 --- a/file.c +++ b/file.c @@ -291,6 +291,11 @@ write_size: mutex_unlock(&sbi->s_lock); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +int exfat_getattr(struct user_namespace *mnt_uerns, const struct path *path, + struct kstat *stat, unsigned int request_mask, + unsigned int query_flags) +#else #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) int exfat_getattr(const struct path *path, struct kstat *stat, unsigned int request_mask, unsigned int query_flags) @@ -298,7 +303,7 @@ int exfat_getattr(const struct path *path, struct kstat *stat, int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) #endif - +#endif { #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) struct inode *inode = d_backing_inode(path->dentry); @@ -322,7 +327,12 @@ int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, return 0; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +int exfat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, + struct iattr *attr) +#else int exfat_setattr(struct dentry *dentry, struct iattr *attr) +#endif { struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb); struct inode *inode = dentry->d_inode; diff --git a/namei.c b/namei.c index a68e56ecd644..ecbfd52194f2 100644 --- a/namei.c +++ b/namei.c @@ -568,8 +568,13 @@ out: return ret; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +static int exfat_create(struct user_namespace *mnt_userns, struct inode *dir, + struct dentry *dentry, umode_t mode, bool excl) +#else static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) +#endif { struct super_block *sb = dir->i_sb; struct inode *inode; @@ -900,7 +905,12 @@ unlock: return err; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +static int exfat_mkdir(struct user_namespace *mnt_userns, struct inode *dir, + struct dentry *dentry, umode_t mode) +#else static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) +#endif { struct super_block *sb = dir->i_sb; struct inode *inode; @@ -1425,6 +1435,12 @@ out: return ret; } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0) +static int exfat_rename(struct user_namespace *mnt_userns, + struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) +#else #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, @@ -1433,6 +1449,7 @@ static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) #endif +#endif { struct inode *old_inode, *new_inode; struct super_block *sb = old_dir->i_sb;