Skip to content

Commit 8b2efe5

Browse files
Hou Taoborkmann
authored andcommitted
bpf: Limit the number of uprobes when attaching program to multiple uprobes
An abnormally big cnt may be passed to link_create.uprobe_multi.cnt, and it will trigger the following warning in kvmalloc_node(): if (unlikely(size > INT_MAX)) { WARN_ON_ONCE(!(flags & __GFP_NOWARN)); return NULL; } Fix the warning by limiting the maximal number of uprobes in bpf_uprobe_multi_link_attach(). If the number of uprobes is greater than MAX_UPROBE_MULTI_CNT, the attachment will return -E2BIG. Fixes: 89ae89f ("bpf: Add multi uprobe link") Reported-by: Xingwei Lee <[email protected]> Signed-off-by: Hou Tao <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Closes: https://lore.kernel.org/bpf/CABOYnLwwJY=yFAGie59LFsUsBAgHfroVqbzZ5edAXbFE3YiNVA@mail.gmail.com Link: https://lore.kernel.org/bpf/[email protected]
1 parent 7489723 commit 8b2efe5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/trace/bpf_trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define bpf_event_rcu_dereference(p) \
4343
rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
4444

45+
#define MAX_UPROBE_MULTI_CNT (1U << 20)
46+
4547
#ifdef CONFIG_MODULES
4648
struct bpf_trace_module {
4749
struct module *module;
@@ -3344,6 +3346,8 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
33443346

33453347
if (!upath || !uoffsets || !cnt)
33463348
return -EINVAL;
3349+
if (cnt > MAX_UPROBE_MULTI_CNT)
3350+
return -E2BIG;
33473351

33483352
uref_ctr_offsets = u64_to_user_ptr(attr->link_create.uprobe_multi.ref_ctr_offsets);
33493353
ucookies = u64_to_user_ptr(attr->link_create.uprobe_multi.cookies);

0 commit comments

Comments
 (0)