Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Limit the number of kprobes when attaching program to multiple kprobes

An abnormally big cnt may also be assigned to kprobe_multi.cnt when
attaching multiple kprobes. 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 kprobes in
bpf_kprobe_multi_link_attach(). If the number of kprobes is greater than
MAX_KPROBE_MULTI_CNT, the attachment will fail and return -E2BIG.

Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20231215100708.2265609-3-houtao@huaweicloud.com

authored by

Hou Tao and committed by
Daniel Borkmann
d6d1e6c1 8b2efe51

+3
+3
kernel/trace/bpf_trace.c
··· 43 43 rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex)) 44 44 45 45 #define MAX_UPROBE_MULTI_CNT (1U << 20) 46 + #define MAX_KPROBE_MULTI_CNT (1U << 20) 46 47 47 48 #ifdef CONFIG_MODULES 48 49 struct bpf_trace_module { ··· 2973 2972 cnt = attr->link_create.kprobe_multi.cnt; 2974 2973 if (!cnt) 2975 2974 return -EINVAL; 2975 + if (cnt > MAX_KPROBE_MULTI_CNT) 2976 + return -E2BIG; 2976 2977 2977 2978 size = cnt * sizeof(*addrs); 2978 2979 addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL);