[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <bd8a6dc3e52369a30c73578ea1144a48f736f393.camel@gmail.com>
Date: Fri, 30 Aug 2024 02:42:19 -0700
From: Eduard Zingerman <eddyz87@...il.com>
To: Jeongjun Park <aha310510@...il.com>
Cc: alexei.starovoitov@...il.com, andrii@...nel.org, ast@...nel.org,
bpf@...r.kernel.org, daniel@...earbox.net, haoluo@...gle.com,
john.fastabend@...il.com, jolsa@...nel.org, kpsingh@...nel.org,
linux-kernel@...r.kernel.org, martin.lau@...ux.dev, sdf@...ichev.me,
song@...nel.org, yonghong.song@...ux.dev
Subject: Re: [PATCH bpf] bpf: add check for invalid name in
btf_name_valid_section()
On Fri, 2024-08-30 at 11:03 +0900, Jeongjun Park wrote:
[...]
> > 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.
Fair enough, however the isprint check should be done for the first character.
So the full fix is a combination :)
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -818,9 +818,11 @@ 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;
+
/* set a limit on identifier length */
src_limit = src + KSYM_NAME_LEN;
- src++;
while (*src && src < src_limit) {
if (!isprint(*src))
return false;
And corresponding test cases (tools/testing/selftests/bpf/prog_tests/btf.c):
{
.descr = "datasec: name with non-printable first char not is ok",
.raw_types = {
/* int */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
/* VAR x */ /* [2] */
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
BTF_VAR_STATIC,
/* DATASEC ?.data */ /* [3] */
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
BTF_VAR_SECINFO_ENC(2, 0, 4),
BTF_END_RAW,
},
BTF_STR_SEC("\0x\0\7foo"),
.err_str = "Invalid name",
.btf_load_err = true,
},{
.descr = "datasec: name '\\0' is not ok",
.raw_types = {
/* int */
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
/* VAR x */ /* [2] */
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
BTF_VAR_STATIC,
/* DATASEC \0 */ /* [3] */
BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
BTF_VAR_SECINFO_ENC(2, 0, 4),
BTF_END_RAW,
},
BTF_STR_SEC("\0x\0"),
.err_str = "Invalid name",
.btf_load_err = true,
},
Could you please resend your patch as a patch-set fix + selftests update?
Powered by blists - more mailing lists