mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Ridong <chenridong@huaweicloud.com>
To: "Tejun Heo" <tj@kernel.org>, "Michal Koutný" <mkoutny@suse.com>
Cc: Chen Ridong <chenridong@huaweicloud.com>,
	lizefan.x@bytedance.com, hannes@cmpxchg.org, longman@redhat.com,
	john.fastabend@gmail.com, roman.gushchin@linux.dev,
	quanyang.wang@windriver.com, ast@kernel.org,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, wangweiyang2@huawei.com
Subject: Re: [PATCH] cgroup/bpf: fix NULL pointer dereference at cgroup_bpf_offline
Date: Thu, 17 Oct 2024 20:17:58 +0800	[thread overview]
Message-ID: <12f57831-6b88-49db-bfb6-eabfc5e1d40c@huaweicloud.com> (raw)
In-Reply-To: <Zw_yHEJCBwtYFJoR@slm.duckdns.org>



On 2024/10/17 1:04, Tejun Heo wrote:
> On Wed, Oct 16, 2024 at 03:13:52PM +0200, Michal Koutný wrote:
>> Hello.
>>
>> On Wed, Oct 16, 2024 at 09:36:33AM GMT, Chen Ridong <chenridong@huaweicloud.com> wrote:
>>> As mentioned above, when cgroup_bpf_inherit returns an error in
>>> cgroup_setup_root, cgrp->bpf.refcnt has been exited. If cgrp->bpf.refcnt is
>>> killed again in the cgroup_kill_sb function, the data of cgrp->bpf.refcnt
>>> may have become NULL, leading to NULL pointer dereference.
>>>
>>> To fix this issue, goto err when cgroup_bpf_inherit returns an error.
>>> Additionally, if cgroup_bpf_inherit returns an error after rebinding
>>> subsystems, the root_cgrp->self.refcnt is exited, which leads to
>>> cgroup1_root_to_use return 1 (restart) when subsystems is  mounted next.
>>> This is due to a failure trying to get the refcnt(the root is root_cgrp,
>>> without rebinding back to cgrp_dfl_root). So move the call to
>>> cgroup_bpf_inherit above rebind_subsystems in the cgroup_setup_root.
>>>
>>> Fixes: 04f8ef5643bc ("cgroup: Fix memory leak caused by missing cgroup_bpf_offline")
>>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>>
>> Hm, I always thought that BPF progs can only be attached to the default
>> hierarchy (cgroup_bpf_prog_attach/cgroup_get_from_fd should prevent
>> that).
>>
>> Thus I wonder whether cgroup_bpf_inherit (which is more like
>> cgroup_bpf_init in this case) needs to be called no v1 roots at all (and
>> with such a change, 04f8ef5643bc could be effectively reverted too).
>>
>> Or can bpf data be used on v1 hierarchies somehow?
> 
> We relaxed some of the usages (see cgroup_v1v2_get_from_fd()) but cgroup BPF
> progs can only be attached to v2.
> 
> Thanks.
> 

So, should commit 04f8ef5643bc ("cgroup: Fix memory leak caused by 
missing cgroup_bpf_offline") be reverted, and should cgroup_bpf_inherit 
be only called in v2?
Have I understood this correctly?

Best regards,
Ridong


  reply	other threads:[~2024-10-17 12:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16  9:36 Chen Ridong
2024-10-16 13:13 ` Michal Koutný
2024-10-16 17:04   ` Tejun Heo
2024-10-17 12:17     ` Chen Ridong [this message]
2024-10-17 21:14       ` 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=12f57831-6b88-49db-bfb6-eabfc5e1d40c@huaweicloud.com \
    --to=chenridong@huaweicloud.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=john.fastabend@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=longman@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=quanyang.wang@windriver.com \
    --cc=roman.gushchin@linux.dev \
    --cc=tj@kernel.org \
    --cc=wangweiyang2@huawei.com \
    /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

all inboxes | Powered by JetHome®