From: Martin KaFai Lau <martin.lau@linux.dev>
To: Yonghong Song <yhs@meta.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v8 4/4] selftests/bpf: Add tests for bpf_rcu_read_lock()
Date: Tue, 22 Nov 2022 17:39:25 -0800 [thread overview]
Message-ID: <ac70f574-4023-664e-b711-e0d3b18117fd@linux.dev> (raw)
In-Reply-To: <b1b8d321-1c3a-ca41-707f-95b3cef7f124@meta.com>
On 11/22/22 5:13 PM, Yonghong Song wrote:
>
>
> On 11/22/22 4:56 PM, Martin KaFai Lau wrote:
>> On 11/22/22 11:53 AM, Yonghong Song wrote:
>>> +SEC("?fentry.s/" SYS_PREFIX "sys_nanosleep")
>>> +int task_acquire(void *ctx)
>>> +{
>>> + struct task_struct *task, *real_parent;
>>> +
>>> + task = bpf_get_current_task_btf();
>>> + bpf_rcu_read_lock();
>>> + real_parent = task->real_parent;
>>> + /* acquire a reference which can be used outside rcu read lock region */
>>> + real_parent = bpf_task_acquire(real_parent);
>> Does the bpf_task_acquire() kfunc need a change to do refcount_inc_not_zero()
>> and KF_RET_NULL?
>
> We have this definition in kernel:
> BTF_ID_FLAGS(func, bpf_task_acquire, KF_ACQUIRE | KF_TRUSTED_ARGS)
>
> So the argument is trusted args so, either marked as PTR_TRUSTED/MEM_ALLOC or
> have a reference acquired already, so
> I guess we should be fine here.
The verifier part is fine on {KF_TRUSTED_ARGS, PTR_TRUSTED}.
iiuc, PTR_TRUSTED means the kfunc can safely dereference the pointer because the
ptr has not been freed yet but does not mean its refcnt > 0 and not on its way
to be freed after the rcu gp.
If real_parent's refcnt is 0 here, bpf_task_acquire() will resurrect a task
which is on its way to be freed and the task can be stored in a map, so a UAF.
next prev parent reply other threads:[~2022-11-23 1:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 19:53 [PATCH bpf-next v8 0/4] bpf: Add bpf_rcu_read_lock() support Yonghong Song
2022-11-22 19:53 ` [PATCH bpf-next v8 1/4] compiler_types: Define __rcu as __attribute__((btf_type_tag("rcu"))) Yonghong Song
2022-11-22 19:53 ` [PATCH bpf-next v8 2/4] bpf: Introduce might_sleep field in bpf_func_proto Yonghong Song
2022-11-22 19:53 ` [PATCH bpf-next v8 3/4] bpf: Add kfunc bpf_rcu_read_lock/unlock() Yonghong Song
2022-11-23 0:24 ` Martin KaFai Lau
2022-11-23 1:06 ` Yonghong Song
2022-11-23 1:19 ` Martin KaFai Lau
2022-11-23 1:24 ` Yonghong Song
2022-11-22 19:53 ` [PATCH bpf-next v8 4/4] selftests/bpf: Add tests for bpf_rcu_read_lock() Yonghong Song
2022-11-23 0:56 ` Martin KaFai Lau
2022-11-23 1:13 ` Yonghong Song
2022-11-23 1:39 ` Martin KaFai Lau [this message]
2022-11-23 1:52 ` Martin KaFai Lau
[not found] ` <SN6PR1501MB20649F820B6FFE58166817E5CA0C9@SN6PR1501MB2064.namprd15.prod.outlook.com>
2022-11-23 23:13 ` Martin KaFai Lau
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=ac70f574-4023-664e-b711-e0d3b18117fd@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
--cc=yhs@meta.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