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
open14 and openat03 failed with wrong file mode #118
Comments
Or another way can be calculate the permission before creating the file but this case, I don't think numbers in test_perms[] still make sense as before (it masked). |
What LTP version/arch/kernel/distro/glibc/filesystem are you using? On first look, my guess is your kernel doesn't respect umask for O_TMPFILE. From man page:
Can you compile/run following and provide output? (With your default umask)
There was a glibc bug related to O_TMPFILE, that made these 2 tests fail as well, but I think the symptoms were a little different: |
Hi @jstancek I'm testing with armv7l (32bits), just fetching LTP several days ago, so I believe it almost latest.
The output from your code
(-L option is not support on my machine, so I changed it)
|
It was only for purposes of having simpler reproducer. Where is your TMPDIR set to? Does it define any ACLs (check getfacl)? Other than that I suspect your kernel doesn't honor umask for O_TMPFILE.
|
Hi @jstancek Yes, I also put logs everywhere and found the the issue appear after tst_tmpdir is provoked.
Export TMPDIR to another location before running this test can help to pass, but actually it's not a suitable solution for me, because my testing system is read-only system, I'd better not running rwrfs on it. Still wonder is there any way can be improved from LTP testcases side ? |
Your output does not list any default ACLs. Can you provide also output of "df -T"? I'm curious about file system types of /home and /tmp. |
Hi, For your information, df -T output
One more observation, /tmp is actually linked to /var/volatile/tmp, and "sticky bit" is set on this folder. I just know this bit help files in this directory can only be renamed or deleted by the user that owns them (and root), I'm not sure if it has any affects to file permission ?
|
Hi @jstancek , I tried with several values of test_perms[] and seems that umask actually did not work for any values. From the original values Did this testcase passed on your system ( I looked around and this not find any LTP reports that have this case) ? I tried with another machine and 07777 is still failed (get 1755 but expect 7755). I guess the permission of O_TMPFILE created in /tmp is much affected by attribute of /tmp file, and the calculation of exp_mode must included also setuid/setgid/Sticky Bit ? |
It does pass with several kernels (on my x86 KVM guest).
At the moment, I'm suspecting this to be related to tmpfs, rather than /tmp permissions/sticky bit. You can try to set TMPDIR to /root/test and set exact same permission/sticky bit on it (as /tmp currently has) - that is mirror the setup of /tmp for all details except for file system type. |
Hi @jstancek, Yes, it's more related on tmpfs than the other ones. Although the last result on another machine (which "get 1755 but expect 7755") the /tmp is on the hard disk, not the tmpfs, but we can temporary abort it. I can pass when pointing TMPDIR to another folder (but need "rwrfs" in advance)
|
I'm not suggesting you do that permanently. Based on your data so far, behaviour is not the same for ext4 vs. tmpfs, so I'd start looking into potential kernel bug. I'd run the failing test via strace, and double-check syscall parameters. |
Hi @jstancek , I did not chance to try with latest upstream kernel. (
|
Hi @jstancek , I read this again, I think the phenomenon somehow like in "Comment 5". open() may have the issue with tmpfs when creating the fd with wrong permission. Workaround with fchmod (fchmod(fd[i], perm & ~mask);) right after the open() helped to move the testcase to correct direction
Not much meaning when I added fchmod like this, but at least we can narrow it to open() method, other parts seems ok, so issue with "glibc" ? |
I still suspect your kernel and tmpfs as it worked fine on other filesystems. If you want to rule out glibc involvement, you can replace open() with syscall(NR_open, ...). |
:( Yes, I tried with syscall and the testcase still fail as before
Maybe as you said, issue seems from our kernel, I may contact our kernel dev team to check more with them. Thanks a lot for taking time to help me. |
CONFIG_TMPFS_POSIX_ACL option needs to be enabled in defconfig. Otherwise the umask is not applied when a new inode is created using shmem_tmpfile call. |
Hi,
I had both testcases open14 and openat03 failed with same errors
openat03 0 TINFO : and check file permissions
openat03 3 TFAIL : openat03.c:223: file mode read 7777, but expected 7755
Looking a little deeper into the code, the issue may come from these lines
In the beginning, the writer may intend to create files and test with each value in test_perms[].
But the "exp_mode" is calculated based on "perm" and "mask", so to keep it with initial value, umask should be set to 0 before calculate "mask" variable ?
(mode_t mask = umask(0) just returns the previous value of the file creation mask, in my machine, it's default 0022)
Tried with this way and it can run normally
or put this line here in the code also can help (with any default umask value)
Should it be fine with this approach ?
The text was updated successfully, but these errors were encountered: