Skip to content

Commit 41bc46c

Browse files
olsajirianakryiko
authored andcommitted
bpf: Add override check to kprobe multi link attach
Currently the multi_kprobe link attach does not check error injection list for programs with bpf_override_return helper and allows them to attach anywhere. Adding the missing check. Fixes: 0dcac27 ("bpf: Add multi kprobe link") Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Alan Maguire <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/bpf/[email protected]
1 parent ac28b1e commit 41bc46c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

kernel/trace/bpf_trace.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,17 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
28532853
return arr.mods_cnt;
28542854
}
28552855

2856+
static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt)
2857+
{
2858+
u32 i;
2859+
2860+
for (i = 0; i < cnt; i++) {
2861+
if (!within_error_injection_list(addrs[i]))
2862+
return -EINVAL;
2863+
}
2864+
return 0;
2865+
}
2866+
28562867
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
28572868
{
28582869
struct bpf_kprobe_multi_link *link = NULL;
@@ -2930,6 +2941,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
29302941
goto error;
29312942
}
29322943

2944+
if (prog->kprobe_override && addrs_check_error_injection_list(addrs, cnt)) {
2945+
err = -EINVAL;
2946+
goto error;
2947+
}
2948+
29332949
link = kzalloc(sizeof(*link), GFP_KERNEL);
29342950
if (!link) {
29352951
err = -ENOMEM;

0 commit comments

Comments
 (0)