From: Kui-Feng Lee <sinquersw@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>, thinker.li@gmail.com
Cc: kuifeng@meta.com, bpf@vger.kernel.org, ast@kernel.org,
song@kernel.org, kernel-team@meta.com, andrii@kernel.org
Subject: Re: [PATCH bpf-next v4 2/3] bpf: Check cfi_stubs before registering a struct_ops type.
Date: Wed, 21 Feb 2024 15:13:18 -0800 [thread overview]
Message-ID: <286d36e1-1d1e-49d3-93d6-d29b402e6009@gmail.com> (raw)
In-Reply-To: <8e6e79d6-e003-446b-bc36-b6a4500f802b@linux.dev>
On 2/21/24 10:25, Martin KaFai Lau wrote:
> On 2/20/24 11:52 PM, thinker.li@gmail.com wrote:
>> From: Kui-Feng Lee <thinker.li@gmail.com>
>>
>> Recently, cfi_stubs were introduced. However, existing struct_ops types
>> that are not in the upstream may not be aware of this, resulting in
>> kernel
>> crashes. By rejecting struct_ops types that do not provide cfi_stubs
>> during
>> registration, these crashes can be avoided.
>>
>> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
>> ---
>> kernel/bpf/bpf_struct_ops.c | 17 +++++++++++++++++
>> 1 file changed, 17 insertions(+)
>>
>> diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c
>> index 0d7be97a2411..c1c502caae08 100644
>> --- a/kernel/bpf/bpf_struct_ops.c
>> +++ b/kernel/bpf/bpf_struct_ops.c
>> @@ -302,6 +302,11 @@ int bpf_struct_ops_desc_init(struct
>> bpf_struct_ops_desc *st_ops_desc,
>> }
>> sprintf(value_name, "%s%s", VALUE_PREFIX, st_ops->name);
>> + if (!st_ops->cfi_stubs) {
>> + pr_warn("struct %s has no cfi_stubs\n", st_ops->name);
>> + return -EINVAL;
>> + }
>> +
>> type_id = btf_find_by_name_kind(btf, st_ops->name,
>> BTF_KIND_STRUCT);
>> if (type_id < 0) {
>> @@ -339,6 +344,7 @@ int bpf_struct_ops_desc_init(struct
>> bpf_struct_ops_desc *st_ops_desc,
>> for_each_member(i, t, member) {
>> const struct btf_type *func_proto;
>> + u32 moff;
>> mname = btf_name_by_offset(btf, member->name_off);
>> if (!*mname) {
>> @@ -361,6 +367,17 @@ int bpf_struct_ops_desc_init(struct
>> bpf_struct_ops_desc *st_ops_desc,
>> if (!func_proto)
>> continue;
>> + moff = __btf_member_bit_offset(t, member) / 8;
>> + err = st_ops->check_member ?
>> + st_ops->check_member(t, member, NULL) : 0;
>
> I don't think it is necessary to make check_member more complicated by
> taking
> NULL prog. The struct_ops implementer then needs to handle this extra NULL
> prog case.
>
> Have you thought about Alexei's earlier suggestion in v3 to reuse the NULL
> member in cfi_stubs to flag unsupported member and remove the
> unsupported_ops[]
> from bpf_tcp_ca.c?
>
> If the verifier can consistently reject loading unsupported bpf prog, it
> will
> not reach the bpf_struct_ops_map_update_elem and then hits the NULL member
> in cfi_stubs during map_update_elem.
>
Ok! I misunderstood previously. I will go this way.
next prev parent reply other threads:[~2024-02-21 23:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 7:52 [PATCH bpf-next v4 0/3] Check cfi_stubs before registering a struct_ops type thinker.li
2024-02-21 7:52 ` [PATCH bpf-next v4 1/3] bpf, net: allow passing NULL prog to check_member thinker.li
2024-02-21 7:52 ` [PATCH bpf-next v4 2/3] bpf: Check cfi_stubs before registering a struct_ops type thinker.li
2024-02-21 18:25 ` Martin KaFai Lau
2024-02-21 23:13 ` Kui-Feng Lee [this message]
2024-02-22 1:11 ` Kui-Feng Lee
2024-02-21 7:52 ` [PATCH bpf-next v4 3/3] selftests/bpf: Test case for lacking CFI stub functions thinker.li
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=286d36e1-1d1e-49d3-93d6-d29b402e6009@gmail.com \
--to=sinquersw@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=thinker.li@gmail.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