[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <tencent_A7CAD02BDAA81222B6C184105ED6F9258706@qq.com>
Date: Wed, 12 Feb 2025 09:14:14 +0800
From: Rong Tao <rtoax@...mail.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>,
Quentin Monnet <qmo@...nel.org>
Cc: ast@...nel.org, daniel@...earbox.net, rongtao@...tc.cn,
Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau
<martin.lau@...ux.dev>, Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
"open list:BPF [TOOLING] (bpftool)" <bpf@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH bpf-next v2] bpftool: Check map name length when map
create
On 2/12/25 05:07, Andrii Nakryiko wrote:
> On Tue, Feb 11, 2025 at 2:48 AM Quentin Monnet <qmo@...nel.org> wrote:
>> 2025-02-11 18:38 UTC+0800 ~ Rong Tao <rtoax@...mail.com>
>>> From: Rong Tao <rongtao@...tc.cn>
>>>
>>> The size of struct bpf_map::name is BPF_OBJ_NAME_LEN (16).
>>>
>>> bpf(2) {
>>> map_create() {
>>> bpf_obj_name_cpy(map->name, attr->map_name, sizeof(attr->map_name));
>>> }
>>> }
>>>
>>> When specifying a map name using bpftool map create name, no error is
>>> reported if the name length is greater than 15.
>>>
>>> $ sudo bpftool map create /sys/fs/bpf/12345678901234567890 \
>>> type array key 4 value 4 entries 5 name 12345678901234567890
>>>
>>> Users will think that 12345678901234567890 is legal, but this name cannot
>>> be used to index a map.
>>>
>>> $ sudo bpftool map show name 12345678901234567890
>>> Error: can't parse name
>>>
>>> $ sudo bpftool map show
>>> ...
>>> 1249: array name 123456789012345 flags 0x0
>>> key 4B value 4B max_entries 5 memlock 304B
>>>
>>> $ sudo bpftool map show name 123456789012345
>>> 1249: array name 123456789012345 flags 0x0
>>> key 4B value 4B max_entries 5 memlock 304B
>>>
>>> The map name provided in the command line is truncated, but no error is
>>> reported. This submission checks the length of the map name.
>>>
>>> Signed-off-by: Rong Tao <rongtao@...tc.cn>
>>
>> Reviewed-by: Quentin Monnet <qmo@...nel.org>
>>
> Would it make sense to just warn but proceed with a truncated name?
> libbpf truncates the name when creating a map, but preserves the
> original name in BTF (and in memory, fetchable through
> bpf_map__name()). So from the user's perspective that map is still
> named "blah-blah-something-long", even if the kernel records just a
> prefix of that.
>
> Basically, instead of forcing users to count the first 15 characters,
> warn, but do the right thing anyways?
Yes, you're right, i'll submit v3.
Rong Tao
>
>> Thank you!
Powered by blists - more mailing lists