From: Song Liu <songliubraving@fb.com>
To: Wan Jiabing <wanjiabing@vivo.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>, Martin Lau <kafai@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] bpf: use vmemdup_user instead of kvmalloc and copy_from_user
Date: Thu, 12 May 2022 16:45:24 +0000 [thread overview]
Message-ID: <4C02E841-C402-4862-9C54-FBD5686E2FB4@fb.com> (raw)
In-Reply-To: <20220512141710.116135-4-wanjiabing@vivo.com>
> On May 12, 2022, at 7:17 AM, Wan Jiabing <wanjiabing@vivo.com> wrote:
>
> Fix following coccicheck warning:
> ./kernel/trace/bpf_trace.c:2488:12-20: WARNING opportunity for vmemdup_user
>
> Use vmemdup_user instead of kvmalloc and copy_from_user.
>
> Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
> ---
> kernel/trace/bpf_trace.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 1b0db8f78dc8..48fc97a6db50 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2483,15 +2483,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
>
> ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies);
> if (ucookies) {
> - cookies = kvmalloc(size, GFP_KERNEL);
> - if (!cookies) {
> - err = -ENOMEM;
> + cookies = vmemdup_user(ucookies, size);
vmemdup_user() uses GFP_USER, so this is a behavior change.
Song
> + if (IS_ERR(cookies)) {
> + err = PTR_ERR(cookies);
> goto error_addrs;
> }
> - if (copy_from_user(cookies, ucookies, size)) {
> - err = -EFAULT;
> - goto error_cookies;
> - }
> }
>
> link = kzalloc(sizeof(*link), GFP_KERNEL);
> --
> 2.35.1
>
prev parent reply other threads:[~2022-05-12 16:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-12 14:17 [PATCH 0/3] bpf: optimize the bpf_kprobe_multi_link_attach function Wan Jiabing
2022-05-12 14:17 ` [PATCH 1/3] bpf: use 'error_xxx' tags in bpf_kprobe_multi_link_attach Wan Jiabing
2022-05-12 16:40 ` Song Liu
2022-05-12 17:05 ` David Vernet
2022-05-12 14:17 ` [PATCH 2/3] bpf: simplify if-if to if " Wan Jiabing
2022-05-12 16:44 ` Song Liu
2022-05-12 14:17 ` [PATCH 3/3] bpf: use vmemdup_user instead of kvmalloc and copy_from_user Wan Jiabing
2022-05-12 16:45 ` Song Liu [this message]
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=4C02E841-C402-4862-9C54-FBD5686E2FB4@fb.com \
--to=songliubraving@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=wanjiabing@vivo.com \
--cc=yhs@fb.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®