fs: add a new SB_NOUMASK flag
Subsystems (3)
Jeff Layton
maintainerPATCH v2 1/1 fs: add a new SB_NOUMASK flag
SB_POSIXACL must be set when a filesystem supports POSIX ACLs, but NFSv4 also sets this flag to prevent the VFS from applying the umask on newly-created files. NFSv4 doesn't support POSIX ACLs however, which causes confusion when other subsystems try to test for them.
Split the umask-stripping opt-out into a separate SB_NOUMASK flag, and have NFSv4 set that instead of SB_POSIXACL. Fix the appropriate places in the VFS to check for that flag (in addition to SB_POSIXACL) when stripping the umask.
---
Yet another approach to fixing this issue. I think this way is probably the best, since makes the purpose of these flags clearer, and stops NFS from relying on SB_POSIXACL to avoid umask stripping.
---
Changes in v2:
- new approach: add a new SB_NOUMASK flag that NFSv4 can use instead of SB_POSIXACL
- Link to v1: https://lore.kernel.org/r/[email protected]
--- fs/init.c | 4 ++-- fs/namei.c | 2 +- fs/nfs/super.c | 2 +- include/linux/fs.h | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-)
fs/init.c +2 -2
@@ -153,7 +153,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_NOUMASK (path.dentry->d_inode)) mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (!error)
@@ -229,7 +229,7 @@ int __init init_mkdir(const char *pathname, umode_t mode) dentry =kern_path_create (AT_FDCWD , pathname, &path,LOOKUP_DIRECTORY );if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_NOUMASK (path.dentry->d_inode)) mode &= ~current_umask (); error =security_path_mkdir (&path, dentry, mode);if (!error)
fs/namei.c +1 -1
@@ -3117,7 +3117,7 @@ EXPORT_SYMBOL(unlock_rename);*/ static inline umode_t mode_strip_umask (const struct inode *dir,umode_t mode) { -if (!IS_POSIXACL (dir)) +if (!IS_NOUMASK (dir)) mode &= ~current_umask ();return mode; }
fs/nfs/super.c +1 -1
@@ -1071,7 +1071,7 @@ static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx) sb->s_export_op = &nfs_export_ops;break ;case 4 : - sb->s_flags |=SB_POSIXACL ; + sb->s_flags |=SB_NOUMASK ; sb->s_time_gran =1 ; sb->s_time_min =S64_MIN ; sb->s_time_max =S64_MAX ;
include/linux/fs.h +3 -1
@@ -1119,13 +1119,14 @@ extern int send_sigurg(struct fown_struct *fown);#define SB_NOATIME BIT(10)/* Do not update access times. */ #define SB_NODIRATIME BIT(11)/* Do not update directory access times */ #define SB_SILENT BIT(15) -#define SB_POSIXACL BIT(16)/* VFS does not apply the umask */ +#define SB_POSIXACL BIT(16)/* POSIX ACLs are supported (implies NOUMASK) */ #define SB_INLINECRYPT BIT(17)/* Use blk-crypto for encrypted files */ #define SB_KERNMOUNT BIT(22)/* this is a kern_mount call */ #define SB_I_VERSION BIT(23)/* Update inode I_version field */ #define SB_LAZYTIME BIT(25)/* Update the on-disk [acm]times lazily */ /* These sb flags are internal to the kernel */ +#define SB_NOUMASK BIT(20)/* VFS does not apply the umask */ #define SB_DEAD BIT(21)#define SB_DYING BIT(24)#define SB_SUBMOUNT BIT(26)
@@ -2111,6 +2112,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags#define IS_APPEND (inode) ((inode)->i_flags & S_APPEND)#define IS_IMMUTABLE (inode) ((inode)->i_flags & S_IMMUTABLE)#define IS_POSIXACL (inode) __IS_FLG(inode, SB_POSIXACL) +#define IS_NOUMASK (inode) __IS_FLG(inode, SB_POSIXACL|SB_NOUMASK)#define IS_DEADDIR (inode) ((inode)->i_flags & S_DEAD)#define IS_NOCMTIME (inode) ((inode)->i_flags & S_NOCMTIME)
---
base-commit: a48fa7efaf1161c1c898931fe4c7f0070964233a
change-id: 20230908-acl-fix-6f8f86930f32
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerQuoted 9 lines · Jeff Layton
SB_POSIXACLmust be set when a filesystem supports POSIX ACLs, but NFSv4 also sets this flag to prevent the VFS from applying the umask on newly-created files. NFSv4 doesn't support POSIX ACLs however, which causes confusion when other subsystems try to test for them.Split the umask-stripping opt-out into a separate
SB_NOUMASKflag, and have NFSv4 set that instead ofSB_POSIXACL. Fix the appropriate places in the VFS to check for that flag (in addition toSB_POSIXACL) when stripping the umask.
Oh, I see you only raised SB_POSIXACL to avoid umask stripping. That's a bit weird indeed. Hm, since this is an internal, non-user changeable flag I think it might be better in s_iflags as SB_I_NOUMASK? Also allows us to avoid wasting an s_flags bit.
Quoted 32 lines
Signed-off-by Jeff Layton <[email protected]>---
Yet another approach to fixing this issue. I think this way is probably the best, since makes the purpose of these flags clearer, and stops NFS from relying onSB_POSIXACLto avoid umask stripping.
---
Changes in v2:
- new approach: add a newSB_NOUMASKflag that NFSv4 can use instead ofSB_POSIXACL
- Link to v1: https://lore.kernel.org/r/[email protected]--- fs/init.c | 4 ++-- fs/namei.c | 2 +- fs/nfs/super.c | 2 +- include/linux/fs.h | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-)fs/init.c +1
-1@@ -153,7 +153,7 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev)if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_NOUMASK (path.dentry->d_inode)) mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (!error)
fs/init.c int __init init_mkdir(const char *pathname, umode_t mode) · line 233
Quoted 6 lines
fs/init.c +1
-1@@ -229,7 +229,7 @@ int __init init_mkdir(const char *pathname, umode_t mode) dentry =kern_path_create (AT_FDCWD , pathname, &path,LOOKUP_DIRECTORY );if (IS_ERR (dentry))return PTR_ERR (dentry); -if (!IS_POSIXACL (path.dentry->d_inode)) +if (!IS_NOUMASK (path.dentry->d_inode)) mode &= ~current_umask ();
Could you please just convert them over to mode_strip_umask()? Seems I forgot these two places back then.