* [PATCH] selftests/cgroup: Fix cg_read_strcmp() empty string comparison
@ 2026-05-09 8:03 Hongfu Li
2026-05-11 1:59 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Hongfu Li @ 2026-05-09 8:03 UTC (permalink / raw)
To: tj, hannes, mkoutny, shuah, seanjc, jthoughton, zhangguopeng
Cc: cgroups, linux-kselftest, linux-kernel, Hongfu Li
cg_read_strcmp() allocated a buffer sized to strlen(expected) + 1,
then passed it to read_text() which calls read(fd, buf, size-1).
When comparing against an empty string (""), strlen("") = 0 gives a
1-byte buffer, and read() is asked to read 0 bytes. The file content
is never actually read, so strcmp("", buf) always returns 0 regardless
of the real content. This caused cg_test_proc_killed() to always
report the cgroup as empty immediately, making OOM tests pass without
verifying that processes were killed.
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
tools/testing/selftests/cgroup/lib/cgroup_util.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testing/selftests/cgroup/lib/cgroup_util.c
index 6a7295347e90..42f54936f4bb 100644
--- a/tools/testing/selftests/cgroup/lib/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c
@@ -106,8 +106,9 @@ int cg_read_strcmp(const char *cgroup, const char *control,
/* Handle the case of comparing against empty string */
if (!expected)
return -1;
- else
- size = strlen(expected) + 1;
+
+ /* needs size > 1, otherwise cg_read() reads 0 bytes */
+ size = (expected[0] == '\0') ? 2 : strlen(expected) + 1;
buf = malloc(size);
if (!buf)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests/cgroup: Fix cg_read_strcmp() empty string comparison
2026-05-09 8:03 [PATCH] selftests/cgroup: Fix cg_read_strcmp() empty string comparison Hongfu Li
@ 2026-05-11 1:59 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-05-11 1:59 UTC (permalink / raw)
To: Hongfu Li
Cc: Johannes Weiner, Michal Koutný, Shuah Khan,
Sean Christopherson, James Houghton, zhangguopeng, cgroups,
linux-kselftest, linux-kernel
Hello,
Applied to cgroup/for-7.1-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-11 1:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 8:03 [PATCH] selftests/cgroup: Fix cg_read_strcmp() empty string comparison Hongfu Li
2026-05-11 1:59 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox