All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] lib: tst_cgroup: Fix NULL pointer dereference
@ 2026-11-29 20:05 Yorrison via ltp
  2026-11-29 20:58 ` [LTP] " linuxtestproject.agent
  2026-12-01 15:49 ` [LTP] [PATCH] " Petr Vorel
  0 siblings, 2 replies; 3+ messages in thread
From: Yorrison via ltp @ 2026-11-29 20:05 UTC (permalink / raw)
  To: ltp@lists.linux.it


tst_cg_require() dereferences ctrl->ctrl_name before checking whether
ctrl is NULL.

Move the initialization of base and the cgroup v2 validation after the
NULL check to prevent a NULL pointer dereference when the controller is
unknown.

Signed-off-by: Yorrison <Harrisoonn@proton.me>
---
 lib/tst_cgroup.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 3ee9d32a4..9e185f734 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -853,10 +853,7 @@ void tst_cg_require(const char *const ctrl_name,
 	const char *const cgsc = "cgroup.subtree_control";
 	struct cgroup_ctrl *const ctrl = cgroup_find_ctrl(ctrl_name, 1);
 	struct cgroup_root *root;
-	int base = !strcmp(ctrl->ctrl_name, "base");
-
-	if (base && options->needs_ver != TST_CG_V2)
-		tst_brk(TCONF, "Base control only support needs_ver TST_CG_V2!");
+	int base;
 
 	if (!ctrl) {
 		tst_brk(TBROK, "'%s' controller is unknown to LTP", ctrl_name);
@@ -864,6 +861,11 @@ void tst_cg_require(const char *const ctrl_name,
 		return;
 	}
 
+	base = !strcmp(ctrl->ctrl_name, "base");
+
+	if (base && options->needs_ver != TST_CG_V2)
+		tst_brk(TCONF, "Base control only support needs_ver TST_CG_V2!");
+
 	if (ctrl->we_require_it)
 		tst_res(TWARN, "Duplicate %s(%s, )", __func__, ctrl->ctrl_name);
 
-- 
2.53.0



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

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

end of thread, other threads:[~2026-12-01 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 20:05 [LTP] [PATCH] lib: tst_cgroup: Fix NULL pointer dereference Yorrison via ltp
2026-11-29 20:58 ` [LTP] " linuxtestproject.agent
2026-12-01 15:49 ` [LTP] [PATCH] " Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.