From: Eduard Zingerman <eddyz87@gmail.com>
To: Hou Tao <houtao@huaweicloud.com>, bpf@vger.kernel.org
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
Hao Luo <haoluo@google.com>,
Yonghong Song <yonghong.song@linux.dev>,
Daniel Borkmann <daniel@iogearbox.net>,
KP Singh <kpsingh@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Kui-Feng Lee <thinker.li@gmail.com>,
houtao1@huawei.com, xukuohai@huawei.com
Subject: Re: [RESEND][PATCH bpf 1/2] bpf: Check the remaining info_cnt before repeating btf fields
Date: Wed, 11 Sep 2024 20:03:22 -0700 [thread overview]
Message-ID: <9a7d4f5ff0ea8af86a6d7a5b630c38cb7ecc2075.camel@gmail.com> (raw)
In-Reply-To: <99c3bd09-054a-2c7c-7c6f-f1c613444f1f@huaweicloud.com>
On Thu, 2024-09-12 at 09:20 +0800, Hou Tao wrote:
[...]
> > > @@ -3592,6 +3592,12 @@ static int btf_find_nested_struct(const struct btf *btf, const struct btf_type *
> > > info[i].off += off;
> > >
> > > if (nelems > 1) {
> > > + /* The type of struct size or variable size is u32,
> > > + * so the multiplication will not overflow.
> > > + */
> > > + if (ret * nelems > info_cnt)
> > > + return -E2BIG;
> > > +
> > > err = btf_repeat_fields(info, ret, nelems - 1, t->size);
> > > if (err == 0)
> > > ret *= nelems;
> >
> > btf_repeat_fields(struct btf_field_info *info,
> > u32 field_cnt, u32 repeat_cnt, u32 elem_size)
> >
> > copies field "field_cnt * repeat_cnt" times,
> > in this case field_cnt == ret, repeat_cnt == nelems - 1,
> > should the check be "ret * (nelems - 1) > info_cnt"?
>
> No. The number of available btf_field_info is info_cnt,
> btf_find_struct_field() has already used ret fields, and there are still
> ret * (nelems - 1) fields waiting for repetition, so checking ret *
> nelems against info_cnt is correct.
Please bear with me. Here is btf_repeat_fields():
static int btf_repeat_fields(struct btf_field_info *info,
u32 field_cnt, u32 repeat_cnt, u32 elem_size)
{
u32 i, j;
u32 cur;
...
cur = field_cnt;
for (i = 0; i < repeat_cnt; i++) {
...
for (j = 0; j < field_cnt; j++)
info[cur++].off += (i + 1) * elem_size;
}
...
}
The range for 'cur' is [field_cnt .. field_cnt * repeat_cnt].
Meaning that at-least 'field_cnt * repeat_cnt' entries are necessary
in the 'info' array.
Given parameters passed to the function, this is 'ret * (nelems - 1)'.
What do I miss?
next prev parent reply other threads:[~2024-09-12 3:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 11:05 [RESEND][PATCH bpf 0/2] Check the remaining info_cnt before repeating btf fields Hou Tao
2024-09-11 11:05 ` [RESEND][PATCH bpf 1/2] bpf: " Hou Tao
2024-09-11 17:37 ` Eduard Zingerman
2024-09-12 1:20 ` Hou Tao
2024-09-12 3:03 ` Eduard Zingerman [this message]
2024-09-12 3:14 ` Eduard Zingerman
[not found] ` <CAFVMQ6Q64aFM7xCW_htrU0dpB+S+eEXYLSeUufTgg_eB5DEN4g@mail.gmail.com>
2024-09-12 19:45 ` Eduard Zingerman
2024-09-11 11:05 ` [RESEND][PATCH bpf 2/2] selftests/bpf: Add more test case for field flattening Hou Tao
2024-09-11 17:07 ` Eduard Zingerman
2024-09-12 1:05 ` Hou Tao
2024-09-12 2:31 ` Eduard Zingerman
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=9a7d4f5ff0ea8af86a6d7a5b630c38cb7ecc2075.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=houtao@huaweicloud.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=thinker.li@gmail.com \
--cc=xukuohai@huawei.com \
--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