public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Wang Yufen <wangyufen@huawei.com>
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
	andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
	yhs@fb.com, kpsingh@kernel.org, haoluo@google.com,
	jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [bpf-next] bpf: use kvmemdup_bpfptr helper
Date: Fri, 9 Sep 2022 10:27:26 -0700	[thread overview]
Message-ID: <Yxt3fnUdzDTJzUTt@google.com> (raw)
In-Reply-To: <1662721097-23793-1-git-send-email-wangyufen@huawei.com>

On 09/09, Wang Yufen wrote:
> Use kvmemdup_bpfptr helper instead of open-coding to
> simplify the code.

> Signed-off-by: Wang Yufen <wangyufen@huawei.com>
> ---
>   kernel/bpf/syscall.c | 14 ++++----------
>   1 file changed, 4 insertions(+), 10 deletions(-)

> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 4e9d4622aef7..13ce28081982 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -1413,20 +1413,14 @@ static int map_update_elem(union bpf_attr *attr,  
> bpfptr_t uattr)
>   	}

>   	value_size = bpf_map_value_size(map);
> -
> -	err = -ENOMEM;
> -	value = kvmalloc(value_size, GFP_USER | __GFP_NOWARN);
> -	if (!value)
> +	value = kvmemdup_bpfptr(uvalue, value_size);
> +	if (IS_ERR(value)) {
> +		err = PTR_ERR(value);
>   		goto free_key;
> -
> -	err = -EFAULT;
> -	if (copy_from_bpfptr(value, uvalue, value_size) != 0)
> -		goto free_value;
> +	}

>   	err = bpf_map_update_value(map, f, key, value, attr->flags);


[..]

> -free_value:
> -	kvfree(value);

And here you leak the value. We need to free it after update regardless
of error/success. That's why it is coded like that.

>   free_key:
>   	kvfree(key);
>   err_put:
> --
> 2.25.1


  reply	other threads:[~2022-09-09 17:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09 10:58 [bpf-next] bpf: use kvmemdup_bpfptr helper Wang Yufen
2022-09-09 17:27 ` sdf [this message]
2022-09-13  4:24   ` wangyufen

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=Yxt3fnUdzDTJzUTt@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=wangyufen@huawei.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