public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Mukesh Ojha <quic_mojha@quicinc.com>
To: Ming Lei <ming.lei@redhat.com>, Tejun Heo <tj@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: cgroups@vger.kernel.org, Marco Patalano <mpatalan@redhat.com>,
	Muneendra <muneendra.kumar@broadcom.com>
Subject: Re: [PATCH] cgroup: fix cgroup_get_from_id
Date: Fri, 23 Sep 2022 21:13:15 +0530	[thread overview]
Message-ID: <5b013fa2-4ad7-5995-ae6d-52770106272a@quicinc.com> (raw)
In-Reply-To: <20220923115119.2035603-1-ming.lei@redhat.com>

Hi,

On 9/23/2022 5:21 PM, Ming Lei wrote:
> cgroup has to be one kernfs dir, otherwise kernel panic is caused,
> especially cgroup id is provide from userspace.
> 
> Reported-by: Marco Patalano <mpatalan@redhat.com>
> Fixes: 6b658c4863c1 ("scsi: cgroup: Add cgroup_get_from_id()")
> Cc: Muneendra <muneendra.kumar@broadcom.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>   kernel/cgroup/cgroup.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index e4bb5d57f4d1..5f2090d051ac 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -6049,6 +6049,9 @@ struct cgroup *cgroup_get_from_id(u64 id)
>   	if (!kn)
>   		goto out;
>   
> +	if (kernfs_type(kn) != KERNFS_DIR)
> +		goto put;
> +
>   	rcu_read_lock();
>   
>   	cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
> @@ -6056,7 +6059,7 @@ struct cgroup *cgroup_get_from_id(u64 id)
>   		cgrp = NULL;
>   
>   	rcu_read_unlock();
> -
> +put:
>   	kernfs_put(kn);
>   out:
>   	return cgrp;

Good catch.

Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>

-Mukesh

  reply	other threads:[~2022-09-23 15:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 11:51 [PATCH] cgroup: fix cgroup_get_from_id Ming Lei
2022-09-23 15:43 ` Mukesh Ojha [this message]
     [not found] ` <20220923115119.2035603-1-ming.lei-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-09-23 17:29   ` Tejun Heo
     [not found]     ` <Yy3tEKSV+vg6swOd-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-09-23 17:31       ` [PATCH cgroup/for-6.1] cgroup: Make cgroup_get_from_id() prettier Tejun Heo
     [not found]         ` <Yy3tjvIGd2j4wnSw-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-09-28 11:38           ` Michal Koutný

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=5b013fa2-4ad7-5995-ae6d-52770106272a@quicinc.com \
    --to=quic_mojha@quicinc.com \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=mpatalan@redhat.com \
    --cc=muneendra.kumar@broadcom.com \
    --cc=tj@kernel.org \
    /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