netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.14 11/59] xfrm: Fix NULL pointer dereference in xfrm_input when skb_dst_force clears the dst_entry.
Date: Wed, 26 Dec 2018 17:37:51 -0500	[thread overview]
Message-ID: <20181226223839.150262-11-sashal@kernel.org> (raw)
In-Reply-To: <20181226223839.150262-1-sashal@kernel.org>

From: Steffen Klassert <steffen.klassert@secunet.com>

[ Upstream commit 0152eee6fc3b84298bb6a79961961734e8afa5b8 ]

Since commit 222d7dbd258d ("net: prevent dst uses after free")
skb_dst_force() might clear the dst_entry attached to the skb.
The xfrm code doesn't expect this to happen, so we crash with
a NULL pointer dereference in this case.

Fix it by checking skb_dst(skb) for NULL after skb_dst_force()
and drop the packet in case the dst_entry was cleared. We also
move the skb_dst_force() to a codepath that is not used when
the transformation was offloaded, because in this case we
don't have a dst_entry attached to the skb.

The output and forwarding path was already fixed by
commit 9e1437937807 ("xfrm: Fix NULL pointer dereference when
skb_dst_force clears the dst_entry.")

Fixes: 222d7dbd258d ("net: prevent dst uses after free")
Reported-by: Jean-Philippe Menil <jpmenil@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/xfrm/xfrm_input.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 8e75319dd9c0..06dec32503bd 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -341,6 +341,12 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 		skb->sp->xvec[skb->sp->len++] = x;
 
+		skb_dst_force(skb);
+		if (!skb_dst(skb)) {
+			XFRM_INC_STATS(net, LINUX_MIB_XFRMINERROR);
+			goto drop;
+		}
+
 lock:
 		spin_lock(&x->lock);
 
@@ -380,7 +386,6 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 		XFRM_SKB_CB(skb)->seq.input.low = seq;
 		XFRM_SKB_CB(skb)->seq.input.hi = seq_hi;
 
-		skb_dst_force(skb);
 		dev_hold(skb->dev);
 
 		if (crypto_done)
-- 
2.19.1

  parent reply	other threads:[~2018-12-26 22:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181226223839.150262-1-sashal@kernel.org>
2018-12-26 22:37 ` [PATCH AUTOSEL 4.14 09/59] xfrm: Fix error return code in xfrm_output_one() Sasha Levin
2018-12-26 22:37 ` [PATCH AUTOSEL 4.14 10/59] xfrm: Fix bucket count reported to userspace Sasha Levin
2018-12-26 22:37 ` Sasha Levin [this message]
2018-12-26 22:37 ` [PATCH AUTOSEL 4.14 12/59] netfilter: seqadj: re-load tcp header pointer after possible head reallocation Sasha Levin
2018-12-26 22:37 ` [PATCH AUTOSEL 4.14 16/59] ibmvnic: Fix non-atomic memory allocation in IRQ context Sasha Levin
2018-12-26 22:37 ` [PATCH AUTOSEL 4.14 17/59] ieee802154: ca8210: fix possible u8 overflow in ca8210_rx_done Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 20/59] i40e: fix mac filter delete when setting mac address Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 21/59] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 22/59] netfilter: ipset: do not call ipset_nest_end after nla_nest_cancel Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 23/59] netfilter: nat: can't use dst_hold on noref dst Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 24/59] bnx2x: Clear fip MAC when fcoe offload support is disabled Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 25/59] bnx2x: Remove configured vlans as part of unload sequence Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 26/59] bnx2x: Send update-svid ramrod with retry/poll flags enabled Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 30/59] drivers: net: xgene: Remove unnecessary forward declarations Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 31/59] w90p910_ether: remove incorrect __init annotation Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 32/59] qmi_wwan: Added support for Telit LN940 series Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 33/59] net: hns: Incorrect offset address used for some registers Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 34/59] net: hns: All ports can not work when insmod hns ko after rmmod Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 35/59] net: hns: Some registers use wrong address according to the datasheet Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 36/59] net: hns: Fixed bug that netdev was opened twice Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 37/59] net: hns: Clean rx fbd when ae stopped Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 38/59] net: hns: Free irq when exit from abnormal branch Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 39/59] net: hns: Avoid net reset caused by pause frames storm Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 40/59] net: hns: Fix ntuple-filters status error Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 41/59] net: hns: Add mac pcs config when enable|disable mac Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 42/59] net: hns: Fix ping failed when use net bridge and send multicast Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 43/59] SUNRPC: Fix a race with XPRT_CONNECTING Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 45/59] qed: Fix an error code qed_ll2_start_xmit() Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 46/59] net: macb: fix random memory corruption on RX with 64-bit DMA Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 47/59] net: macb: fix dropped RX frames due to a race Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 48/59] lan78xx: Resolve issue with changing MAC address Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 49/59] xen/netfront: tolerate frags with no data Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 50/59] vxge: ensure data0 is initialized in when fetching firmware version information Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 51/59] mac80211: free skb fraglist before freeing the skb Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 53/59] net/mlx5: Typo fix in del_sw_hw_rule Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 57/59] net: netxen: fix a missing check and an uninitialized use Sasha Levin
2018-12-26 22:38 ` [PATCH AUTOSEL 4.14 58/59] qmi_wwan: Fix qmap header retrieval in qmimux_rx_fixup Sasha Levin

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=20181226223839.150262-11-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=steffen.klassert@secunet.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).