Commit ae1768bb authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

ip6_gre: fix ip6gre_err() invalid reads

[ Upstream commit 7892032c ]

Andrey Konovalov reported out of bound accesses in ip6gre_err()

If GRE flags contains GRE_KEY, the following expression
*(((__be32 *)p) + (grehlen / 4) - 1)

accesses data ~40 bytes after the expected point, since
grehlen includes the size of IPv6 headers.

Let's use a "struct gre_base_hdr *greh" pointer to make this
code more readable.

p[1] becomes greh->protocol.
grhlen is the GRE header length.

Fixes: c12b395a ("gre: Support GRE over IPv6")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 66cdd434
...@@ -367,35 +367,37 @@ static void ip6gre_tunnel_uninit(struct net_device *dev) ...@@ -367,35 +367,37 @@ static void ip6gre_tunnel_uninit(struct net_device *dev)
static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt, static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
u8 type, u8 code, int offset, __be32 info) u8 type, u8 code, int offset, __be32 info)
{ {
const struct ipv6hdr *ipv6h = (const struct ipv6hdr *)skb->data; const struct gre_base_hdr *greh;
__be16 *p = (__be16 *)(skb->data + offset); const struct ipv6hdr *ipv6h;
int grehlen = offset + 4; int grehlen = sizeof(*greh);
struct ip6_tnl *t; struct ip6_tnl *t;
int key_off = 0;
__be16 flags; __be16 flags;
__be32 key;
flags = p[0]; if (!pskb_may_pull(skb, offset + grehlen))
if (flags&(GRE_CSUM|GRE_KEY|GRE_SEQ|GRE_ROUTING|GRE_VERSION)) { return;
if (flags&(GRE_VERSION|GRE_ROUTING)) greh = (const struct gre_base_hdr *)(skb->data + offset);
return; flags = greh->flags;
if (flags&GRE_KEY) { if (flags & (GRE_VERSION | GRE_ROUTING))
grehlen += 4; return;
if (flags&GRE_CSUM) if (flags & GRE_CSUM)
grehlen += 4; grehlen += 4;
} if (flags & GRE_KEY) {
key_off = grehlen + offset;
grehlen += 4;
} }
/* If only 8 bytes returned, keyed message will be dropped here */ if (!pskb_may_pull(skb, offset + grehlen))
if (!pskb_may_pull(skb, grehlen))
return; return;
ipv6h = (const struct ipv6hdr *)skb->data; ipv6h = (const struct ipv6hdr *)skb->data;
p = (__be16 *)(skb->data + offset); greh = (const struct gre_base_hdr *)(skb->data + offset);
key = key_off ? *(__be32 *)(skb->data + key_off) : 0;
t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr, t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
flags & GRE_KEY ? key, greh->protocol);
*(((__be32 *)p) + (grehlen / 4) - 1) : 0,
p[1]);
if (!t) if (!t)
return; return;
......
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