Skip to contentSkip to conversation

libbpf: reject static entry-point BPF programs

PATCH Applied Andrii Nakryiko 5 participants 5 messages May 14, 2021 – May 15, 2021

Subsystems (4)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: reject static entry-point BPF programs

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.

---
 tools/lib/bpf/libbpf.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/lib/bpf/libbpf.c +5 -0
index 182bd3d3f728..e58f51b24574 100644
@@ -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);
 
Signature · 1 line
2.30.2
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrii Nakryiko

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.

Quoted 23 lines
---
 tools/lib/bpf/libbpf.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/lib/bpf/libbpf.c +5 -1
index 182bd3d3f728..e58f51b24574 100644
@@ -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

#2 lore raw
In reply to Andrii Nakryiko
Quoted 3 lines · Andrii Nakryiko

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 ?

#3 lore raw
Quoted 7 lines · Alexei Starovoitov
Quoted 3 lines · Andrii Nakryiko

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.

#4 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 8 lines · 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.

---
 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