linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Bader <stefan.bader@canonical.com>
To: stable <stable@vger.kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
	Sasha Levin <sashal@kernel.org>, Peter Oskolkov <posk@google.com>,
	Ben Hutchings <ben.hutchings@codethink.co.uk>,
	Andy Whitcroft <andy.whitcroft@canonical.com>,
	Greg KH <gregkh@linuxfoundation.org>
Subject: [PATCH 4/4] ipv6: frags: Use inet_frag_pull_head() in ip6_expire_frag_queue()
Date: Wed, 29 May 2019 12:25:42 +0200	[thread overview]
Message-ID: <20190529102542.17742-5-stefan.bader@canonical.com> (raw)
In-Reply-To: <20190529102542.17742-1-stefan.bader@canonical.com>

With frag code shared between IPv4 and IPv6 it is now possible
to use inet_frag_pull_head() in ip6_expire_frag_queue() in order
to properly extract the first skb from the frags queue.
Since this really takes the skb out of the list, it no longer
needs to be protected against removal (which implicitly fixes
a crash that will happen somewhere in the call to icmp6_send()
when the use count is forcefully checked to be 1.

 kernel BUG at linux-4.4.0/net/core/skbuff.c:1207!
 RIP: 0010:[<ffffffff81740953>]
  [<ffffffff81740953>] pskb_expand_head+0x243/0x250
  [<ffffffff81740e50>] __pskb_pull_tail+0x50/0x350
  [<ffffffff8183939a>] _decode_session6+0x26a/0x400
  [<ffffffff817ec719>] __xfrm_decode_session+0x39/0x50
  [<ffffffff818239d0>] icmpv6_route_lookup+0xf0/0x1c0
  [<ffffffff81824421>] icmp6_send+0x5e1/0x940
  [<ffffffff8183d431>] icmpv6_send+0x21/0x30
  [<ffffffff8182b500>] ip6_expire_frag_queue+0xe0/0x120

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 net/ipv6/reassembly.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 020cf70273c9..2bd45abc2516 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -110,16 +110,14 @@ void ip6_expire_frag_queue(struct net *net, struct frag_queue *fq)
 	IP6_INC_STATS_BH(net, __in6_dev_get(dev), IPSTATS_MIB_REASMTIMEOUT);
 
 	/* Don't send error if the first segment did not arrive. */
-	head = fq->q.fragments;
-	if (!(fq->q.flags & INET_FRAG_FIRST_IN) || !head)
+	if (!(fq->q.flags & INET_FRAG_FIRST_IN))
+		goto out;
+
+	head = inet_frag_pull_head(&fq->q);
+	if (!head)
 		goto out;
 
-	/* But use as source device on which LAST ARRIVED
-	 * segment was received. And do not use fq->dev
-	 * pointer directly, device might already disappeared.
-	 */
 	head->dev = dev;
-	skb_get(head);
 	spin_unlock(&fq->q.lock);
 
 	icmpv6_send(head, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0);
-- 
2.17.1


      parent reply	other threads:[~2019-05-29 10:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 10:25 [PATCH 0/4] ipv6: frags: fixups for linux-4.4.y Stefan Bader
2019-05-29 10:25 ` [PATCH 1/4] ipv4: ipv6: netfilter: Adjust the frag mem limit when truesize changes Stefan Bader
2019-05-29 10:37   ` Greg KH
2019-05-29 12:31     ` Stefan Bader
2019-06-04 13:32     ` Stefan Bader
2019-05-29 10:25 ` [PATCH 2/4] ip: fail fast on IP defrag errors Stefan Bader
2019-05-29 10:25 ` [PATCH 3/4] net: IP defrag: encapsulate rbtree defrag code into callable functions Stefan Bader
2019-05-29 10:25 ` Stefan Bader [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=20190529102542.17742-5-stefan.bader@canonical.com \
    --to=stefan.bader@canonical.com \
    --cc=andy.whitcroft@canonical.com \
    --cc=ben.hutchings@codethink.co.uk \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=posk@google.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /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).