cgroup_core02: Requires cgroup2 mounted with nsdelegate
PATCH 1/1 cgroup_core02: Requires cgroup2 mounted with nsdelegate
If cgroup2 is not mounted with the nsdelegate option, this test will fail. It has been patched in kselftests, but has not been ported to LTP yet. This adds an additional tst_test configuration option, needs_cgroup_nsdelegate, to check for the mount option.
--- include/tst_cgroup.h | 1 + include/tst_test.h | 2 ++ lib/tst_cgroup.c | 17 +++++++++++++++++ lib/tst_test.c | 1 + .../kernel/controllers/cgroup/cgroup_core02.c | 1 + 5 files changed, 22 insertions(+)
include/tst_cgroup.h +1 -0
@@ -104,6 +104,7 @@ struct tst_cg_opts {* directory as opposed to the default pid of the calling process. */ int test_pid; +int needs_nsdelegate; };/* A Control Group in LTP's aggregated hierarchy */
include/tst_test.h +2 -0
@@ -578,6 +578,8 @@ struct tst_fs {const enum tst_cg_ver needs_cgroup_ver;const char *const *needs_cgroup_ctrls; + + int needs_cgroup_nsdelegate:1; };/**
lib/tst_cgroup.c +17 -0
@@ -71,6 +71,8 @@ struct cgroup_root {/* CGroup for current test. Which may have children. */ struct cgroup_dir test_dir; + int nsdelegate:1; + int we_mounted_it:1;/* cpuset is in compatability mode */ int no_cpuset_prefix:1;
@@ -344,6 +346,11 @@ static int cgroup_v1_mounted(void)return !!roots[1 ].ver; } +static int cgroup_v2_nsdelegate (void ) +{ +return !!roots[0 ].nsdelegate; +} +static int cgroup_mounted (void ) {return cgroup_v2_mounted () ||cgroup_v1_mounted ();
@@ -568,6 +575,7 @@ static void cgroup_root_scan(const char *const mnt_type,struct cgroup_ctrl *ctrl;uint32_t ctrl_field =0 ;int no_prefix =0 ; +int nsdelegate =0 ;char buf[BUFSIZ ];char *tok;const int mnt_dfd =SAFE_OPEN (mnt_dir,O_PATH |O_DIRECTORY );
@@ -582,6 +590,9 @@ static void cgroup_root_scan(const char *const mnt_type,if (const_ctrl)add_ctrl (&ctrl_field, const_ctrl); } +for (tok =strtok (mnt_opts,"," ); tok; tok =strtok (NULL ,"," )) { + nsdelegate |= !strcmp ("nsdelegate" , tok); + }if (root->ver && ctrl_field == root->ctrl_field) goto discard;
@@ -632,6 +643,7 @@ backref: root->mnt_dir.dir_fd = mnt_dfd; root->ctrl_field = ctrl_field; root->no_cpuset_prefix = no_prefix; + root->nsdelegate = nsdelegate;for_each_ctrl (ctrl) {if (has_ctrl (root->ctrl_field, ctrl))
@@ -869,6 +881,11 @@ void tst_cg_require(const char *const ctrl_name, mkdirs: root = ctrl->ctrl_root; + +if (options->needs_nsdelegate &&cgroup_v2_mounted () && + && !cgroup_v2_nsdelegate ()) +tst_brk (TCONF ,"Requires cgroup2 to be mounted with nsdelegate" ); +add_ctrl (&root->mnt_dir.ctrl_field, ctrl);if (cgroup_ctrl_on_v2 (ctrl) && options->needs_ver ==TST_CG_V1 ) {
lib/tst_test.c +1 -0
@@ -1130,6 +1130,7 @@ static void do_cgroup_requires(void) {const struct tst_cg_opts cg_opts = { .needs_ver = tst_test->needs_cgroup_ver, + .needs_nsdelegate = tst_test->needs_cgroup_nsdelegate, };const char *const *ctrl_names = tst_test->needs_cgroup_ctrls;
testcases/kernel/controllers/cgroup/cgroup_core02.c +1 -0
@@ -121,6 +121,7 @@ static struct tst_test test = { .needs_root = 1, .needs_cgroup_ctrls = (const char *const[]){"memory", NULL}, .needs_cgroup_ver = TST_CG_V2, + .needs_cgroup_nsdelegate = 1, .tags = (const struct tst_tag []) { {"linux-git" ,"e57457641613" }, {"CVE" ,"2021-4197" },
Signature · 5 lines
2.46.0.rc1.232.g9752f9e123-goog -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Edward, all,
Merged (with few changes below), thank you!
Quoted 4 lines
If cgroup2 is not mounted with the nsdelegate option, this test will fail. It has been patched in kselftests, but has not been ported to LTP yet. This adds an additional
tst_testconfiguration option,needs_cgroup_nsdelegate, to check for the mount option.
I mentioned also the kernel commit 4793cb599b1b ("selftests: cgroup: skip test_cgcore_lesser_ns_open when cgroup2 mounted without nsdelegate")
Quoted 3 lines
...
include/tst_test.h struct tst_fs { · line 582
Quoted 10 lines
include/tst_test.h +2
-0@@ -578,6 +578,8 @@ struct tst_fs {const enum tst_cg_ver needs_cgroup_ver;const char *const *needs_cgroup_ctrls; + + int needs_cgroup_nsdelegate:1;
New member also needs to be documented above:
*
* @needs_cgroup_nsdelegate: If set test the will run only if cgroup2 is mounted
* with nsdelegate option.
I added this before merge.
Quoted 55 lines
include/tst_test.h +0
-0};/** lib/tst_cgroup.c +12
-0@@ -71,6 +71,8 @@ struct cgroup_root {/* CGroup for current test. Which may have children. */ struct cgroup_dir test_dir; + int nsdelegate:1; + int we_mounted_it:1;/* cpuset is in compatability mode */ int no_cpuset_prefix:1;@@ -344,6 +346,11 @@ static int cgroup_v1_mounted(void)return !!roots[1 ].ver; } +static int cgroup_v2_nsdelegate (void ) +{ +return !!roots[0 ].nsdelegate; +} +static int cgroup_mounted (void ) {return cgroup_v2_mounted () ||cgroup_v1_mounted ();@@ -568,6 +575,7 @@ static void cgroup_root_scan(const char *const mnt_type,struct cgroup_ctrl *ctrl;uint32_t ctrl_field =0 ;int no_prefix =0 ; +int nsdelegate =0 ;char buf[BUFSIZ ];char *tok;const int mnt_dfd =SAFE_OPEN (mnt_dir,O_PATH |O_DIRECTORY );@@ -582,6 +590,9 @@ static void cgroup_root_scan(const char *const mnt_type,if (const_ctrl)add_ctrl (&ctrl_field, const_ctrl); } +for (tok =strtok (mnt_opts,"," ); tok; tok =strtok (NULL ,"," )) { + nsdelegate |= !strcmp ("nsdelegate" , tok); + }if (root->ver && ctrl_field == root->ctrl_field) goto discard;@@ -632,6 +643,7 @@ backref: root->mnt_dir.dir_fd = mnt_dfd; root->ctrl_field = ctrl_field; root->no_cpuset_prefix = no_prefix; + root->nsdelegate = nsdelegate;for_each_ctrl (ctrl) {if (has_ctrl (root->ctrl_field, ctrl))
lib/tst_cgroup.c void tst_cg_require(const char *const ctrl_name, · line 886
Quoted 6 lines
lib/tst_cgroup.c +3
-0@@ -869,6 +881,11 @@ void tst_cg_require(const char *const ctrl_name, mkdirs: root = ctrl->ctrl_root; + +if (options->needs_nsdelegate &&cgroup_v2_mounted () && + && !cgroup_v2_nsdelegate ())
Double && broke the build, thus I fixed it (+ added inline for readability, otherwise it'd be better to use { } when split on two lines).
Kind regards,
Petr
Quoted 29 lines
lib/tst_cgroup.c +2
-0+tst_brk (TCONF ,"Requires cgroup2 to be mounted with nsdelegate" ); +add_ctrl (&root->mnt_dir.ctrl_field, ctrl);if (cgroup_ctrl_on_v2 (ctrl) && options->needs_ver ==TST_CG_V1 ) {lib/tst_test.c +1
-0@@ -1130,6 +1130,7 @@ static void do_cgroup_requires(void) {const struct tst_cg_opts cg_opts = { .needs_ver = tst_test->needs_cgroup_ver, + .needs_nsdelegate = tst_test->needs_cgroup_nsdelegate, };const char *const *ctrl_names = tst_test->needs_cgroup_ctrls;testcases/kernel/controllers/cgroup/cgroup_core02.c +1
-0@@ -121,6 +121,7 @@ static struct tst_test test = { .needs_root = 1, .needs_cgroup_ctrls = (const char *const[]){"memory", NULL}, .needs_cgroup_ver = TST_CG_V2, + .needs_cgroup_nsdelegate = 1, .tags = (const struct tst_tag []) { {"linux-git" ,"e57457641613" }, {"CVE" ,"2021-4197" },
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp