Message ID | 201107231049.40603.xeb@mail.ru |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
Le samedi 23 juillet 2011 à 10:49 +0400, xeb@mail.ru a écrit : > Fix improper protocol err_handler, current implementation is fully > unapplicable and may cause kernel crash due to double kfree_skb. > > Signed-off-by: Dmitry Kozlov <xeb@mail.ru> > --- > net/ipv4/gre.c | 21 ++++++--------------- > 1 files changed, 6 insertions(+), 15 deletions(-) > Good catch ! Acked-by: Eric Dumazet <eric.dumazet@gmail.com> -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Eric Dumazet <eric.dumazet@gmail.com> Date: Sat, 23 Jul 2011 10:32:44 +0200 > Le samedi 23 juillet 2011 à 10:49 +0400, xeb@mail.ru a écrit : >> Fix improper protocol err_handler, current implementation is fully >> unapplicable and may cause kernel crash due to double kfree_skb. >> >> Signed-off-by: Dmitry Kozlov <xeb@mail.ru> >> --- >> net/ipv4/gre.c | 21 ++++++--------------- >> 1 files changed, 6 insertions(+), 15 deletions(-) >> > > Good catch ! > > Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Applied, thanks everyone. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/ipv4/gre.c b/net/ipv4/gre.c index 9dbe108..dbfc21d 100644 --- a/net/ipv4/gre.c +++ b/net/ipv4/gre.c @@ -15,6 +15,7 @@ #include <linux/kmod.h> #include <linux/skbuff.h> #include <linux/in.h> +#include <linux/ip.h> #include <linux/netdevice.h> #include <linux/spinlock.h> #include <net/protocol.h> @@ -96,27 +97,17 @@ drop: static void gre_err(struct sk_buff *skb, u32 info) { const struct gre_protocol *proto; - u8 ver; - - if (!pskb_may_pull(skb, 12)) - goto drop; + const struct iphdr *iph = (const struct iphdr *)skb->data; + u8 ver = skb->data[(iph->ihl<<2) + 1]&0x7f; - ver = skb->data[1]&0x7f; if (ver >= GREPROTO_MAX) - goto drop; + return; rcu_read_lock(); proto = rcu_dereference(gre_proto[ver]); - if (!proto || !proto->err_handler) - goto drop_unlock; - proto->err_handler(skb, info); - rcu_read_unlock(); - return; - -drop_unlock: + if (proto && proto->err_handler) + proto->err_handler(skb, info); rcu_read_unlock(); -drop: - kfree_skb(skb); } static const struct net_protocol net_gre_protocol = {
Fix improper protocol err_handler, current implementation is fully unapplicable and may cause kernel crash due to double kfree_skb. Signed-off-by: Dmitry Kozlov <xeb@mail.ru> --- net/ipv4/gre.c | 21 ++++++--------------- 1 files changed, 6 insertions(+), 15 deletions(-)