Closed vamsikrishna935 closed 4 years ago
@prp Could you please help us
@vamsikrishna935 Please use GitHub's markdown code blocks for anything that's code or log output. See also https://guides.github.com/features/mastering-markdown/.
@vamsikrishna935 Please use GitHub's markdown code blocks for anything that's code or log output. See also https://guides.github.com/features/mastering-markdown/.
Thanks @letmaik , modified
@davidchisnall @prp this bug is blocking enabling 9 tests. Can you triage and prioritize this issue please.
What is the issue here?
/tmp
are wrong?nobody
user cannot create directories?root
can create directories?nobody
user does not work?A quick look at the code suggests that the permissions on /tmp
should be 0777 (which is not quite right, /tmp
should have the sticky bit set), so any user should be able to write files there.
What is the issue here?
* That the permissions on `/tmp` are wrong? * That the `nobody` user cannot create directories? * That no user other than `root` can create directories? * That switching to the `nobody` user does not work?
A quick look at the code suggests that the permissions on
/tmp
should be 0777 (which is not quite right,/tmp
should have the sticky bit set), so any user should be able to write files there.
nobody user cannot create directories under /tmp folder, it is failing with EACCESS
@vamsikrishna935, please will you try to explain the cause of this? Repeating the original comment is not helpful. Why is the nobody user unable to create directories under /tmp? The directory is created with permissions 0777, is that still the permission?
@vamsikrishna935, please will you try to explain the cause of this? Repeating the original comment is not helpful. Why is the nobody user unable to create directories under /tmp? The directory is created with permissions 0777, is that still the permission?
@davidchisnall , sorry david, i missed. Yes it is created with 777 permissions.
$TMPBASE is /tmp
# Added -m 777 for tests that call tst_tmpdir() and try to
# write to it as user nobody
mkdir -m 777 -p $TMPBASE || \
{
echo "FATAL: Unable to make temporary directory $TMPBASE"
exit 1
}
I have no idea what that means. Have you confirmed that the /tmp directory has permissions 777? Can another user (not root or nobody) create directories there? Who is the owner of /tmp?
What analysis have you done to attempt to identify the root cause?
@vamsikrishna935 any progress on that? I don't see your answer to David's question.
@prp Please find the below information, let me know if anything else needed.
Failing to create directory under /tmp with non-root user (nobody) Code snippet: Creating temporary directory with nobody user https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/chmod/chmod03.c#L149%20L157
\tmp permissions: Command used: SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=0 ../../build/sgx-lkl-run-oe --hw-debug sgxlkl-miniroot-fs.img /bin/ls -la /tmp
Output: [[ SGX-LKL ]] libc_start_main_stage2(): Calling app main: /bin/ls total 4 drwxrwxrwx 2 root root 0 Jun 30 11:28 . drwx------ 21 root root 4096 Jun 30 11:21 ..
Stack trace:
[[ SGX-LKL ]] libc_start_main_stage2(): Calling app main: /ltp/testcases/kernel/syscalls/chmod/chmod03
[Switching to Thread 0x7fff82ffd700 (LWP 28168)]
Thread 11 "ENCLAVE" hit Breakpoint 1, main (ac=1, av=0x7fff40b5eea0) at chmod03.c:101
101 chmod03.c: No such file or directory.
(gdb) c
Continuing.
[Switching to Thread 0x7fff90f9d700 (LWP 28165)]
Thread 8 "ENCLAVE" hit Breakpoint 2, mkdtemp (template=0x7fff40b5dd00 "/tmp/chmXXXXXX") at src/temp/mkdtemp.c:8
8 size_t l = strlen(template);
(gdb) bt
#0 mkdtemp (template=0x7fff40b5dd00 "/tmp/chmXXXXXX") at src/temp/mkdtemp.c:8
#1 0x00007fff3dac1249 in tst_tmpdir () at tst_tmpdir.c:262
#2 0x00007fff3dabf868 in setup () at chmod03.c:157
#3 0x00007fff3dabf531 in main (ac=<optimized out>, av=<optimized out>) at chmod03.c:108
#4 0x00007fff00538402 in libc_start_main_stage2 (main=0x7fff3dabf500 <main>, argc=1, argv=0x7fff40b5eea0)
at src/env/__libc_start_main.c:168
#5 0x00007fff00538361 in __libc_start_main (main=0x7fff3dabf500 <main>, argc=1, argv=0x7fff40b5eea0)
at src/env/__libc_start_main.c:153
#6 0x00007fff3dabf6c3 in _start_c (p=<optimized out>) at crt/crt1.c:17
#7 0x00007fff3dabf69b in _start ()
#8 0x0000000000000000 in ?? ()
(gdb) c
Continuing.
chmod03 1 TBROK : tst_tmpdir.c:264: tst_tmpdir: mkdtemp(/tmp/chmXXXXXX) failed: errno=EACCES(13): Permission denied
cc @hukoyu
@vamsikrishna935 can you address @davidchisnall's original questions?
Can you write a minimal C program that exhibits the problem?
drwxrwxrwx 2 root root 0 Jun 30 11:28 .
So it looks as if /tmp
is not being mounted with the sticky bit set, but is world writeable? So any user should be able to create files there.
drwxrwxrwx 2 root root 0 Jun 30 11:28 .
So it looks as if
/tmp
is not being mounted with the sticky bit set, but is world writeable? So any user should be able to create files there.
root user is able to create files.
Sample code : for reproducing the bug
#include <signal.h>
#include <pwd.h>
#include "test.h"
#include "safe_macros.h"
char nobody_uid[] = "nobody";
struct passwd *ltpuser;
int main(int ac, char **av)
{
tst_require_root();
ltpuser = getpwnam(nobody_uid);
if (ltpuser == NULL)
tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
SAFE_SETUID(NULL, ltpuser->pw_uid);
TEST_PAUSE;
tst_tmpdir();
}
There is a lot to unpack here that could be broken:
This also fails for user operator
.
perms look like 777 on /tmp
yet I have to be root to not get a EACCES error when I try to stat /tmp.
S_IR S_IW S_IX*
are all set for USR, GRP, OTH when I examine st_mode.
uid: 0 grp: 0 on /tmp
How do you change the user? Are you sure that this is happening correctly?
user nobody with id of 65534 is found.
@prp this is the code and it isn't triggering the failure:
int safe_setuid(const char *file, const int lineno, void (*cleanup_fn) (void),
uid_t uid)
{
int rval;
rval = setuid(uid);
if (rval == -1) {
tst_brkm(TBROK | TERRNO, cleanup_fn,
"%s:%d: setuid(%u) failed",
file, lineno, (unsigned) uid);
}
return rval;
}
The tests pass if you set "/" to 777. currently, it is set to 700.
What are the permissions on the /tmp mountpoint directory before the tmp filesystem is mounted?
A large amount of things that would be 0755 on a "normal" linux install are 0700 with sgx-lkl. I'm not sure the reasoning there, but its the cause of our nobody test failures.
The minimum that / needs to be for non-root users to have access to "/tmp" is 0755.
@prp any idea why we are mounting / as 0700?
@prp any idea why we are mounting / as 0700?
That is a good question.
@prp this fix for this issue is to change to 755. I don't know of any harm from that. Although there might be.
Would you be in favor of switching?
@hukoyu I have a fix for this. Where can I find all the tests that were modified to work around this? I want to have those changes be part of the PR.
These are the changes that were made to ltp related to this issue:
It is blocking 9 test cases. For more details: https://dev.azure.com/ConfidentialContainers/ConfidentialLinuxContainers/_queries/edit/352/?triage=true