Skip to contentSkip to conversation

cgroup_dir_mk: set the umask to '0' before creating the subdir

PATCH In review Li Wang 3 participants 5 messages Mar 1, 2024 – Mar 3, 2024 Library code

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 cgroup_dir_mk: set the umask to '0' before creating the subdir

This is to resolve the permission issue when creating a new subdir in the cgroup, in case of 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)

---

Notes:
Hi Wei, can you help confirm if this patch works for you?

 lib/tst_cgroup.c | 2 ++
 1 file changed, 2 insertions(+)
lib/tst_cgroup.c +2 -0
index a8a598e0e..f6afb51d6 100644
@@ -361,6 +361,7 @@ static void cgroup_dir_mk(const struct cgroup_dir *const parent,
 			  struct cgroup_dir *const new)
 {
 	const char *dpath;
+	mode_t old_umask = umask(0);
 
 	new->dir_root = parent->dir_root;
 	new->dir_name = dir_name;
@@ -394,6 +395,7 @@ static void cgroup_dir_mk(const struct cgroup_dir *const parent,
 opendir:
 	new->dir_fd = SAFE_OPENAT(parent->dir_fd, dir_name,
 				  O_PATH | O_DIRECTORY);
+	umask(old_umask);
 }
 
 #define PATH_MAX_STRLEN 4095
Signature · 5 lines
2.40.1


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

Hi Li, Wei,

Quoted 6 lines

This is to resolve the permission issue when creating a new subdir in the cgroup, in case of 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)

Setting this on single place which *should* fix problems, but still not affect whole LTP API looks good to me. BTW there were more tests which needed it, e.g. testcases/kernel/syscalls/statx/statx07.c
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Therefore this solves just some problems.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 9 lines · Petr Vorel

Hi Li, Wei,

Quoted 6 lines

This is to resolve the permission issue when creating a new subdir in the cgroup, in case of 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)

Quoted 7 lines

Setting this on single place which *should* fix problems, but still not affect whole LTP API looks good to me. BTW there were more tests which needed it, e.g. testcases/kernel/syscalls/statx/statx07.c
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Send new patch for stat07:
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Quoted 7 lines

Therefore this solves just some problems.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Li Wang
Quoted 7 lines · Li Wang

This is to resolve the permission issue when creating a new subdir in the cgroup, in case of 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)

Quoted 6 lines

---

Notes:
Hi Wei, can you help confirm if this patch works for you?

@Li I have tested your patch and it can work.
@Li @Petr Thanks for your patch and comments, i suppose this patch can be merged.

Quoted 27 lines
 lib/tst_cgroup.c | 2 ++
 1 file changed, 2 insertions(+)
lib/tst_cgroup.c +2 -0
index a8a598e0e..f6afb51d6 100644
@@ -361,6 +361,7 @@ static void cgroup_dir_mk(const struct cgroup_dir *const parent,
 			  struct cgroup_dir *const new)
 {
 	const char *dpath;
+	mode_t old_umask = umask(0);
 
 	new->dir_root = parent->dir_root;
 	new->dir_name = dir_name;
@@ -394,6 +395,7 @@ static void cgroup_dir_mk(const struct cgroup_dir *const parent,
 opendir:
 	new->dir_fd = SAFE_OPENAT(parent->dir_fd, dir_name,
 				  O_PATH | O_DIRECTORY);
+	umask(old_umask);
 }
 
 #define PATH_MAX_STRLEN 4095
Signature · 1 line
2.40.1
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Li, Wei,

...

Quoted 5 lines
Quoted 2 lines

Notes:
Hi Wei, can you help confirm if this patch works for you?

@Li I have tested your patch and it can work.
@Li @Petr Thanks for your patch and comments, i suppose this patch can be merged.

I added Wei's RBT and TBT and merged.
Thank to you both!

Kind regards,
Petr

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