Commit 2a3cabae authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by David S. Miller

net: ip6_gre: fix possible use-after-free in ip6erspan_rcv

erspan_v6 tunnels run __iptunnel_pull_header on received skbs to remove
erspan header. This can determine a possible use-after-free accessing
pkt_md pointer in ip6erspan_rcv since the packet will be 'uncloned'
running pskb_expand_head if it is a cloned gso skb (e.g if the packet has
been sent though a veth device). Fix it resetting pkt_md pointer after
__iptunnel_pull_header

Fixes: 1d7e2ed2 ("net: erspan: refactor existing erspan code")
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 492b67e2
...@@ -525,10 +525,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi) ...@@ -525,10 +525,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
} }
static int ip6erspan_rcv(struct sk_buff *skb, static int ip6erspan_rcv(struct sk_buff *skb,
struct tnl_ptk_info *tpi) struct tnl_ptk_info *tpi,
int gre_hdr_len)
{ {
struct erspan_base_hdr *ershdr; struct erspan_base_hdr *ershdr;
struct erspan_metadata *pkt_md;
const struct ipv6hdr *ipv6h; const struct ipv6hdr *ipv6h;
struct erspan_md2 *md2; struct erspan_md2 *md2;
struct ip6_tnl *tunnel; struct ip6_tnl *tunnel;
...@@ -547,18 +547,16 @@ static int ip6erspan_rcv(struct sk_buff *skb, ...@@ -547,18 +547,16 @@ static int ip6erspan_rcv(struct sk_buff *skb,
if (unlikely(!pskb_may_pull(skb, len))) if (unlikely(!pskb_may_pull(skb, len)))
return PACKET_REJECT; return PACKET_REJECT;
ershdr = (struct erspan_base_hdr *)skb->data;
pkt_md = (struct erspan_metadata *)(ershdr + 1);
if (__iptunnel_pull_header(skb, len, if (__iptunnel_pull_header(skb, len,
htons(ETH_P_TEB), htons(ETH_P_TEB),
false, false) < 0) false, false) < 0)
return PACKET_REJECT; return PACKET_REJECT;
if (tunnel->parms.collect_md) { if (tunnel->parms.collect_md) {
struct erspan_metadata *pkt_md, *md;
struct metadata_dst *tun_dst; struct metadata_dst *tun_dst;
struct ip_tunnel_info *info; struct ip_tunnel_info *info;
struct erspan_metadata *md; unsigned char *gh;
__be64 tun_id; __be64 tun_id;
__be16 flags; __be16 flags;
...@@ -571,6 +569,14 @@ static int ip6erspan_rcv(struct sk_buff *skb, ...@@ -571,6 +569,14 @@ static int ip6erspan_rcv(struct sk_buff *skb,
if (!tun_dst) if (!tun_dst)
return PACKET_REJECT; return PACKET_REJECT;
/* skb can be uncloned in __iptunnel_pull_header, so
* old pkt_md is no longer valid and we need to reset
* it
*/
gh = skb_network_header(skb) +
skb_network_header_len(skb);
pkt_md = (struct erspan_metadata *)(gh + gre_hdr_len +
sizeof(*ershdr));
info = &tun_dst->u.tun_info; info = &tun_dst->u.tun_info;
md = ip_tunnel_info_opts(info); md = ip_tunnel_info_opts(info);
md->version = ver; md->version = ver;
...@@ -607,7 +613,7 @@ static int gre_rcv(struct sk_buff *skb) ...@@ -607,7 +613,7 @@ static int gre_rcv(struct sk_buff *skb)
if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) || if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
tpi.proto == htons(ETH_P_ERSPAN2))) { tpi.proto == htons(ETH_P_ERSPAN2))) {
if (ip6erspan_rcv(skb, &tpi) == PACKET_RCVD) if (ip6erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
return 0; return 0;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment