netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guillaume Nault <gnault@redhat.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org,
	Martin Varghese <martin.varghese@nokia.com>,
	Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net] bareudp: Fix invalid read beyond skb's linear data
Date: Tue, 10 Aug 2021 11:33:04 +0200	[thread overview]
Message-ID: <20210810093304.GA14279@pc-32.home> (raw)
In-Reply-To: <20210809091918.68ae21e8@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>

On Mon, Aug 09, 2021 at 09:19:18AM -0700, Jakub Kicinski wrote:
> On Sun, 8 Aug 2021 18:16:25 +0200 Guillaume Nault wrote:
> > On Fri, Aug 06, 2021 at 04:22:34PM -0700, Jakub Kicinski wrote:
> > > On Fri, 6 Aug 2021 17:52:06 +0200 Guillaume Nault wrote:  
> > > > Data beyond the UDP header might not be part of the skb's linear data.
> > > > Use skb_copy_bits() instead of direct access to skb->data+X, so that
> > > > we read the correct bytes even on a fragmented skb.
> > > > 
> > > > Fixes: 4b5f67232d95 ("net: Special handling for IP & MPLS.")
> > > > Signed-off-by: Guillaume Nault <gnault@redhat.com>
> > > > ---
> > > >  drivers/net/bareudp.c | 16 +++++++++++-----
> > > >  1 file changed, 11 insertions(+), 5 deletions(-)
> > > > 
> > > > diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c
> > > > index a7ee0af1af90..54e321a695ce 100644
> > > > --- a/drivers/net/bareudp.c
> > > > +++ b/drivers/net/bareudp.c
> > > > @@ -71,12 +71,18 @@ static int bareudp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
> > > >  		family = AF_INET6;
> > > >  
> > > >  	if (bareudp->ethertype == htons(ETH_P_IP)) {
> > > > -		struct iphdr *iphdr;
> > > > +		__u8 ipversion;
> > > >  
> > > > -		iphdr = (struct iphdr *)(skb->data + BAREUDP_BASE_HLEN);
> > > > -		if (iphdr->version == 4) {
> > > > -			proto = bareudp->ethertype;
> > > > -		} else if (bareudp->multi_proto_mode && (iphdr->version == 6)) {
> > > > +		if (skb_copy_bits(skb, BAREUDP_BASE_HLEN, &ipversion,
> > > > +				  sizeof(ipversion))) {  
> > > 
> > > No preference just curious - could skb_header_pointer() be better suited?  
> > 
> > I have no preference either. I just used skb_copy_bits() because it
> > didn't seem useful to get a pointer to the buffer (just to read one
> > byte of data).
> 
> Right, the advantage would be in the "fast" case of skb_header_pointer()
> being inlined.

Yes indeed. The problem was found because of some automated functionnal
tests, not because of any practical use cases. So I didn't consider the
possible performance differences.

I see that you've applied the patch as is already. I can switch to
skb_header_pointer() in the future, if anyone sees any practical
benefit for it.

Thanks for the review.


  reply	other threads:[~2021-08-10  9:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06 15:52 [PATCH net] bareudp: Fix invalid read beyond skb's linear data Guillaume Nault
2021-08-06 23:22 ` Jakub Kicinski
2021-08-08 16:16   ` Guillaume Nault
2021-08-09 16:19     ` Jakub Kicinski
2021-08-10  9:33       ` Guillaume Nault [this message]
2021-08-09 22:40 ` patchwork-bot+netdevbpf

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=20210810093304.GA14279@pc-32.home \
    --to=gnault@redhat.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=martin.varghese@nokia.com \
    --cc=netdev@vger.kernel.org \
    --cc=willemb@google.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).