Skip to contentSkip to conversation

cgroup_core01.c: Set umask before create directory

PATCH In review Wei Gao via ltp 3 participants 22 messages Dec 4, 2023 – Mar 1, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup_core01.c: Set umask before create directory

Some specific build's default mask is 0077, this will trigger issue if
you create directory with A but switch B to access it. Such as following
failed message will popup in current case:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

---
 testcases/kernel/controllers/cgroup/cgroup_core01.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/controllers/cgroup/cgroup_core01.c +1 -0
index 2e695deed..0deff6209 100644
@@ -38,6 +38,7 @@ static void test_lesser_euid_open(void)
 	int fds[TST_CG_ROOTS_MAX] = {-1};
 	int i, loops;
 
+	umask(0022);
 	cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
 	cg_child_b = tst_cg_group_mk(tst_cg, "child_b");
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author Reviewed-by Andrea Cervesato on v1 1/1
#1 lore raw

Hi!
LGTM

Reviewed-by Andrea Cervesato <andrea.cervesato.suse.com>
Quoted 22 lines · Wei Gao via ltp

Some specific build's default mask is 0077, this will trigger issue if
you create directory with A but switch B to access it. Such as following
failed message will popup in current case:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

---
  testcases/kernel/controllers/cgroup/cgroup_core01.c | 1 +
  1 file changed, 1 insertion(+)
testcases/kernel/controllers/cgroup/cgroup_core01.c +1 -0
index 2e695deed..0deff6209 100644
@@ -38,6 +38,7 @@ static void test_lesser_euid_open(void)
  	int fds[TST_CG_ROOTS_MAX] = {-1};
  	int i, loops;
 
+	umask(0022);
  	cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
  	cg_child_b = tst_cg_group_mk(tst_cg, "child_b");
 
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 tst_test.c: Set system default umaks to 0022

In reply to Wei Gao via ltp

Some system's default umask is 0077, this will trigger issues for LTP case.

Example 1:
cgroup_core01.c will report following error msg:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

Detail reason:
Code:
cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
cg_child_b = tst_cg_group_mk(tst_cg, "child_b");

Result:
wegao:/sys/fs/cgroup # ll ltp/test-25304/
drwx------ 2 root root 0 Feb 10 10:37 child_a <<<<<< group and other has no any permission
drwx------ 2 root root 0 Feb 10 10:38 child_b

Code:
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1); SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);

Result:
wegao:/sys/fs/cgroup # ll ltp/test-26388/child_a/ total 0
-rw-r--r-- 1 nobody root 0 Feb 10 10:44 cgroup.procs <<<<<<

Code:
SAFE_SETEUID(nobody_uid); <<<< after switch to nobody then can not access child_{a,b} or any file under child_{a,b}

Result:
nobody@wegao:/sys/fs/cgroup/ltp/test-26730> ll child_a/ <<< nobody has no permission on child_a
ls: cannot open directory 'child_a/': Permission denied

Code:
loops = SAFE_CG_OPEN(cg_child_b, "cgroup.procs", O_RDWR, fds);
Result:
cgroup_core01.c:76: TBROK: openat(9</sys/fs/cgroup/ltp/test-26388/child_b>, 'cgroup.procs', 2, 0): EACCES (13)

Example 2:
chdir01
chdir01.c:107: TFAIL: nobody: chdir("testfile") returned unexpected error: EACCES (13)

Reason:
susetest:/tmp/LTP_chd5JtblL/mntpoint # mount | grep loop0
/dev/loop0 on /tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/loop0 on /var/tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

susetest:/tmp/LTP_chd5JtblL # ll
total 307216
drwx------ 4 root root 16384 Dec 31 1969 mntpoint <<<< nobody has no permission on mount directory
-rw------- 1 root root 314572800 Feb 19 04:51 test_dev.img

susetest:/tmp/LTP_chd5JtblL/mntpoint # ll
total 16
-rwx------ 1 root root 0 Feb 19 04:53 aa
drwx------ 2 root root 8192 Feb 19 04:50 keep_out
drwx------ 2 root root 8192 Feb 19 04:50 subdir
-rwx------ 1 root root 0 Feb 19 04:50 testfile <<<< nobody has no permission on testfile

---
 lib/tst_test.c | 2 ++
 1 file changed, 2 insertions(+)
lib/tst_test.c +2 -0
index edb42f7f4..e03fd93e7 100644
@@ -1174,6 +1174,8 @@ static void do_setup(int argc, char *argv[])
 {
 	char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
 
+	umask(0022);
+
 	if (!tst_test)
 		tst_brk(TBROK, "No tests to run");
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2] tst_test.c: Set system default umaks to 0022

Hi Wei,

Quoted 69 lines

Some system's default umask is 0077, this will trigger issues for LTP case.

Example 1:
cgroup_core01.c will report following error msg:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

Detail reason:
Code:
cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
cg_child_b = tst_cg_group_mk(tst_cg, "child_b");

Result:
wegao:/sys/fs/cgroup # ll ltp/test-25304/
drwx------ 2 root root 0 Feb 10 10:37 child_a <<<<<< group and other has no any permission
drwx------ 2 root root 0 Feb 10 10:38 child_b

Code:
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1); SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);

Result:
wegao:/sys/fs/cgroup # ll ltp/test-26388/child_a/ total 0
-rw-r--r-- 1 nobody root 0 Feb 10 10:44 cgroup.procs <<<<<<

Code:
SAFE_SETEUID(nobody_uid); <<<< after switch to nobody then can not access child_{a,b} or any file under child_{a,b}

Result:
nobody@wegao:/sys/fs/cgroup/ltp/test-26730> ll child_a/ <<< nobody has no permission on child_a
ls: cannot open directory 'child_a/': Permission denied

Code:
loops = SAFE_CG_OPEN(cg_child_b, "cgroup.procs", O_RDWR, fds);
Result:
cgroup_core01.c:76: TBROK: openat(9</sys/fs/cgroup/ltp/test-26388/child_b>, 'cgroup.procs', 2, 0): EACCES (13)

Example 2:
chdir01
chdir01.c:107: TFAIL: nobody: chdir("testfile") returned unexpected error: EACCES (13)

Reason:
susetest:/tmp/LTP_chd5JtblL/mntpoint # mount | grep loop0
/dev/loop0 on /tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/loop0 on /var/tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

susetest:/tmp/LTP_chd5JtblL # ll
total 307216
drwx------ 4 root root 16384 Dec 31 1969 mntpoint <<<< nobody has no permission on mount directory
-rw------- 1 root root 314572800 Feb 19 04:51 test_dev.img

susetest:/tmp/LTP_chd5JtblL/mntpoint # ll
total 16
-rwx------ 1 root root 0 Feb 19 04:53 aa
drwx------ 2 root root 8192 Feb 19 04:50 keep_out
drwx------ 2 root root 8192 Feb 19 04:50 subdir
-rwx------ 1 root root 0 Feb 19 04:50 testfile <<<< nobody has no permission on testfile

---
 lib/tst_test.c | 2 ++
 1 file changed, 2 insertions(+)
lib/tst_test.c +0 -0
index edb42f7f4..e03fd93e7 100644

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1177

Quoted 4 lines
lib/tst_test.c +1 -0
@@ -1174,6 +1174,8 @@ static void do_setup(int argc, char *argv[])
 {
 	char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
 
+	umask(0022);

I don't think this is a good idea. Changing umask() in the library can influent tests. Could you please instead add umask(0) (to reset umask) on the tests which need it? The way it's done in open07.c.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2] tst_test.c: Set system default umaks to 0022

Quoted 9 lines · Petr Vorel

Hi Wei,

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1177

Quoted 3 lines
lib/tst_test.c +1 -0
 	char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
 
+	umask(0022);

I don't think this is a good idea. Changing umask() in the library can influent tests. Could you please instead add umask(0) (to reset umask) on the tests which need it? The way it's done in open07.c.

cgroup_core01.c and statx07.c can use umask(0) in tests and i have updated the patch.

But chdir01 will still failed on vfat and exfat. Like following error msg:
chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)

The reason is umask(0) should set before mount /dev/loop0 to /tmp/xxx/mntpoint, otherwise you have no chance modify permission of file. What's your suggestion?

susetest:/tmp/LTP_chd5JtblL/mntpoint # mount | grep loop0
/dev/loop0 on /tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/loop0 on /var/tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

susetest:/tmp/LTP_chd5JtblL # chmod 777 mntpoint <<<< susetest:/tmp/LTP_chd5JtblL # ll
total 307216
drwx------ 4 root root 16384 Dec 31 1969 mntpoint <<<<<<<< group and other has no any permission even try chmod
-rw------- 1 root root 314572800 Feb 19 04:51 test_dev.img

susetest:/tmp/LTP_chd5JtblL/mntpoint # touch aa
susetest:/tmp/LTP_chd5JtblL/mntpoint # ll
total 16
-rwx------ 1 root root 0a
drwx------ 2 root root 8192 Feb 19 04:50 keep_out
drwx------ 2 root root 8192 Feb 19 04:50 subdir
-rwx------ 1 root root 0 Feb 19 04:50 testfile <<<<<<

Thanks.

Quoted 3 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v2] tst_test.c: Set system default umaks to 0022

Hi all,

Quoted 10 lines · Petr Vorel
Quoted 9 lines

Hi Wei,

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1177

Quoted 3 lines
lib/tst_test.c +1 -0
 	char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
 
+	umask(0022);

I don't think this is a good idea. Changing umask() in the library can influent tests. Could you please instead add umask(0) (to reset umask) on the tests which need it? The way it's done in open07.c.

First I thought that modifying umask (either with umask(0022) or just reset with umask(0)) is not a good idea, but now I'm not sure:

1) We have quite a few tests, which will needs it:
NEW API tests:

$ git grep '^\s*umask(0' $(git grep -l tst_test.h) | wc -l
15

All tests:

$ git grep '^\s*umask(0' testcases/ | wc -l
34

And for sure some other, which will fail when too restrictive umask is set.

Wouldn't be better to have it in the library? Hopefully fewer tests would be influenced this setup (and would need to set different umask()).

Quoted 4 lines

cgroup_core01.c and statx07.c can use umask(0) in tests and i have updated the patch.

But chdir01 will still failed on vfat and exfat. Like following error msg:
chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)

FYI test fails on vfat and ntfs when umask is 0077 (because override file and directory permissions) (other filesystems are ok).

Quoted 6 lines

The reason is umask(0) should set before mount /dev/loop0 to /tmp/xxx/mntpoint, otherwise you have no chance modify permission of file. What's your suggestion?

susetest:/tmp/LTP_chd5JtblL/mntpoint # mount | grep loop0
/dev/loop0 on /tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/loop0 on /var/tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

2) tests, which set .mount_device = 1 and have more restrictive umask will not work. Workaround would be to not use it and mount manually in the setup(). Or, reset umask with umask(0).

WDYT?

Kind regards,
Petr

Quoted 19 lines

susetest:/tmp/LTP_chd5JtblL # chmod 777 mntpoint <<<< susetest:/tmp/LTP_chd5JtblL # ll
total 307216
drwx------ 4 root root 16384 Dec 31 1969 mntpoint <<<<<<<< group and other has no any permission even try chmod
-rw------- 1 root root 314572800 Feb 19 04:51 test_dev.img

susetest:/tmp/LTP_chd5JtblL/mntpoint # touch aa
susetest:/tmp/LTP_chd5JtblL/mntpoint # ll
total 16
-rwx------ 1 root root 0a
drwx------ 2 root root 8192 Feb 19 04:50 keep_out
drwx------ 2 root root 8192 Feb 19 04:50 subdir
-rwx------ 1 root root 0 Feb 19 04:50 testfile <<<<<<

Thanks.

Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v2] tst_test.c: Set system default umaks to 0022

Quoted 45 lines · Petr Vorel

Hi all,

Quoted 10 lines · Petr Vorel
Quoted 9 lines

Hi Wei,

lib/tst_test.c static void do_setup(int argc, char *argv[]) · line 1177

Quoted 3 lines
lib/tst_test.c +1 -0
 	char *tdebug_env = getenv("LTP_ENABLE_DEBUG");
 
+	umask(0022);

I don't think this is a good idea. Changing umask() in the library can influent tests. Could you please instead add umask(0) (to reset umask) on the tests which need it? The way it's done in open07.c.

First I thought that modifying umask (either with umask(0022) or just reset with umask(0)) is not a good idea, but now I'm not sure:

1) We have quite a few tests, which will needs it:
NEW API tests:

$ git grep '^\s*umask(0' $(git grep -l tst_test.h) | wc -l
15

All tests:

$ git grep '^\s*umask(0' testcases/ | wc -l
34

And for sure some other, which will fail when too restrictive umask is set.

Wouldn't be better to have it in the library? Hopefully fewer tests would be influenced this setup (and would need to set different umask()).

Quoted 4 lines

cgroup_core01.c and statx07.c can use umask(0) in tests and i have updated the patch.

But chdir01 will still failed on vfat and exfat. Like following error msg:
chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)

FYI test fails on vfat and ntfs when umask is 0077 (because override file and directory permissions) (other filesystems are ok).

Quoted 6 lines

The reason is umask(0) should set before mount /dev/loop0 to /tmp/xxx/mntpoint, otherwise you have no chance modify permission of file. What's your suggestion?

susetest:/tmp/LTP_chd5JtblL/mntpoint # mount | grep loop0
/dev/loop0 on /tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/loop0 on /var/tmp/LTP_chd5JtblL/mntpoint type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

Quoted 5 lines

2) tests, which set .mount_device = 1 and have more restrictive umask will not work. Workaround would be to not use it and mount manually in the setup(). Or, reset umask with umask(0).

WDYT?

Currently i only need fix one case chdir01 so i will try to do workaround(mount mount manually in setup). If new fail happen in future then i suppose we need consider do umask in lib.

Thanks for your comments.

Quoted 23 lines

Kind regards,
Petr

Quoted 19 lines

susetest:/tmp/LTP_chd5JtblL # chmod 777 mntpoint <<<< susetest:/tmp/LTP_chd5JtblL # ll
total 307216
drwx------ 4 root root 16384 Dec 31 1969 mntpoint <<<<<<<< group and other has no any permission even try chmod
-rw------- 1 root root 314572800 Feb 19 04:51 test_dev.img

susetest:/tmp/LTP_chd5JtblL/mntpoint # touch aa
susetest:/tmp/LTP_chd5JtblL/mntpoint # ll
total 16
-rwx------ 1 root root 0a
drwx------ 2 root root 8192 Feb 19 04:50 keep_out
drwx------ 2 root root 8192 Feb 19 04:50 subdir
-rwx------ 1 root root 0 Feb 19 04:50 testfile <<<<<<

Thanks.

Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

v3 cover Set system default umaks to 0022

In reply to Wei Gao via ltp

Wei Gao (2):
cgroup_core01.c: Set system default umaks to 0022 statx07.c: set umask to 0022

 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 testcases/kernel/syscalls/statx/statx07.c           | 2 ++
 2 files changed, 4 insertions(+)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

PATCH v3 1/2 cgroup_core01.c: Set system default umaks to 0022

When system's default umask is 0077, this will trigger issues for LTP case.

cgroup_core01.c will report following error msg:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

Detail reason:
Code:
cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
cg_child_b = tst_cg_group_mk(tst_cg, "child_b");

Result:
wegao:/sys/fs/cgroup # ll ltp/test-25304/
drwx------ 2 root root 0 Feb 10 10:37 child_a <<<<<< group and other has no any permission
drwx------ 2 root root 0 Feb 10 10:38 child_b

Code:
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1); SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);

Result:
wegao:/sys/fs/cgroup # ll ltp/test-26388/child_a/ total 0
-rw-r--r-- 1 nobody root 0 Feb 10 10:44 cgroup.procs <<<<<<

Code:
SAFE_SETEUID(nobody_uid); <<<< after switch to nobody then can not access child_{a,b} or any file under child_{a,b}

Result:
nobody@wegao:/sys/fs/cgroup/ltp/test-26730> ll child_a/ <<< nobody has no permission on child_a
ls: cannot open directory 'child_a/': Permission denied

Code:
loops = SAFE_CG_OPEN(cg_child_b, "cgroup.procs", O_RDWR, fds);
Result:
cgroup_core01.c:76: TBROK: openat(9</sys/fs/cgroup/ltp/test-26388/child_b>, 'cgroup.procs', 2, 0): EACCES (13)

---
 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/controllers/cgroup/cgroup_core01.c +2 -0
index 2e695deed..80d13a9c5 100644
@@ -76,6 +76,8 @@ static void setup(void)
 {
 	struct passwd *pw;
 
+	umask(0022);
+
 	pw = SAFE_GETPWNAM("nobody");
 	nobody_uid = pw->pw_uid;
 	save_uid = geteuid();
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

PATCH v3 2/2 statx07.c: set umask to 0022

In reply to Wei Gao via ltp

When system's default umask is 0077, this will trigger issues.

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +2 -0
index 4dbf83e18..1ad02fb3e 100644
@@ -116,6 +116,8 @@ static void setup(void)
 	int ret;
 	char server_path[BUFF_SIZE];
 
+	umask(0022);
+
 	cwd = tst_get_tmpdir();
 
 	SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v3 2/2] statx07.c: set umask to 0022

Hi Wei,

Quoted 12 lines

When system's default umask is 0077, this will trigger issues.

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +0 -0
index 4dbf83e18..1ad02fb3e 100644

testcases/kernel/syscalls/statx/statx07.c static void setup(void) · line 119

Quoted 4 lines
testcases/kernel/syscalls/statx/statx07.c +1 -0
@@ -116,6 +116,8 @@ static void setup(void)
 	int ret;
 	char server_path[BUFF_SIZE];
 
+	umask(0022);

Even this works, why not completely reset umask with umask(0), as I asked previously? That's the safest option.

Kind regards,
Petr

Quoted 4 lines
testcases/kernel/syscalls/statx/statx07.c +1 -0
+
 	cwd = tst_get_tmpdir();
 
 	SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

v3 cover Set system default umaks to 0

In reply to Wei Gao via ltp

Wei Gao (2):
cgroup_core01.c: Set system default umaks to 0
statx07.c: set umask to 0

 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 testcases/kernel/syscalls/statx/statx07.c           | 2 ++
 2 files changed, 4 insertions(+)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v4 1/2 cgroup_core01.c: Set system default umaks to 0

When system's default umask is 0077, this will trigger issues for LTP case.

cgroup_core01.c will report following error msg:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

Detail reason:
Code:
cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
cg_child_b = tst_cg_group_mk(tst_cg, "child_b");

Result:
wegao:/sys/fs/cgroup # ll ltp/test-25304/
drwx------ 2 root root 0 Feb 10 10:37 child_a <<<<<< group and other has no any permission
drwx------ 2 root root 0 Feb 10 10:38 child_b

Code:
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1); SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);

Result:
wegao:/sys/fs/cgroup # ll ltp/test-26388/child_a/ total 0
-rw-r--r-- 1 nobody root 0 Feb 10 10:44 cgroup.procs <<<<<<

Code:
SAFE_SETEUID(nobody_uid); <<<< after switch to nobody then can not access child_{a,b} or any file under child_{a,b}

Result:
nobody@wegao:/sys/fs/cgroup/ltp/test-26730> ll child_a/ <<< nobody has no permission on child_a
ls: cannot open directory 'child_a/': Permission denied

Code:
loops = SAFE_CG_OPEN(cg_child_b, "cgroup.procs", O_RDWR, fds);
Result:
cgroup_core01.c:76: TBROK: openat(9</sys/fs/cgroup/ltp/test-26388/child_b>, 'cgroup.procs', 2, 0): EACCES (13)

---
 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/controllers/cgroup/cgroup_core01.c +2 -0
index 2e695deed..ad08c74a9 100644
@@ -76,6 +76,8 @@ static void setup(void)
 {
 	struct passwd *pw;
 
+	umask(0);
+
 	pw = SAFE_GETPWNAM("nobody");
 	nobody_uid = pw->pw_uid;
 	save_uid = geteuid();
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v4 2/2 statx07.c: set umask to 0

In reply to Wei Gao via ltp

When system's default umask is 0077, this will trigger issues.

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +2 -0
index 4dbf83e18..227c33c96 100644
@@ -116,6 +116,8 @@ static void setup(void)
 	int ret;
 	char server_path[BUFF_SIZE];
 
+	umask(0);
+
 	cwd = tst_get_tmpdir();
 
 	SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

v5 cover Set system default umaks to 0

In reply to Wei Gao via ltp

Wei Gao (2):
cgroup_core01.c: Set system default umaks to 0
statx07.c: set umask to 0

 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 testcases/kernel/syscalls/statx/statx07.c           | 2 ++
 2 files changed, 4 insertions(+)
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH v5 1/2 cgroup_core01.c: Set system default umaks to 0

When system's default umask is 0077, following error will popup:
cgroup_core01.c:50: TBROK: openat(21</sys/fs/cgroup/memory/ltp/test-3519/child_b>, 'tasks', 2, 0): EACCES (13)

The reason is default user will create directory without permission for group and other if umask(0077), then error happen if case switch to nobody user.

---
 testcases/kernel/controllers/cgroup/cgroup_core01.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/controllers/cgroup/cgroup_core01.c +2 -0
index 2e695deed..ad08c74a9 100644
@@ -76,6 +76,8 @@ static void setup(void)
 {
 	struct passwd *pw;
 
+	umask(0);
+
 	pw = SAFE_GETPWNAM("nobody");
 	nobody_uid = pw->pw_uid;
 	save_uid = geteuid();
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

Re: [LTP] [PATCH v5 1/2] cgroup_core01.c: Set system default umaks to 0

Hi Wei, Petr,

Seems the problem Wei met is the default umask of 0077, any new files or directories that are created will have their permission bits modified by this umask.

After looking though what you both discussed, I think maybe another better choice is to set the umask to '0000' temporarily before creating the directory, and then restoring the previous umask right after.

All these operations are just put into cgroup_dir_mk function.

Something like this:

lib/tst_cgroup.c +0 -0
@@ -368,8 +368,11 @@ static void cgroup_dir_mk(const struct cgroup_dir

*const parent,

        new->ctrl_field = parent->ctrl_field;
        new->we_created_it = 0;

+ mode_t old_umask = umask(0000);
+

        if (!mkdirat(parent->dir_fd, dir_name, 0777)) {
                new->we_created_it = 1;
+               umask(old_umask);
                goto opendir;
        }
Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

Re: [LTP] [PATCH v5 1/2] cgroup_core01.c: Set system default umaks to 0

Hi Li,

Quoted 6 lines

Hi Wei, Petr,

Seems the problem Wei met is the default umask of 0077, any new files or directories that are created will have their permission bits modified by this umask.

Quoted 6 lines

After looking though what you both discussed, I think maybe another better choice is to set the umask to '0000' temporarily before creating the directory, and then restoring the previous umask right after.

All these operations are just put into cgroup_dir_mk function.

LGTM this approach, please send a patch.

lib/tst_cgroup.c static void cgroup_dir_mk(const struct cgroup_dir · line 372

Quoted 10 lines

Something like this:

lib/tst_cgroup.c +1 -0
@@ -368,8 +368,11 @@ static void cgroup_dir_mk(const struct cgroup_dir
 *const parent,
        new->ctrl_field = parent->ctrl_field;
        new->we_created_it = 0;
 
+       mode_t old_umask = umask(0000);

nit: umask(0) is the same right?

Kind regards,
Petr

Quoted 6 lines
lib/tst_cgroup.c +2 -0
+
        if (!mkdirat(parent->dir_fd, dir_name, 0777)) {
                new->we_created_it = 1;
+               umask(old_umask);
                goto opendir;
        }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

Re: [LTP] [PATCH v5 1/2] cgroup_core01.c: Set system default umaks to 0

Quoted 8 lines · Petr Vorel

Hi Li,

Quoted 5 lines

Hi Wei, Petr,

Seems the problem Wei met is the default umask of 0077, any new files or directories that are created will have their permission bits modified by this umask.

Quoted 9 lines
Quoted 6 lines

After looking though what you both discussed, I think maybe another better choice is to set the umask to '0000' temporarily before creating the directory, and then restoring the previous umask right after.

All these operations are just put into cgroup_dir_mk function.

LGTM this approach, please send a patch.

Ok, sure.

Quoted 3 lines
Quoted 1 line

+ mode_t old_umask = umask(0000);

nit: umask(0) is the same right?

exactly.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw

PATCH v5 2/2 statx07.c: set umask to 0

In reply to Wei Gao via ltp

When system's default umask is 0077, this will trigger following issues:
statx07.c:108: TFAIL: statx() with AT_STATX_DONT_SYNC for mode 644 600

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +2 -0
index 4dbf83e18..227c33c96 100644
@@ -116,6 +116,8 @@ static void setup(void)
 	int ret;
 	char server_path[BUFF_SIZE];
 
+	umask(0);
+
 	cwd = tst_get_tmpdir();
 
 	SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#20 lore raw

Re: [LTP] [PATCH v5 2/2] statx07.c: set umask to 0

Quoted 15 lines · Wei Gao via ltp

When system's default umask is 0077, this will trigger following issues:
statx07.c:108: TFAIL: statx() with AT_STATX_DONT_SYNC for mode 644 600

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +0 -0
index 4dbf83e18..227c33c96 100644

testcases/kernel/syscalls/statx/statx07.c static void setup(void) · line 123

Quoted 8 lines
testcases/kernel/syscalls/statx/statx07.c +2 -0
@@ -116,6 +116,8 @@ static void setup(void)
        int ret;
        char server_path[BUFF_SIZE];
 
+       umask(0);
+
        cwd = tst_get_tmpdir();
 
        SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);

Better to restore the old mask right after.

Otherwise looks good.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

Re: [LTP] [PATCH v5 2/2] statx07.c: set umask to 0

Quoted 19 lines · Wei Gao via ltp
Quoted 17 lines

When system's default umask is 0077, this will trigger following issues:
statx07.c:108: TFAIL: statx() with AT_STATX_DONT_SYNC for mode 644 600

---
 testcases/kernel/syscalls/statx/statx07.c | 2 ++
 1 file changed, 2 insertions(+)
testcases/kernel/syscalls/statx/statx07.c +0 -0
index 4dbf83e18..227c33c96 100644
@@ -116,6 +116,8 @@ static void setup(void)
        int ret;
        char server_path[BUFF_SIZE];
Quoted 8 lines

testcases/kernel/syscalls/statx/statx07.c static void setup(void) · line 123

Quoted 5 lines
testcases/kernel/syscalls/statx/statx07.c +2 -0
+       umask(0);
+
        cwd = tst_get_tmpdir();
 
        SAFE_MKDIR(SERV_PATH, DEFAULT_MODE);

Better to restore the old mask right after.

+1, Wei, can you please send new version?

Quoted 1 line

Otherwise looks good.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp