netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Alexander Aring <alex.aring@gmail.com>,
	David Lebrun <david.lebrun@uclouvain.be>,
	 netdev@vger.kernel.org, eric.dumazet@gmail.com,
	 Eric Dumazet <edumazet@google.com>
Subject: [PATCH net 1/3] ipv6: exthdrs: fix potential use-after-free in ipv6_rpl_srh_rcv()
Date: Wed, 17 May 2023 21:31:16 +0000	[thread overview]
Message-ID: <20230517213118.3389898-2-edumazet@google.com> (raw)
In-Reply-To: <20230517213118.3389898-1-edumazet@google.com>

After calls to pskb_may_pull() we need to reload @hdr variable,
because skb->head might have changed.

We need to move up first pskb_may_pull() call right after
looped_back label.

Fixes: 8610c7c6e3bd ("net: ipv6: add support for rpl sr exthdr")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Alexander Aring <alex.aring@gmail.com>
Cc: David Lebrun <david.lebrun@uclouvain.be>
---
 net/ipv6/exthdrs.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index a8d961d3a477f6516f542025dfbcfc6f47407a70..b129e982205ee43cbf74f4900c3031827d962dc2 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -511,6 +511,10 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
 	}
 
 looped_back:
+	if (!pskb_may_pull(skb, sizeof(*hdr))) {
+		kfree_skb(skb);
+		return -1;
+	}
 	hdr = (struct ipv6_rpl_sr_hdr *)skb_transport_header(skb);
 
 	if (hdr->segments_left == 0) {
@@ -544,12 +548,6 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
 
 		return 1;
 	}
-
-	if (!pskb_may_pull(skb, sizeof(*hdr))) {
-		kfree_skb(skb);
-		return -1;
-	}
-
 	n = (hdr->hdrlen << 3) - hdr->pad - (16 - hdr->cmpre);
 	r = do_div(n, (16 - hdr->cmpri));
 	/* checks if calculation was without remainder and n fits into
@@ -592,6 +590,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
 		kfree_skb(skb);
 		return -1;
 	}
+	hdr = (struct ipv6_rpl_sr_hdr *)skb_transport_header(skb);
 
 	hdr->segments_left--;
 	i = n - hdr->segments_left;
-- 
2.40.1.606.ga4b1b128d6-goog


  reply	other threads:[~2023-05-17 21:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 21:31 [PATCH net 0/3] ipv6: exthdrs: fix three SRH issues Eric Dumazet
2023-05-17 21:31 ` Eric Dumazet [this message]
2023-05-18 17:05   ` [PATCH net 1/3] ipv6: exthdrs: fix potential use-after-free in ipv6_rpl_srh_rcv() Simon Horman
2023-05-21 18:22     ` Eric Dumazet
2023-05-22 20:00       ` Jakub Kicinski
2023-05-23  8:47         ` Simon Horman
2023-05-23 10:45           ` Eric Dumazet
2023-05-23 14:41             ` Simon Horman
2023-05-17 21:31 ` [PATCH net 2/3] ipv6: exthdrs: avoid potential NULL deref in ipv6_srh_rcv() Eric Dumazet
2023-05-18 17:06   ` Simon Horman
2023-05-17 21:31 ` [PATCH net 3/3] ipv6: exthdrs: avoid potential NULL deref in ipv6_rpl_srh_rcv() Eric Dumazet
2023-05-18 17:06   ` Simon Horman
2023-05-18  1:53 ` [PATCH net 0/3] ipv6: exthdrs: fix three SRH issues Alexander Aring
2023-05-21 17:05   ` 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=20230517213118.3389898-2-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=alex.aring@gmail.com \
    --cc=davem@davemloft.net \
    --cc=david.lebrun@uclouvain.be \
    --cc=eric.dumazet@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).