]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
xfrm: Fix NULL pointer dereference when skb_dst_force clears the dst_entry.
authorSteffen Klassert <steffen.klassert@secunet.com>
Tue, 11 Sep 2018 08:31:15 +0000 (10:31 +0200)
committerSteffen Klassert <steffen.klassert@secunet.com>
Tue, 11 Sep 2018 09:28:25 +0000 (11:28 +0200)
Since commit 222d7dbd258d ("net: prevent dst uses after free")
skb_dst_force() might clear the dst_entry attached to the skb.
The xfrm code don'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 cast the dst_entry was cleared.

Fixes: 222d7dbd258d ("net: prevent dst uses after free")
Reported-by: Tobias Hommel <netdev-list@genoetigt.de>
Reported-by: Kristian Evensen <kristian.evensen@gmail.com>
Reported-by: Wolfgang Walter <linux@stwm.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_output.c
net/xfrm/xfrm_policy.c

index 89b178a78dc7894ac477b876e3e25320c8265f85..36d15a38ce5e64fb24b5064709b5239fcab505f1 100644 (file)
@@ -101,6 +101,10 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
                spin_unlock_bh(&x->lock);
 
                skb_dst_force(skb);
+               if (!skb_dst(skb)) {
+                       XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
+                       goto error_nolock;
+               }
 
                if (xfrm_offload(skb)) {
                        x->type_offload->encap(x, skb);
index 7c5e8978aeaabfe417d86f943f1576f30571da4c..626e0f4d1749947b571b82fad1e947ed22850466 100644 (file)
@@ -2548,6 +2548,10 @@ int __xfrm_route_forward(struct sk_buff *skb, unsigned short family)
        }
 
        skb_dst_force(skb);
+       if (!skb_dst(skb)) {
+               XFRM_INC_STATS(net, LINUX_MIB_XFRMFWDHDRERROR);
+               return 0;
+       }
 
        dst = xfrm_lookup(net, skb_dst(skb), &fl, NULL, XFRM_LOOKUP_QUEUE);
        if (IS_ERR(dst)) {