-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't fail to apply umask for O_TMPFILE files #8998
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8998 +/- ##
==========================================
- Coverage 79.52% 79.33% -0.19%
==========================================
Files 418 419 +1
Lines 123544 123586 +42
==========================================
- Hits 98247 98047 -200
- Misses 25297 25539 +242
Continue to review full report at Codecov.
|
module/zfs/zpl_inode.c
Outdated
@@ -231,6 +231,7 @@ zpl_tmpfile(struct inode *dir, struct dentry *dentry, zpl_umode_t mode) | |||
cookie = spl_fstrans_mark(); | |||
error = -zfs_tmpfile(dir, vap, 0, mode, &ip, cr, 0, NULL); | |||
if (error == 0) { | |||
ip->i_mode &= ~current_umask(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, the core issue here is that unlike .create
we can't rely of the VFS apply the umask for .tmpfile
, so we need to handle it ourselves. This fix makes sense but I think we should apply the mask prior to the zpl_vap_init()
call, this should work and is more consistent with all other callers. How about something like this (untested).
/*
* The VFS does not apply the umask to the provided mode.
* Therefore, it must be applied at the filesystem layer.
*/
mode &= ~current_umask();
zpl_vap_init(vap, dir, mode, cr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, the core issue here is that unlike .create we can't rely of the VFS apply the umask for .tmpfile, so we need to handle it ourselves.
yes, and even if VFS supports it at some point, I don't think this change (mode &= ~umask
) will bother that.
This fix makes sense but I think we should apply the mask prior to the zpl_vap_init() call, this should work and is more consistent with all other callers. How about something like this (untested).
ok, that might be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated + rebased + tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test case under functional/tmpfile
.
944b19f
to
0782977
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the test case.
module/zfs/zpl_inode.c
Outdated
@@ -226,6 +226,11 @@ zpl_tmpfile(struct inode *dir, struct dentry *dentry, zpl_umode_t mode) | |||
|
|||
crhold(cr); | |||
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); | |||
/* | |||
* The VFS does not apply the umask to the provided mode as of 5.2. | |||
* Therefore, it must be applied at the filesystem layer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this really a change in the 5.2 kernel, or does it predate it? That shouldn't matter for the fix itself, but I'm curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has nothing to do with version 5.2, this bug is a lot older, and may even be older than O_TMPFILE
itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. the rest of the Linux kernel applies the umask only if there's no ACL, e.g.:
https://github.com/torvalds/linux/blob/v5.2/fs/posix_acl.c#L596-L597
https://github.com/torvalds/linux/blob/v5.2/fs/namei.c#L3176-L3177
This PR applies it unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this really a change in the 5.2 kernel, or does it predate it?
I meant to say it has been there and still not supported by VFS in 5.2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out that the kernel only applies this when there is no ACL. @kusumi what do you think about the follow modification.
index 3f3b2e2..9854791 100644
--- a/module/zfs/zpl_inode.c
+++ b/module/zfs/zpl_inode.c
@@ -226,6 +226,15 @@ zpl_tmpfile(struct inode *dir, struct dentry *dentry, zpl_u
crhold(cr);
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
+ /*
+ * The VFS does not apply the umask, therefore it is applied here
+ * when POSIX ACLs are not enabled.
+ */
+ if (!IS_POSIXACL(dir->d_inode))
+ mode &= ~current_umask();
+
zpl_vap_init(vap, dir, mode, cr);
cookie = spl_fstrans_mark();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I guess we also want to change ip->i_mode &= ~current_umask();
in zpl_init_acl()
side too ? It sounds like ZoL was doing opposite of what VFS expects.
zfs seems to be ignoring umask if files created with O_TMPFILE unless acltype=posixacl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check my diff and Linux VFS code again soon. If needed I'll make the change and rebase again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied !IS_POSIXACL()
conditional + rebased.
If you can rebase this on master, I can take a look at it. |
Thanks, I will in next week or so. |
Rebased. Haven't ran |
Apply umask to `mode` which will eventually be applied to inode. This is needed since VFS doesn't apply umask for O_TMPFILE files. (Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();` only when POSIX ACL is used.) Signed-off-by: Tomohiro Kusumi <[email protected]>
@behlendorf Looks like tests are seeing ENOSPC this time, whereas in previous rebase on Nov 28 tests went fine IIRC. |
@kusumi probably a CI related hiccup, I've resubmitted the those builds. |
@behlendorf Thanks. Looks to me this is ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this, looks good. @tonyhutter can you please take a look at this too.
Apply umask to `mode` which will eventually be applied to inode. This is needed since VFS doesn't apply umask for O_TMPFILE files. (Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();` only when POSIX ACL is used.) Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Tomohiro Kusumi <[email protected]> Closes openzfs#8997 Closes openzfs#8998
Apply umask to `mode` which will eventually be applied to inode. This is needed since VFS doesn't apply umask for O_TMPFILE files. (Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();` only when POSIX ACL is used.) Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Tomohiro Kusumi <[email protected]> Closes openzfs#8997 Closes openzfs#8998
Apply umask to `mode` which will eventually be applied to inode. This is needed since VFS doesn't apply umask for O_TMPFILE files. (Note that zpl_init_acl() applies `ip->i_mode &= ~current_umask();` only when POSIX ACL is used.) Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Tomohiro Kusumi <[email protected]> Closes #8997 Closes #8998
Motivation and Context
#8997
Description
Apply umask to
mode
which will eventually be applied to inode.This is needed since VFS doesn't apply umask for O_TMPFILE files.
(Note that zpl_init_acl() applies
ip->i_mode &= ~current_umask();
only when POSIX ACL is used.)
How Has This Been Tested?
With the code pasted in #8997.
Types of changes
Checklist:
Signed-off-by
.