From: Hou Tao <houtao@huaweicloud.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <martin.lau@linux.dev>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
Hao Luo <haoluo@google.com>,
Yonghong Song <yonghong.song@linux.dev>,
Daniel Borkmann <daniel@iogearbox.net>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
xingwei lee <xrivendell7@gmail.com>,
houtao1@huawei.com
Subject: Re: [PATCH bpf-next v2 2/4] bpf: Limit the number of kprobes when attaching program to multiple kprobes
Date: Thu, 14 Dec 2023 09:00:57 +0800 [thread overview]
Message-ID: <faf3159c-7479-e2fb-e68b-b173a1cb8b88@huaweicloud.com> (raw)
In-Reply-To: <CAEf4BzZerWpU-GW8iqZYHue5qbTrdWXZp1WKvrkxLkDj1y2Lww@mail.gmail.com>
Hi,
On 12/14/2023 7:32 AM, Andrii Nakryiko wrote:
> On Wed, Dec 13, 2023 at 3:24 AM Hou Tao <houtao@huaweicloud.com> wrote:
>> From: Hou Tao <houtao1@huawei.com>
>>
>> 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().
>>
>> Fixes: 0dcac2725406 ("bpf: Add multi kprobe link")
>> Signed-off-by: Hou Tao <houtao1@huawei.com>
>> ---
>> kernel/trace/bpf_trace.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
>> index 2d1201f7b554..944678529f5c 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -43,6 +43,7 @@
>> rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
>>
>> #define MAX_UPROBE_MULTI_CNT (1U << 20)
>> +#define MAX_KPROBE_MULTI_CNT (1U << 20)
>>
>> #ifdef CONFIG_MODULES
>> struct bpf_trace_module {
>> @@ -2970,7 +2971,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
>> return -EINVAL;
>>
>> cnt = attr->link_create.kprobe_multi.cnt;
>> - if (!cnt)
>> + if (!cnt || cnt > MAX_KPROBE_MULTI_CNT)
>> return -EINVAL;
> let's return -E2BIG for `cnt > MAX` cases? Same in another patch
Good point. Will do in v3.
>> size = cnt * sizeof(*addrs);
>> --
>> 2.29.2
>>
next prev parent reply other threads:[~2023-12-14 1:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 11:25 [PATCH bpf-next v2 0/4] bpf: Fix warnings in kvmalloc_node() Hou Tao
2023-12-13 11:25 ` [PATCH bpf-next v2 1/4] bpf: Limit the number of uprobes when attaching program to multiple uprobes Hou Tao
2023-12-13 11:25 ` [PATCH bpf-next v2 2/4] bpf: Limit the number of kprobes when attaching program to multiple kprobes Hou Tao
2023-12-13 23:32 ` Andrii Nakryiko
2023-12-14 1:00 ` Hou Tao [this message]
2023-12-13 11:25 ` [PATCH bpf-next v2 3/4] selftests/bpf: Add test for abnormal cnt during multi-uprobe attachment Hou Tao
2023-12-13 14:43 ` Jiri Olsa
2023-12-14 1:02 ` Hou Tao
2023-12-13 11:25 ` [PATCH bpf-next v2 4/4] selftests/bpf: Add test for abnormal cnt during multi-kprobe attachment Hou Tao
2023-12-13 23:33 ` Andrii Nakryiko
2023-12-14 1:44 ` Hou Tao
2023-12-14 4:26 ` Andrii Nakryiko
2023-12-13 14:42 ` [PATCH bpf-next v2 0/4] bpf: Fix warnings in kvmalloc_node() Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=faf3159c-7479-e2fb-e68b-b173a1cb8b88@huaweicloud.com \
--to=houtao@huaweicloud.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=houtao1@huawei.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=xrivendell7@gmail.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.