Skip to content
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

Merged
merged 1 commit into from
Dec 13, 2019
Merged

Conversation

kusumi
Copy link
Member

@kusumi kusumi commented Jul 7, 2019

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.

# gcc -Wall -g ./tmpfile1.c
# zpool create p1 sdb
# cd /p1
# ~/a.out
current umask = 022
fstat(): in_mode=0777, resulting_mode=0100755
stat():  in_mode=0777, resulting_mode=0100755
current umask = 077
fstat(): in_mode=0777, resulting_mode=0100700
stat():  in_mode=0777, resulting_mode=0100700

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@codecov
Copy link

codecov bot commented Jul 7, 2019

Codecov Report

Merging #8998 into master will decrease coverage by 0.18%.
The diff coverage is 4.76%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#kernel 80.02% <100%> (-0.13%) ⬇️
#user 66.98% <0%> (-0.4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e69bb31...bb1daae. Read the comment docs.

@@ -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();
Copy link
Contributor

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);

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated + rebased + tested.

Copy link
Member Author

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.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jul 8, 2019
@kusumi kusumi changed the title Don't fail to umask for O_TMPFILE files Don't fail to apply umask for O_TMPFILE files Jul 9, 2019
@kusumi kusumi force-pushed the acl1 branch 4 times, most recently from 944b19f to 0782977 Compare July 9, 2019 16:13
Copy link
Contributor

@behlendorf behlendorf left a 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.

@@ -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.
Copy link
Contributor

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.

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.

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.

Copy link
Member Author

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.

Copy link
Contributor

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();

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Member Author

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.

@tonyhutter
Copy link
Contributor

If you can rebase this on master, I can take a look at it.

@kusumi
Copy link
Member Author

kusumi commented Oct 26, 2019

Thanks, I will in next week or so.

@behlendorf behlendorf added the Status: Revision Needed Changes are required for the PR to be accepted label Nov 13, 2019
@kusumi
Copy link
Member Author

kusumi commented Nov 27, 2019

Rebased. Haven't ran tests/zfs-tests/tests/functional/tmpfile/tmpfile_stat_mode.c on my local after rebase, but let's see how it goes.

@behlendorf behlendorf removed the Status: Revision Needed Changes are required for the PR to be accepted label Nov 28, 2019
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]>
@kusumi
Copy link
Member Author

kusumi commented Dec 7, 2019

@behlendorf Looks like tests are seeing ENOSPC this time, whereas in previous rebase on Nov 28 tests went fine IIRC.

@behlendorf
Copy link
Contributor

@kusumi probably a CI related hiccup, I've resubmitted the those builds.

@kusumi
Copy link
Member Author

kusumi commented Dec 8, 2019

@behlendorf Thanks. Looks to me this is ready to merge.

Copy link
Contributor

@behlendorf behlendorf left a 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.

@behlendorf behlendorf merged commit ddb4e69 into openzfs:master Dec 13, 2019
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 26, 2019
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
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 27, 2019
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
tonyhutter pushed a commit that referenced this pull request Jan 23, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants