All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Lau <kafai@fb.com>
To: Yafang Shao <laoar.shao@gmail.com>, Lawrence Brakmo <brakmo@fb.com>
Cc: "ast@kernel.org" <ast@kernel.org>,
	"daniel@iogearbox.net" <daniel@iogearbox.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"shaoyafang@didiglobal.com" <shaoyafang@didiglobal.com>
Subject: Re: [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt()
Date: Tue, 22 Jan 2019 18:04:58 +0000	[thread overview]
Message-ID: <20190122180457.goq4xgtbi5cuxzwz@kafai-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <1547878852-22081-1-git-send-email-laoar.shao@gmail.com>

On Sat, Jan 19, 2019 at 02:20:52PM +0800, Yafang Shao wrote:
> As the last character of optval will be set with 0, so just copying
> (optlen - 1) characters is enough.
I am not sure this optimization is needed but I think it will
make it more consistent with the bpf_setsockopt() above.

Acked-by: Martin KaFai Lau <kafai@fb.com>

Cc: Lawrence Brakmo <brakmo@fb.com>

> 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  net/core/filter.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 447dd1b..7a4de22 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4262,7 +4262,7 @@ static unsigned long bpf_xdp_copy(void *dst_buff, const void *src_buff,
>  
>  			if (!icsk->icsk_ca_ops || optlen <= 1)
>  				goto err_clear;
> -			strncpy(optval, icsk->icsk_ca_ops->name, optlen);
> +			strncpy(optval, icsk->icsk_ca_ops->name, optlen - 1);
>  			optval[optlen - 1] = 0;
>  			break;
>  		case TCP_SAVED_SYN:
> -- 
> 1.8.3.1
> 

  reply	other threads:[~2019-01-22 18:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-19  6:20 [PATCH bpf-next] bpf: use the proper optlen when doing strncpy in bpf_getsockopt() Yafang Shao
2019-01-22 18:04 ` Martin Lau [this message]
2019-01-22 18:39   ` Lawrence Brakmo
2019-01-23 13:53   ` Daniel Borkmann

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=20190122180457.goq4xgtbi5cuxzwz@kafai-mbp.dhcp.thefacebook.com \
    --to=kafai@fb.com \
    --cc=ast@kernel.org \
    --cc=brakmo@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=laoar.shao@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=shaoyafang@didiglobal.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.