All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Eric Dumazet <edumazet@google.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev <netdev@vger.kernel.org>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, bpf <bpf@vger.kernel.org>,
	Lawrence Brakmo <brakmo@fb.com>
Subject: Re: [PATCH bpf] bpf: properly check TCP_CONGESTION optlen
Date: Sat, 23 Feb 2019 12:38:09 -0800	[thread overview]
Message-ID: <20190223203808.f2r54xz2z7j2gecg@ast-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <20190223190709.61558-1-edumazet@google.com>

On Sat, Feb 23, 2019 at 11:07:09AM -0800, Eric Dumazet wrote:
> If caller of bpf_setsockopt() is silly passing a negative optlen
> bad things happen.
> 
> Fixes: 91b5b21c7c16 ("bpf: Add support for changing congestion control")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Lawrence Brakmo <brakmo@fb.com>
> ---
>  net/core/filter.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index f7d0004fc16096eb42ece3a6acf645540ee2326b..6a5d89464168f2f35f43986c1dbc0446c9390a3c 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4194,8 +4194,9 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
>  			char name[TCP_CA_NAME_MAX];
>  			bool reinit = bpf_sock->op > BPF_SOCK_OPS_NEEDS_ECN;
>  
> -			strncpy(name, optval, min_t(long, optlen,
> -						    TCP_CA_NAME_MAX-1));
> +			if (optlen < 0)
> +				return -EINVAL;
> +			strncpy(name, optval, min(optlen, TCP_CA_NAME_MAX - 1));

Unnecessary.
The verifier guarantees that optlen > 0 because
static const struct bpf_func_proto bpf_setsockopt_proto = {
        .func           = bpf_setsockopt,
...
        .arg5_type      = ARG_CONST_SIZE,
};


  reply	other threads:[~2019-02-23 20:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-23 19:07 [PATCH bpf] bpf: properly check TCP_CONGESTION optlen Eric Dumazet
2019-02-23 20:38 ` Alexei Starovoitov [this message]
2019-02-23 20:48   ` Eric Dumazet
2019-02-23 23:11     ` Alexei Starovoitov
2019-02-25 11:07       ` Daniel Borkmann
2019-02-25 15:43         ` Eric Dumazet

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=20190223203808.f2r54xz2z7j2gecg@ast-mbp.dhcp.thefacebook.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brakmo@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=edumazet@google.com \
    --cc=eric.dumazet@gmail.com \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.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 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.