[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220322112843.6687-1-hanyihao@vivo.com>
Date: Tue, 22 Mar 2022 04:28:43 -0700
From: Yihao Han <hanyihao@...o.com>
To: Steven Rostedt <rostedt@...dmis.org>,
Ingo Molnar <mingo@...hat.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, netdev@...r.kernel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: kernel@...o.com, Yihao Han <hanyihao@...o.com>
Subject: [PATCH] bpf: use vmemdup_user instead of kvmalloc and copy_from_user
fix memdup_user.cocci warning:
kernel/trace/bpf_trace.c:2450:12-20: WARNING opportunity
for vmemdup_user
Signed-off-by: Yihao Han <hanyihao@...o.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 7fa2ebc07f60..aff2461c1ea2 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2447,13 +2447,9 @@ 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;
- goto error;
- }
- if (copy_from_user(cookies, ucookies, size)) {
- err = -EFAULT;
+ cookies = vmemdup_user(ucookies, size);
+ if (IS_ERR(cookies)) {
+ err = PTR_ERR(cookies);
goto error;
}
}
--
2.17.1
Powered by blists - more mailing lists