bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Cong Wang <xiyou.wangcong@gmail.com>,
	John Fastabend <john.fastabend@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, Cong Wang <cong.wang@bytedance.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Lorenz Bauer <lmb@cloudflare.com>,
	Jakub Sitnicki <jakub@cloudflare.com>
Subject: Re: [Patch bpf] udp: validate checksum in udp_read_sock()
Date: Wed, 13 Oct 2021 09:51:20 -0700	[thread overview]
Message-ID: <61670e88c86ee_4d1c0208a3@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <CAM_iQpXqCQ1BPwqokr6djGmGEHF5BXQDQEPygq16FHDJwxk=uA@mail.gmail.com>

Cong Wang wrote:
> On Mon, Oct 11, 2021 at 10:06 PM John Fastabend
> <john.fastabend@gmail.com> wrote:
> >
> > Cong Wang wrote:
> > > From: Cong Wang <cong.wang@bytedance.com>
> > >
> > > It turns out the skb's in sock receive queue could have
> > > bad checksums, as both ->poll() and ->recvmsg() validate
> > > checksums. We have to do the same for ->read_sock() path
> > > too before they are redirected in sockmap.
> > >
> > > Fixes: d7f571188ecf ("udp: Implement ->read_sock() for sockmap")
> > > Reported-by: Daniel Borkmann <daniel@iogearbox.net>
> > > Reported-by: John Fastabend <john.fastabend@gmail.com>
> > > Cc: Lorenz Bauer <lmb@cloudflare.com>
> > > Cc: Jakub Sitnicki <jakub@cloudflare.com>
> > > Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> > > ---
> > >  net/ipv4/udp.c | 11 +++++++++++
> > >  1 file changed, 11 insertions(+)
> > >
> > > diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> > > index 8536b2a7210b..0ae8ab5e05b4 100644
> > > --- a/net/ipv4/udp.c
> > > +++ b/net/ipv4/udp.c
> > > @@ -1808,6 +1808,17 @@ int udp_read_sock(struct sock *sk, read_descriptor_t *desc,
> > >               skb = skb_recv_udp(sk, 0, 1, &err);
> > >               if (!skb)
> > >                       return err;
> > > +
> > > +             if (udp_lib_checksum_complete(skb)) {
> > > +                     __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS,
> > > +                                     IS_UDPLITE(sk));
> > > +                     __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
> > > +                                     IS_UDPLITE(sk));
> > > +                     atomic_inc(&sk->sk_drops);
> > > +                     kfree_skb(skb);
> >
> > We could use sock_drop() here? Otherwise looks good thanks.
> 
> sock_drop() is in include/linux/skmsg.h, I think we need to move it
> to sock.h before using it here in net/ipv4/udp.c, right?

Yes it would be necessary. Lets not do it here otherwise backports
will be ugly.

Acked-by: John Fastabend <john.fastabend@gmail.com>

> 
> And there are other similar patterns which can be replaced with
> sock_drop(), so we can do the replacement for all in a separate
> patch.
> 
> Thanks.

      reply	other threads:[~2021-10-13 16:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08 20:46 [Patch bpf] udp: validate checksum in udp_read_sock() Cong Wang
2021-10-12  5:06 ` John Fastabend
2021-10-13 16:38   ` Cong Wang
2021-10-13 16:51     ` John Fastabend [this message]

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=61670e88c86ee_4d1c0208a3@john-XPS-13-9370.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=cong.wang@bytedance.com \
    --cc=daniel@iogearbox.net \
    --cc=jakub@cloudflare.com \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).