Re: [PATCH 3/3] bpf: use vmemdup_user instead of kvmalloc and copy_from_user

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On May 12, 2022, at 7:17 AM, Wan Jiabing <wanjiabing@xxxxxxxx> 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@xxxxxxxx>
> ---
> 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
> 




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux