[LTP] [PATCH] lib: tst_cgroup: Fix NULL pointer dereference

Petr Vorel pvorel@suse.cz
Tue Dec 1 16:49:23 CET 2026


Hi Yorrison,

> 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.

Thank you, I should have caught that when doing review for 973da9fbd3.
Merged.

Kind regards,
Petr

> 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);


More information about the ltp mailing list