Skip to contentSkip to conversation

ext4: Don't reduce symlink i_mode by umask if no ACL support

PATCH Superseded David Howells 4 participants 6 messages May 9, 2024 – May 10, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Don't reduce symlink i_mode by umask if no ACL support

If CONFIG_EXT4_FS_POSIX_ACL=n then the fallback version of ext4_init_acl() will mask off the umask bits from the new inode's i_mode. This should not be done if the inode is a symlink. If CONFIG_EXT4_FS_POSIX_ACL=y, then we go through posix_acl_create() instead which does the right thing with symlinks.

Fix this by making the fallback version of ext4_init_acl() do nothing if inode is a symlink.

Fixes 484fd6c1de13 ("ext4: apply umask if ACL support is disabled")
---
 fs/ext4/acl.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/acl.h +2 -1
index ef4c19e5f570..566625286442 100644
@@ -71,7 +71,8 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
 	/* usually, the umask is applied by posix_acl_create(), but if
 	   ext4 ACL support is disabled at compile time, we need to do
 	   it here, because posix_acl_create() will never be called */
-	inode->i_mode &= ~current_umask();
+	if (!S_ISLNK(inode->i_mode))
+		inode->i_mode &= ~current_umask();
 
 	return 0;
 }
#1 lore raw

fs/ext4/acl.h ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) · line 75

Quoted 11 lines · David Howells
fs/ext4/acl.h +2 -1
index ef4c19e5f570..566625286442 100644
@@ -71,7 +71,8 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
        /* usually, the umask is applied by posix_acl_create(), but if
           ext4 ACL support is disabled at compile time, we need to do
           it here, because posix_acl_create() will never be called */
-       inode->i_mode &= ~current_umask();
+       if (!S_ISLNK(inode->i_mode))
+               inode->i_mode &= ~current_umask();

I think this should just be removed unconditionally, since the VFS now takes care of mode masking in vfs_prepare_mode().

Thanks,
Miklos

#2 lore raw
Quoted 2 lines · Miklos Szeredi

I think this should just be removed unconditionally, since the VFS now takes care of mode masking in vfs_prepare_mode().

That works for symlinks because the symlink path doesn't call it?

David

#3 lore raw
Quoted 7 lines · David Howells
Quoted 2 lines · Miklos Szeredi

I think this should just be removed unconditionally, since the VFS now takes care of mode masking in vfs_prepare_mode().

That works for symlinks because the symlink path doesn't call it?

Yep.

Thanks,
Miklos

#4 lore raw
In reply to David Howells
Quoted 6 lines · David Howells
Quoted 2 lines · Miklos Szeredi

I think this should just be removed unconditionally, since the VFS now takes care of mode masking in vfs_prepare_mode().

That works for symlinks because the symlink path doesn't call it?

All of the mode handling should now be done correctly in the VFS (see Miklos reply as well). In general the less fs specific mode handling we have, the better because we've been bitten by this before.

maintainer Reviewed-by Christian Brauner Tested-by Michael Forney
#5 lore raw
In reply to Miklos Szeredi
Quoted 16 lines · Miklos Szeredi

fs/ext4/acl.h ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir) · line 75

Quoted 11 lines · David Howells
fs/ext4/acl.h +2 -1
index ef4c19e5f570..566625286442 100644
@@ -71,7 +71,8 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
        /* usually, the umask is applied by posix_acl_create(), but if
           ext4 ACL support is disabled at compile time, we need to do
           it here, because posix_acl_create() will never be called */
-       inode->i_mode &= ~current_umask();
+       if (!S_ISLNK(inode->i_mode))
+               inode->i_mode &= ~current_umask();

I think this should just be removed unconditionally, since the VFS now takes care of mode masking in vfs_prepare_mode().

The following is in the ext4 tree:

commit c77194965dd0dcc26f9c1671d2e74e4eb1248af5

Author: Max Kellermann <[email protected]>
Date:   Fri Mar 15 15:29:56 2024 +0100

Revert "ext4: apply umask if ACL support is disabled"

This reverts commit 484fd6c1de13b336806a967908a927cc0356e312. The commit caused a regression because now the umask was applied to symlinks and the fix is unnecessary because the umask/O_TMPFILE bug has been fixed somewhere else already.