From: Jeongjun Park <aha310510@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: alexei.starovoitov@gmail.com, andrii@kernel.org, ast@kernel.org,
bpf@vger.kernel.org, daniel@iogearbox.net, haoluo@google.com,
john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org,
linux-kernel@vger.kernel.org, martin.lau@linux.dev,
sdf@fomichev.me, song@kernel.org, yonghong.song@linux.dev
Subject: Re: [PATCH bpf] bpf: add check for invalid name in btf_name_valid_section()
Date: Fri, 30 Aug 2024 11:03:54 +0900 [thread overview]
Message-ID: <07EBE3E5-61A7-4F64-92BA-24A1DCA9583B@gmail.com> (raw)
In-Reply-To: <3a48e38f29cc8c73e36a6d3339b9303571d522a8.camel@gmail.com>
> Eduard Zingerman wrote:
>
> On Wed, 2024-08-28 at 22:45 -0700, Eduard Zingerman wrote:
>
> [...]
>
>> I will prepare a test case.
>> Probably tomorrow.
>
> Please find test in the attachment. This test triggers KASAN error
> report as in another attachment. (I enabled CONFIG_KASAN using
> menuconfig on top of regular selftest config).
>
Thank you for writing the selftest for me.
> On Fri, Aug 23, 2024 at 3:43 AM Jeongjun Park <aha310510@gmail.com> wrote:
>
> [...]
>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 520f49f422fe..5c24ea1a65a4 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -823,6 +823,9 @@ static bool btf_name_valid_section(const struct btf *btf, u32 offset)
>> const char *src = btf_str_by_offset(btf, offset);
>> const char *src_limit;
>>
>> + if (!*src)
>> + return false;
>> +
>
> I think that correct fix would be as follows:
>
> ---
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index edad152cee8e..d583d76fcace 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -820,7 +820,6 @@ static bool btf_name_valid_section(const struct btf *btf, u32 offset)
>
> /* set a limit on identifier length */
> src_limit = src + KSYM_NAME_LEN;
> - src++;
> while (*src && src < src_limit) {
> if (!isprint(*src))
> return false;
However, this patch is logically flawed.
It will return true for invalid names with
length 1 and src[0] being NULL. So I think
it's better to stick with the original patch.
>
> <bad-name-test.patch>
> <bad-name-kasan-report.txt>
next prev parent reply other threads:[~2024-08-30 2:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-23 10:43 Jeongjun Park
2024-08-29 2:36 ` Alexei Starovoitov
2024-08-29 3:45 ` Jeongjun Park
2024-08-29 5:45 ` Eduard Zingerman
2024-08-30 1:26 ` Eduard Zingerman
2024-08-30 2:03 ` Jeongjun Park [this message]
2024-08-30 9:42 ` Eduard Zingerman
2024-08-30 11:41 ` Jeongjun Park
2024-08-30 18:04 ` 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=07EBE3E5-61A7-4F64-92BA-24A1DCA9583B@gmail.com \
--to=aha310510@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@fomichev.me \
--cc=song@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
all inboxes | Powered by JetHome®