bpf: Limit the number of uprobes when attaching program to multiple uprobes
[linux-2.6-microblaze.git] / kernel / trace / bpf_trace.c
index 774cf47..75c05ae 100644 (file)
@@ -42,6 +42,8 @@
 #define bpf_event_rcu_dereference(p)                                   \
        rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
 
+#define MAX_UPROBE_MULTI_CNT (1U << 20)
+
 #ifdef CONFIG_MODULES
 struct bpf_trace_module {
        struct module *module;
@@ -3344,6 +3346,8 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 
        if (!upath || !uoffsets || !cnt)
                return -EINVAL;
+       if (cnt > MAX_UPROBE_MULTI_CNT)
+               return -E2BIG;
 
        uref_ctr_offsets = u64_to_user_ptr(attr->link_create.uprobe_multi.ref_ctr_offsets);
        ucookies = u64_to_user_ptr(attr->link_create.uprobe_multi.cookies);