* [PATCH bpf-next] libbpf: reject static entry-point BPF programs
@ 2021-05-14 19:55 Andrii Nakryiko
2021-05-14 20:52 ` Song Liu
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2021-05-14 19:55 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii, kernel-team
Detect use of static entry-point BPF programs (those with SEC() markings) and
emit error message. This is similar to
c1cccec9c636 ("libbpf: Reject static maps") but for BPF programs.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/libbpf.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 182bd3d3f728..e58f51b24574 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -677,6 +677,11 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,
return -LIBBPF_ERRNO__FORMAT;
}
+ if (sec_idx != obj->efile.text_shndx && GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
+ pr_warn("sec '%s': program '%s' is static and not supported\n", sec_name, name);
+ return -ENOTSUP;
+ }
+
pr_debug("sec '%s': found program '%s' at insn offset %zu (%zu bytes), code size %zu insns (%zu bytes)\n",
sec_name, name, sec_off / BPF_INSN_SZ, sec_off, prog_sz / BPF_INSN_SZ, prog_sz);
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] libbpf: reject static entry-point BPF programs
2021-05-14 19:55 [PATCH bpf-next] libbpf: reject static entry-point BPF programs Andrii Nakryiko
@ 2021-05-14 20:52 ` Song Liu
2021-05-14 23:14 ` Alexei Starovoitov
2021-05-14 23:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2021-05-14 20:52 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, Networking, Alexei Starovoitov, Daniel Borkmann, Kernel Team
On Fri, May 14, 2021 at 1:33 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> Detect use of static entry-point BPF programs (those with SEC() markings) and
> emit error message. This is similar to
> c1cccec9c636 ("libbpf: Reject static maps") but for BPF programs.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 182bd3d3f728..e58f51b24574 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -677,6 +677,11 @@ bpf_object__add_programs(struct bpf_object *obj, Elf_Data *sec_data,
> return -LIBBPF_ERRNO__FORMAT;
> }
>
> + if (sec_idx != obj->efile.text_shndx && GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
> + pr_warn("sec '%s': program '%s' is static and not supported\n", sec_name, name);
> + return -ENOTSUP;
> + }
> +
> pr_debug("sec '%s': found program '%s' at insn offset %zu (%zu bytes), code size %zu insns (%zu bytes)\n",
> sec_name, name, sec_off / BPF_INSN_SZ, sec_off, prog_sz / BPF_INSN_SZ, prog_sz);
>
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] libbpf: reject static entry-point BPF programs
2021-05-14 19:55 [PATCH bpf-next] libbpf: reject static entry-point BPF programs Andrii Nakryiko
2021-05-14 20:52 ` Song Liu
@ 2021-05-14 23:14 ` Alexei Starovoitov
2021-05-15 5:25 ` Andrii Nakryiko
2021-05-14 23:20 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2021-05-14 23:14 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
Kernel Team
On Fri, May 14, 2021 at 1:34 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> Detect use of static entry-point BPF programs (those with SEC() markings) and
> emit error message.
Applied. I was wondering whether you've seen such combinations ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] libbpf: reject static entry-point BPF programs
2021-05-14 19:55 [PATCH bpf-next] libbpf: reject static entry-point BPF programs Andrii Nakryiko
2021-05-14 20:52 ` Song Liu
2021-05-14 23:14 ` Alexei Starovoitov
@ 2021-05-14 23:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-05-14 23:20 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, netdev, ast, daniel, kernel-team
Hello:
This patch was applied to bpf/bpf-next.git (refs/heads/master):
On Fri, 14 May 2021 12:55:34 -0700 you wrote:
> Detect use of static entry-point BPF programs (those with SEC() markings) and
> emit error message. This is similar to
> c1cccec9c636 ("libbpf: Reject static maps") but for BPF programs.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
> tools/lib/bpf/libbpf.c | 5 +++++
> 1 file changed, 5 insertions(+)
Here is the summary with links:
- [bpf-next] libbpf: reject static entry-point BPF programs
https://git.kernel.org/bpf/bpf-next/c/513f485ca516
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] 5+ messages in thread
* Re: [PATCH bpf-next] libbpf: reject static entry-point BPF programs
2021-05-14 23:14 ` Alexei Starovoitov
@ 2021-05-15 5:25 ` Andrii Nakryiko
0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2021-05-15 5:25 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Andrii Nakryiko, bpf, Network Development, Alexei Starovoitov,
Daniel Borkmann, Kernel Team
On Fri, May 14, 2021 at 4:14 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Fri, May 14, 2021 at 1:34 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> >
> > Detect use of static entry-point BPF programs (those with SEC() markings) and
> > emit error message.
>
> Applied. I was wondering whether you've seen such combinations ?
Haven't seen this anywhere in the real code, only tested locally by
adding static to one of selftests. Unlikely to break anyone, but good
to be as strict as with maps.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-05-15 5:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 19:55 [PATCH bpf-next] libbpf: reject static entry-point BPF programs Andrii Nakryiko
2021-05-14 20:52 ` Song Liu
2021-05-14 23:14 ` Alexei Starovoitov
2021-05-15 5:25 ` Andrii Nakryiko
2021-05-14 23: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;
as well as URLs for NNTP newsgroup(s).