mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 22:26:55 +00:00
bpf: Limit the number of kprobes when attaching program to multiple kprobes
[ Upstream commitd6d1e6c17c
] 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:0dcac27254
("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 Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
5735054af3
commit
3d83b820bf
1 changed files with 3 additions and 0 deletions
|
@ -42,6 +42,7 @@
|
||||||
rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
|
rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
|
||||||
|
|
||||||
#define MAX_UPROBE_MULTI_CNT (1U << 20)
|
#define MAX_UPROBE_MULTI_CNT (1U << 20)
|
||||||
|
#define MAX_KPROBE_MULTI_CNT (1U << 20)
|
||||||
|
|
||||||
#ifdef CONFIG_MODULES
|
#ifdef CONFIG_MODULES
|
||||||
struct bpf_trace_module {
|
struct bpf_trace_module {
|
||||||
|
@ -2897,6 +2898,8 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
|
||||||
cnt = attr->link_create.kprobe_multi.cnt;
|
cnt = attr->link_create.kprobe_multi.cnt;
|
||||||
if (!cnt)
|
if (!cnt)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
if (cnt > MAX_KPROBE_MULTI_CNT)
|
||||||
|
return -E2BIG;
|
||||||
|
|
||||||
size = cnt * sizeof(*addrs);
|
size = cnt * sizeof(*addrs);
|
||||||
addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL);
|
addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL);
|
||||||
|
|
Loading…
Reference in a new issue