* [PATCH bpf-next v4] bpftool: Check map name length when map create
@ 2025-02-12 12:45 Rong Tao
2025-02-12 14:33 ` Quentin Monnet
2025-02-14 4:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Rong Tao @ 2025-02-12 12:45 UTC (permalink / raw)
To: andrii, qmo, ast
Cc: rongtao, rtoax, Daniel Borkmann, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
open list:BPF [TOOLING] (bpftool), open list
From: Rong Tao <rongtao@cestc.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 warning is
reported. This submission checks the length of the map name.
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
v3: https://lore.kernel.org/lkml/tencent_AF066A426F591F977D2A73AF00A34A883808@qq.com/
v2: https://lore.kernel.org/lkml/tencent_26592A2BAF08A3A688A50600421559929708@qq.com/
v1: https://lore.kernel.org/lkml/tencent_1C4444032C2188ACD04B4995B0D78F510607@qq.com/
---
tools/bpf/bpftool/map.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index ed4a9bd82931..81cc668b4b05 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -1270,6 +1270,10 @@ static int do_create(int argc, char **argv)
} else if (is_prefix(*argv, "name")) {
NEXT_ARG();
map_name = GET_ARG();
+ if (strlen(map_name) > BPF_OBJ_NAME_LEN - 1) {
+ p_info("Warning: map name is longer than %u characters, it will be truncated.",
+ BPF_OBJ_NAME_LEN - 1);
+ }
} else if (is_prefix(*argv, "key")) {
if (parse_u32_arg(&argc, &argv, &key_size,
"key size"))
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next v4] bpftool: Check map name length when map create
2025-02-12 12:45 [PATCH bpf-next v4] bpftool: Check map name length when map create Rong Tao
@ 2025-02-12 14:33 ` Quentin Monnet
2025-02-14 4:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Quentin Monnet @ 2025-02-12 14:33 UTC (permalink / raw)
To: Rong Tao, andrii, ast
Cc: rongtao, Daniel Borkmann, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, Jiri Olsa,
open list:BPF [TOOLING] (bpftool), open list
2025-02-12 20:45 UTC+0800 ~ Rong Tao <rtoax@foxmail.com>
> From: Rong Tao <rongtao@cestc.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 warning is
> reported. This submission checks the length of the map name.
>
> Reviewed-by: Quentin Monnet <qmo@kernel.org>
> Signed-off-by: Rong Tao <rongtao@cestc.cn>
Looks good to me, thank you!
Quentin
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next v4] bpftool: Check map name length when map create
2025-02-12 12:45 [PATCH bpf-next v4] bpftool: Check map name length when map create Rong Tao
2025-02-12 14:33 ` Quentin Monnet
@ 2025-02-14 4:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-02-14 4:20 UTC (permalink / raw)
To: Rong Tao
Cc: andrii, qmo, ast, rongtao, daniel, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, bpf,
linux-kernel
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 12 Feb 2025 20:45:52 +0800 you wrote:
> From: Rong Tao <rongtao@cestc.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));
> }
> }
>
> [...]
Here is the summary with links:
- [bpf-next,v4] bpftool: Check map name length when map create
https://git.kernel.org/bpf/bpf-next/c/a4585442ade5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-14 4:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 12:45 [PATCH bpf-next v4] bpftool: Check map name length when map create Rong Tao
2025-02-12 14:33 ` Quentin Monnet
2025-02-14 4:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox