All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Vernet <void@manifault.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, Joanne Koong <joannelkoong@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v1 6/7] bpf: Use memmove for bpf_dynptr_{read,write}
Date: Thu, 17 Nov 2022 17:51:25 -0600	[thread overview]
Message-ID: <Y3bI/YSEcuHpyeTx@maniforge.lan> (raw)
In-Reply-To: <20221115000130.1967465-7-memxor@gmail.com>

On Tue, Nov 15, 2022 at 05:31:29AM +0530, Kumar Kartikeya Dwivedi wrote:
> It may happen that destination buffer memory overlaps with memory dynptr
> points to. Hence, we must use memmove to correctly copy from dynptr to
> destination buffer, or source buffer to dynptr.
> 
> This actually isn't a problem right now, as memcpy implementation falls
> back to memmove on detecting overlap and warns about it, but we
> shouldn't be relying on that.
> 
> Acked-by: Joanne Koong <joannelkoong@gmail.com>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---

Good call, thanks for this.

Acked-by: David Vernet <void@manifault.com>

>  kernel/bpf/helpers.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 714f5c9d0c1f..1099ed1e7712 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -1489,7 +1489,7 @@ BPF_CALL_5(bpf_dynptr_read, void *, dst, u32, len, const struct bpf_dynptr_kern
>  	if (err)
>  		return err;
>  
> -	memcpy(dst, src->data + src->offset + offset, len);
> +	memmove(dst, src->data + src->offset + offset, len);

Can you add a comment here and in bpf_dynptr_write() which explain why
memmove is needed?

>  
>  	return 0;
>  }
> @@ -1517,7 +1517,7 @@ BPF_CALL_5(bpf_dynptr_write, const struct bpf_dynptr_kern *, dst, u32, offset, v
>  	if (err)
>  		return err;
>  
> -	memcpy(dst->data + dst->offset + offset, src, len);
> +	memmove(dst->data + dst->offset + offset, src, len);
>  
>  	return 0;
>  }
> -- 
> 2.38.1
> 

  reply	other threads:[~2022-11-17 23:51 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15  0:01 [PATCH bpf-next v1 0/7] Dynptr refactorings Kumar Kartikeya Dwivedi
2022-11-15  0:01 ` [PATCH bpf-next v1 1/7] bpf: Refactor ARG_PTR_TO_DYNPTR checks into process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-15  4:15   ` Joanne Koong
2022-11-15  0:01 ` [PATCH bpf-next v1 2/7] bpf: Propagate errors from process_* checks in check_func_arg Kumar Kartikeya Dwivedi
2022-11-15  3:53   ` Joanne Koong
2022-11-15  0:01 ` [PATCH bpf-next v1 3/7] bpf: Rework process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-16 18:04   ` Joanne Koong
2022-11-17 21:11   ` David Vernet
2022-11-20 18:06     ` Kumar Kartikeya Dwivedi
2022-11-20 18:16       ` David Vernet
2022-11-15  0:01 ` [PATCH bpf-next v1 4/7] bpf: Rework check_func_arg_reg_off Kumar Kartikeya Dwivedi
2022-11-15 18:24   ` Joanne Koong
2022-11-17 23:42   ` David Vernet
2022-11-20 18:41     ` Kumar Kartikeya Dwivedi
2022-11-21  5:39       ` David Vernet
2022-11-15  0:01 ` [PATCH bpf-next v1 5/7] bpf: Move PTR_TO_STACK alignment check to process_dynptr_func Kumar Kartikeya Dwivedi
2022-11-15 18:29   ` Joanne Koong
2022-11-17 23:49   ` David Vernet
2022-11-20 19:10     ` Kumar Kartikeya Dwivedi
2022-11-20 19:40       ` Alexei Starovoitov
2022-11-20 21:02         ` Kumar Kartikeya Dwivedi
2022-11-21  7:27       ` David Vernet
2022-12-07 20:41         ` Kumar Kartikeya Dwivedi
2022-11-15  0:01 ` [PATCH bpf-next v1 6/7] bpf: Use memmove for bpf_dynptr_{read,write} Kumar Kartikeya Dwivedi
2022-11-17 23:51   ` David Vernet [this message]
2022-11-15  0:01 ` [PATCH bpf-next v1 7/7] selftests/bpf: Add test for dynptr reinit in user_ringbuf callback Kumar Kartikeya Dwivedi
2022-11-15 18:36   ` Joanne Koong
2022-11-15 19:41     ` Kumar Kartikeya Dwivedi

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=Y3bI/YSEcuHpyeTx@maniforge.lan \
    --to=void@manifault.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=joannelkoong@gmail.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.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 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.