netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Stefano Brivio <sbrivio@redhat.com>, wenxu <wenxu@ucloud.cn>,
	Alexei Starovoitov <ast@fb.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Hangbin Liu <liuhangbin@gmail.com>
Subject: [PATCH 2/2] xfrm/xfrm_policy: fix dst dev null pointer dereference in collect_md mode
Date: Mon, 19 Aug 2019 15:53:27 +0800	[thread overview]
Message-ID: <20190819075327.32412-3-liuhangbin@gmail.com> (raw)
In-Reply-To: <20190819075327.32412-1-liuhangbin@gmail.com>

In decode_session{4,6} there is a possibility that the skb dst dev is NULL,
e,g, with tunnel collect_md mode, which will cause kernel crash.
Here is what the code path looks like, for GRE:

- ip6gre_tunnel_xmit
  - ip6gre_xmit_ipv6
    - __gre6_xmit
      - ip6_tnl_xmit
        - if skb->len - t->tun_hlen - eth_hlen > mtu; return -EMSGSIZE
    - icmpv6_send
      - icmpv6_route_lookup
        - xfrm_decode_session_reverse
          - decode_session4
            - oif = skb_dst(skb)->dev->ifindex; <-- here
          - decode_session6
            - oif = skb_dst(skb)->dev->ifindex; <-- here

The reason is __metadata_dst_init() init dst->dev to NULL by default.
We could not fix it in __metadata_dst_init() as there is no dev supplied.
On the other hand, the skb_dst(skb)->dev is actually not needed as we
called decode_session{4,6} via xfrm_decode_session_reverse(), so oif is not
used by: fl4->flowi4_oif = reverse ? skb->skb_iif : oif;

So make a dst dev check here should be clean and safe.

Fixes: 8d79266bc48c ("ip6_tunnel: add collect_md mode to IPv6 tunnels")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 net/xfrm/xfrm_policy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 8ca637a72697..ec94f5795ea4 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3269,7 +3269,7 @@ decode_session4(struct sk_buff *skb, struct flowi *fl, bool reverse)
 	struct flowi4 *fl4 = &fl->u.ip4;
 	int oif = 0;
 
-	if (skb_dst(skb))
+	if (skb_dst(skb) && skb_dst(skb)->dev)
 		oif = skb_dst(skb)->dev->ifindex;
 
 	memset(fl4, 0, sizeof(struct flowi4));
@@ -3387,7 +3387,7 @@ decode_session6(struct sk_buff *skb, struct flowi *fl, bool reverse)
 
 	nexthdr = nh[nhoff];
 
-	if (skb_dst(skb))
+	if (skb_dst(skb) && skb_dst(skb)->dev)
 		oif = skb_dst(skb)->dev->ifindex;
 
 	memset(fl6, 0, sizeof(struct flowi6));
-- 
2.19.2


  parent reply	other threads:[~2019-08-19  7:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-15  6:09 [PATCH net] tunnel: fix dev null pointer dereference when send pkg larger than mtu in collect_md mode Hangbin Liu
2019-08-15  9:16 ` Eric Dumazet
2019-08-16  3:24   ` Hangbin Liu
2019-08-16  4:01     ` Hangbin Liu
2019-08-16  8:23     ` Eric Dumazet
2019-08-16 10:51       ` Hangbin Liu
2019-08-19  7:53 ` [PATCHv2 0/2] " Hangbin Liu
2019-08-19  7:53   ` [PATCH 1/2] ipv4/icmp: fix rt dst dev null pointer dereference Hangbin Liu
2019-08-21 16:11     ` Julian Anastasov
2019-08-19  7:53   ` Hangbin Liu [this message]
2019-08-20 19:20   ` [PATCHv2 0/2] fix dev null pointer dereference when send pkg larger than mtu in collect_md mode David Miller
2019-08-21  2:09 ` [PATCHv3 0/2] fix dev null pointer dereference when send packets " Hangbin Liu
2019-08-21  2:09   ` [PATCHv3 1/2] ipv4/icmp: fix rt dst dev null pointer dereference Hangbin Liu
2019-08-21  2:09   ` [PATCHv3 2/2] xfrm/xfrm_policy: fix dst dev null pointer dereference in collect_md mode Hangbin Liu
2019-08-22 14:19 ` [PATCHv4 0/2] fix dev null pointer dereference when send packets larger than mtu " Hangbin Liu
2019-08-22 14:19   ` [PATCHv4 net 1/2] ipv4/icmp: fix rt dst dev null pointer dereference Hangbin Liu
2019-08-22 18:46     ` Julian Anastasov
2019-08-23 22:32     ` Jonathan Lemon
2019-08-22 14:19   ` [PATCHv4 net 2/2] xfrm/xfrm_policy: fix dst dev null pointer dereference in collect_md mode Hangbin Liu
2019-08-23 22:30     ` Jonathan Lemon
2019-08-24 21:51   ` [PATCHv4 0/2] fix dev null pointer dereference when send packets larger than mtu " David Miller

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=20190819075327.32412-3-liuhangbin@gmail.com \
    --to=liuhangbin@gmail.com \
    --cc=ast@fb.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=sbrivio@redhat.com \
    --cc=wenxu@ucloud.cn \
    /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).