public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] cgroup: Handle trailing new line in cgroup.controllers
@ 2023-10-26  9:49 Richard Palethorpe via ltp
  2023-10-26 10:22 ` Marius Kittler
  2023-10-26 11:06 ` Petr Vorel
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Palethorpe via ltp @ 2023-10-26  9:49 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

The last item in cgroup.controllers (misc or rdma in my case)
contained a new line character which caused the controller search to
fail.

This commit avoids including the newline character inside the name
comparison.

The search failure caused the "cgroup_regression_test.sh" test to fail
with a confusing error when it tries to mount a V1 subsys thus
removing the V2 and causing the available set of V2s to change between
scans.

According to the V2 docs subsys names can only include lowercase
characters and '_'. So we strictly look for those characters.

The newline (and delimiting space) is just what the kernel currently
prints. IDK if it is specified anywhere, but if it changes then the
error should be obvious.

Fixes: 310da3784 ("Add new CGroups APIs")
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Cc: Petr Vorel <pvorel@suse.cz>
Cc: Marius Kittler <mkittler@suse.de>
---

V2:
* Add underscore
* Add length check
* Expand commit message
* Use shorter syntax

 lib/tst_cgroup.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 5240aadaa..c5cb20505 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -433,9 +433,20 @@ __attribute__ ((nonnull, warn_unused_result))
 static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
 {
 	struct cgroup_ctrl *ctrl;
+	int l = 0;
+	char c = ctrl_name[l];
+
+	while (c == '_' || (c >= 'a' && c <= 'z'))
+		c = ctrl_name[++l];
+
+	if (l > 32)
+		tst_res(TWARN, "Subsys name len greater than max known value of MAX_CGROUP_TYPE_NAMELEN: %d > 32", l);
+
+	if (!(c == '\n' || c == '\0'))
+		tst_brk(TBROK, "Unexpected char in %s: %c", ctrl_name, c);
 
 	for_each_ctrl(ctrl) {
-		if (!strcmp(ctrl_name, ctrl->ctrl_name))
+		if (!strncmp(ctrl_name, ctrl->ctrl_name, l))
 			return ctrl;
 	}
 
-- 
2.40.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-27 10:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-26  9:49 [LTP] [PATCH v2] cgroup: Handle trailing new line in cgroup.controllers Richard Palethorpe via ltp
2023-10-26 10:22 ` Marius Kittler
2023-10-26 11:06 ` Petr Vorel
2023-10-27  8:21   ` Richard Palethorpe
2023-10-27 10:09     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox