Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Harrisoonn@proton.me
Cc: "ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH] lib: tst_cgroup: Fix NULL pointer dereference
Date: Tue, 1 Dec 2026 16:49:23 +0100	[thread overview]
Message-ID: <20261201154923.GA80452@pevik> (raw)
In-Reply-To: <2Z_DdJA7Z-lEtZYh3a8WvCgJjvjO5ZHivMPAu0cMmospfpUBZtkVtxJ7uovx9F46F2WS-t1FxvjzjMOYnep1CrOvvGL__1YLyLhKa6NTk_4=@proton.me>

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

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

      parent reply	other threads:[~2026-12-01 15:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Petr Vorel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201154923.GA80452@pevik \
    --to=pvorel@suse.cz \
    --cc=Harrisoonn@proton.me \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox