* [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name
@ 2022-08-01 13:24 Manu Bretelle
2022-08-01 21:01 ` Jiri Olsa
2022-08-04 21:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Manu Bretelle @ 2022-08-01 13:24 UTC (permalink / raw)
To: bpf, andrii, quentin
bpftool was limiting the length of names to BPF_OBJ_NAME_LEN in prog_parse
fds.
Since commit b662000aff84 ("bpftool: Adding support for BTF program names")
we can get the full program name from BTF.
This patch removes the restriction of name length when running `bpftool
prog show name ${name}`.
Test:
Tested against some internal program names that were longer than
`BPF_OBJ_NAME_LEN`, here a redacted example of what was ran to test.
# previous behaviour
$ sudo bpftool prog show name some_long_program_name
Error: can't parse name
# with the patch
$ sudo ./bpftool prog show name some_long_program_name
123456789: tracing name some_long_program_name tag taghexa gpl ....
...
...
...
# too long
sudo ./bpftool prog show name $(python3 -c 'print("A"*128)')
Error: can't parse name
# not too long but no match
$ sudo ./bpftool prog show name $(python3 -c 'print("A"*127)')
Signed-off-by: Manu Bretelle <chantr4@gmail.com>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
---
v1 -> v2:
* Fix commit message to follow patch submission guidelines
* use strncmp instead of strcmp
* reintroduce arg length check against MAX_PROG_FULL_NAME
v2 -> v3:
* Fix alignment with opening parenthesis
---
tools/bpf/bpftool/common.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 067e9ea59e3b..8727765add88 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -722,6 +722,7 @@ print_all_levels(__maybe_unused enum libbpf_print_level level,
static int prog_fd_by_nametag(void *nametag, int **fds, bool tag)
{
+ char prog_name[MAX_PROG_FULL_NAME];
unsigned int id = 0;
int fd, nb_fds = 0;
void *tmp;
@@ -754,12 +755,20 @@ static int prog_fd_by_nametag(void *nametag, int **fds, bool tag)
goto err_close_fd;
}
- if ((tag && memcmp(nametag, info.tag, BPF_TAG_SIZE)) ||
- (!tag && strncmp(nametag, info.name, BPF_OBJ_NAME_LEN))) {
+ if (tag && memcmp(nametag, info.tag, BPF_TAG_SIZE)) {
close(fd);
continue;
}
+ if (!tag) {
+ get_prog_full_name(&info, fd, prog_name,
+ sizeof(prog_name));
+ if (strncmp(nametag, prog_name, sizeof(prog_name))) {
+ close(fd);
+ continue;
+ }
+ }
+
if (nb_fds > 0) {
tmp = realloc(*fds, (nb_fds + 1) * sizeof(int));
if (!tmp) {
@@ -820,7 +829,7 @@ int prog_parse_fds(int *argc, char ***argv, int **fds)
NEXT_ARGP();
name = **argv;
- if (strlen(name) > BPF_OBJ_NAME_LEN - 1) {
+ if (strlen(name) > MAX_PROG_FULL_NAME - 1) {
p_err("can't parse name");
return -1;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name
2022-08-01 13:24 [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name Manu Bretelle
@ 2022-08-01 21:01 ` Jiri Olsa
2022-08-04 21:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2022-08-01 21:01 UTC (permalink / raw)
To: Manu Bretelle; +Cc: bpf, andrii, quentin
On Mon, Aug 01, 2022 at 06:24:09AM -0700, Manu Bretelle wrote:
> bpftool was limiting the length of names to BPF_OBJ_NAME_LEN in prog_parse
> fds.
>
> Since commit b662000aff84 ("bpftool: Adding support for BTF program names")
> we can get the full program name from BTF.
>
> This patch removes the restriction of name length when running `bpftool
> prog show name ${name}`.
>
> Test:
> Tested against some internal program names that were longer than
> `BPF_OBJ_NAME_LEN`, here a redacted example of what was ran to test.
>
> # previous behaviour
> $ sudo bpftool prog show name some_long_program_name
> Error: can't parse name
> # with the patch
> $ sudo ./bpftool prog show name some_long_program_name
> 123456789: tracing name some_long_program_name tag taghexa gpl ....
> ...
> ...
> ...
> # too long
> sudo ./bpftool prog show name $(python3 -c 'print("A"*128)')
> Error: can't parse name
> # not too long but no match
> $ sudo ./bpftool prog show name $(python3 -c 'print("A"*127)')
>
> Signed-off-by: Manu Bretelle <chantr4@gmail.com>
>
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>
tested on tetragon programs ;-)
Tested-by: Jiri Olsa <jolsa@kernel.org>
jirka
>
> ---
>
> v1 -> v2:
> * Fix commit message to follow patch submission guidelines
> * use strncmp instead of strcmp
> * reintroduce arg length check against MAX_PROG_FULL_NAME
>
> v2 -> v3:
> * Fix alignment with opening parenthesis
> ---
> tools/bpf/bpftool/common.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
> index 067e9ea59e3b..8727765add88 100644
> --- a/tools/bpf/bpftool/common.c
> +++ b/tools/bpf/bpftool/common.c
> @@ -722,6 +722,7 @@ print_all_levels(__maybe_unused enum libbpf_print_level level,
>
> static int prog_fd_by_nametag(void *nametag, int **fds, bool tag)
> {
> + char prog_name[MAX_PROG_FULL_NAME];
> unsigned int id = 0;
> int fd, nb_fds = 0;
> void *tmp;
> @@ -754,12 +755,20 @@ static int prog_fd_by_nametag(void *nametag, int **fds, bool tag)
> goto err_close_fd;
> }
>
> - if ((tag && memcmp(nametag, info.tag, BPF_TAG_SIZE)) ||
> - (!tag && strncmp(nametag, info.name, BPF_OBJ_NAME_LEN))) {
> + if (tag && memcmp(nametag, info.tag, BPF_TAG_SIZE)) {
> close(fd);
> continue;
> }
>
> + if (!tag) {
> + get_prog_full_name(&info, fd, prog_name,
> + sizeof(prog_name));
> + if (strncmp(nametag, prog_name, sizeof(prog_name))) {
> + close(fd);
> + continue;
> + }
> + }
> +
> if (nb_fds > 0) {
> tmp = realloc(*fds, (nb_fds + 1) * sizeof(int));
> if (!tmp) {
> @@ -820,7 +829,7 @@ int prog_parse_fds(int *argc, char ***argv, int **fds)
> NEXT_ARGP();
>
> name = **argv;
> - if (strlen(name) > BPF_OBJ_NAME_LEN - 1) {
> + if (strlen(name) > MAX_PROG_FULL_NAME - 1) {
> p_err("can't parse name");
> return -1;
> }
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name
2022-08-01 13:24 [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name Manu Bretelle
2022-08-01 21:01 ` Jiri Olsa
@ 2022-08-04 21:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-04 21:50 UTC (permalink / raw)
To: Manu Bretelle; +Cc: bpf, andrii, quentin
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 1 Aug 2022 06:24:09 -0700 you wrote:
> bpftool was limiting the length of names to BPF_OBJ_NAME_LEN in prog_parse
> fds.
>
> Since commit b662000aff84 ("bpftool: Adding support for BTF program names")
> we can get the full program name from BTF.
>
> This patch removes the restriction of name length when running `bpftool
> prog show name ${name}`.
>
> [...]
Here is the summary with links:
- [bpf-next,v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name
https://git.kernel.org/bpf/bpf-next/c/d55dfe587bc0
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:[~2022-08-04 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01 13:24 [PATCH bpf-next v3] bpftool: Remove BPF_OBJ_NAME_LEN restriction when looking up bpf program by name Manu Bretelle
2022-08-01 21:01 ` Jiri Olsa
2022-08-04 21:50 ` 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;
as well as URLs for NNTP newsgroup(s).