summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartynas Pumputis <m@lambda.lt>2021-07-05 14:43:07 +0200
committerStephen Hemminger <stephen@networkplumber.org>2021-07-06 16:59:39 -0700
commit83d4d61bc90e38eaf483f8c6f94f3f7059f07bc9 (patch)
treec98c201c8e23bab4bd1a82b5460337fbd82f5e78
parent02c06ffc13b40da269584eff42eb850b4d54c921 (diff)
downloadiproute2-83d4d61bc90e38eaf483f8c6f94f3f7059f07bc9.tar.gz
libbpf: fix attach of prog with multiple sections
When BPF programs which consists of multiple executable sections via iproute2+libbpf (configured with LIBBPF_FORCE=on), we noticed that a wrong section can be attached to a device. E.g.: # tc qdisc replace dev lxc_health clsact # tc filter replace dev lxc_health ingress prio 1 \ handle 1 bpf da obj bpf_lxc.o sec from-container # tc filter show dev lxc_health ingress filter protocol all pref 1 bpf chain 0 filter protocol all pref 1 bpf chain 0 handle 0x1 bpf_lxc.o:[__send_drop_notify] <-- WRONG SECTION direct-action not_in_hw id 38 tag 7d891814eda6809e jited After taking a closer look into load_bpf_object() in lib/bpf_libbpf.c, we noticed that the filter used in the program iterator does not check whether a program section name matches a requested section name (cfg->section). This can lead to a wrong prog FD being used to attach the program. Fixes: 6d61a2b55799 ("lib: add libbpf support") Signed-off-by: Martynas Pumputis <m@lambda.lt> Acked-by: Hangbin Liu <haliu@redhat.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--lib/bpf_libbpf.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/bpf_libbpf.c b/lib/bpf_libbpf.c
index 864f8c35..dbec2cb5 100644
--- a/lib/bpf_libbpf.c
+++ b/lib/bpf_libbpf.c
@@ -268,10 +268,12 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
}
bpf_object__for_each_program(p, obj) {
+ bool prog_to_attach = !prog && cfg->section &&
+ !strcmp(get_bpf_program__section_name(p), cfg->section);
+
/* Only load the programs that will either be subsequently
* attached or inserted into a tail call map */
- if (find_legacy_tail_calls(p, obj) < 0 && cfg->section &&
- strcmp(get_bpf_program__section_name(p), cfg->section)) {
+ if (find_legacy_tail_calls(p, obj) < 0 && !prog_to_attach) {
ret = bpf_program__set_autoload(p, false);
if (ret)
return -EINVAL;
@@ -280,7 +282,8 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
bpf_program__set_type(p, cfg->type);
bpf_program__set_ifindex(p, cfg->ifindex);
- if (!prog)
+
+ if (prog_to_attach)
prog = p;
}