From: Waiman Long <longman@redhat.com>
To: chenridong <chenridong@huawei.com>, "Michal Koutný" <mkoutny@suse.com>
Cc: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org,
bpf@vger.kernel.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH -next] cgroup: fix uaf when proc_cpuset_show
Date: Tue, 25 Jun 2024 10:16:15 -0400 [thread overview]
Message-ID: <80e87513-aa48-4548-893e-ed339690c941@redhat.com> (raw)
In-Reply-To: <920bbfaa-bb76-4aa1-bd07-9a552e3bfdf2@huawei.com>
On 6/25/24 10:11, chenridong wrote:
>
>
> On 2024/6/25 18:10, Michal Koutný wrote:
>> Hello.
>>
>> On Tue, Jun 25, 2024 at 11:12:20AM GMT, chenridong<chenridong@huawei.com> wrote:
>>> I am considering whether the cgroup framework has a method to fix this
>>> issue, as other subsystems may also have the same underlying problem.
>>> Since the root css will not be released, but the css->cgrp will be
>>> released.
>> <del>First part is already done in
>> d23b5c5777158 ("cgroup: Make operations on the cgroup root_list RCU safe")
>> second part is that</del>
>> you need to take RCU read lock and check for NULL, similar to
>> 9067d90006df0 ("cgroup: Eliminate the need for cgroup_mutex in proc_cgroup_show()")
>>
>> Does that make sense to you?
>>
>> A Fixes: tag would be nice, it seems at least
>> a79a908fd2b08 ("cgroup: introduce cgroup namespaces")
>> played some role. (Here the RCU lock is not for cgroup_roots list but to
>> preserve the root cgrp itself css_free_rwork_fn/cgroup_destroy_root.
>>
>> HTH,
>> Michal
>
> Thank you, Michal, that is a good idea. Do you mean as below?
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>
> index c12b9fdb22a4..2ce0542067f1 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -5051,10 +5051,17 @@ int proc_cpuset_show(struct seq_file *m,
> struct pid_namespace *ns,
> if (!buf)
> goto out;
>
> + rcu_read_lock();
> + spin_lock_irq(&css_set_lock);
> css = task_get_css(tsk, cpuset_cgrp_id);
> - retval = cgroup_path_ns(css->cgroup, buf, PATH_MAX,
> - current->nsproxy->cgroup_ns);
> +
> + retval = cgroup_path_ns_locked(css->cgroup, buf, PATH_MAX,
> + current->nsproxy->cgroup_ns);
> css_put(css);
> +
> + spin_unlock_irq(&css_set_lock);
> + cgroup_unlock();
> +
> if (retval == -E2BIG)
> retval = -ENAMETOOLONG;
>
> if (retval < 0)
>
That should work. However, I would suggest that you take task_get_css()
and css_put() outside of the critical section. The task_get_css() is a
while loop that may take a while to execute and you don't want run it
with interrupt disabled.
Cheers,
Longman
next prev parent reply other threads:[~2024-06-25 14:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-22 11:38 [PATCH -next] cgroup: fix uaf when proc_cpuset_show Chen Ridong
2024-06-22 13:45 ` Markus Elfring
2024-06-24 3:34 ` chenridong
2024-06-22 15:05 ` Waiman Long
2024-06-22 20:04 ` [PATCH] cgroup/cpuset: Prevent UAF in proc_cpuset_show() Markus Elfring
2024-06-22 20:12 ` Waiman Long
2024-06-23 6:18 ` Markus Elfring
2024-06-23 16:28 ` Waiman Long
2024-06-24 2:59 ` [PATCH -next] cgroup: fix uaf when proc_cpuset_show chenridong
2024-06-24 23:59 ` Waiman Long
2024-06-25 1:46 ` chenridong
2024-06-25 2:40 ` Waiman Long
2024-06-25 3:12 ` chenridong
2024-06-25 10:10 ` Michal Koutný
[not found] ` <920bbfaa-bb76-4aa1-bd07-9a552e3bfdf2@huawei.com>
2024-06-25 14:16 ` Waiman Long [this message]
2024-06-25 14:29 ` chenridong
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=80e87513-aa48-4548-893e-ed339690c941@redhat.com \
--to=longman@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mkoutny@suse.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