From: Hou Tao <houtao1@huawei.com>
To: Eduard Zingerman <eddyz87@gmail.com>, Paul Moses <p@1g4.org>,
<martin.lau@linux.dev>, <ast@kernel.org>, <daniel@iogearbox.net>,
<andrii@kernel.org>, <memxor@gmail.com>, <bpf@vger.kernel.org>
Cc: <song@kernel.org>, <yonghong.song@linux.dev>, <jolsa@kernel.org>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH bpf] bpf: Validate BTF repeated field counts before expansion
Date: Wed, 10 Jun 2026 10:13:49 +0800 [thread overview]
Message-ID: <53d437cb-e2f9-ca99-4242-6a985393ceed@huawei.com> (raw)
In-Reply-To: <189a79443144cacf4a257f0627586f917d8d18a2.camel@gmail.com>
On 6/9/2026 4:01 AM, Eduard Zingerman wrote:
> On Fri, 2026-06-05 at 23:43 +0000, Paul Moses wrote:
>> btf_parse_struct_metas() walks user-supplied BTF during BPF_BTF_LOAD,
>> and btf_repeat_fields() expands repeatable fields from array elements
>> into the fixed BTF_FIELDS_MAX scratch array used by btf_parse_fields().
>>
>> The remaining-capacity check performs the expanded field count calculation
>> in u32. A malformed BTF can wrap that calculation, causing the check to
>> pass even when the expanded field count exceeds the scratch array
>> capacity. The following memcpy() can then write past the end of the
>> array.
>>
>> Use checked addition and multiplication before copying repeated fields
>> and reject impossible counts.
>>
>> Fixes: 797d73ee232d ("bpf: Check the remaining info_cnt before repeating btf fields")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Paul Moses <p@1g4.org>
>> ---
> Regardless of the sibling email I sent, I think that this is a good
> defensive practice to use check_{add,mul}_overflow() here.
There is no need for check_add_overflow here (it seems Alexi had pointed
it out as well), because it callers have already guaranteed that.
> Having said that, it would be nice to have a selftest in the patch-set.
>
> Acked-by: Eduard Zingerman <eddyz87@gmail.com>
>
> [...]
> .
prev parent reply other threads:[~2026-06-10 2:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 23:43 [PATCH bpf] bpf: Validate BTF repeated field counts before expansion Paul Moses
2026-06-07 8:59 ` Kumar Kartikeya Dwivedi
2026-06-07 10:11 ` Paul Moses
2026-06-07 11:08 ` Kumar Kartikeya Dwivedi
2026-06-07 17:53 ` Paul Moses
2026-06-08 19:59 ` Eduard Zingerman
2026-06-09 1:30 ` Hou Tao
2026-06-09 6:25 ` Eduard Zingerman
2026-06-07 16:55 ` Alexei Starovoitov
2026-06-08 20:01 ` Eduard Zingerman
2026-06-09 8:43 ` Kumar Kartikeya Dwivedi
2026-06-10 2:13 ` Hou Tao [this message]
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=53d437cb-e2f9-ca99-4242-6a985393ceed@huawei.com \
--to=houtao1@huawei.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=p@1g4.org \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=yonghong.song@linux.dev \
/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