Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

set fake_rtable's dst to NULL to avoid kernel Oops

bridge: set fake_rtable's dst to NULL to avoid kernel Oops

when bridge is deleted before tap/vif device's delete, kernel may
encounter an oops because of NULL reference to fake_rtable's dst.
Set fake_rtable's dst to NULL before sending packets out can solve
this problem.

v4 reformat, change br_drop_fake_rtable(skb) to {}

v3 enrich commit header

v2 introducing new flag DST_FAKE_RTABLE to dst_entry struct.

[ Use "do { } while (0)" for nop br_drop_fake_rtable()
implementation -DaveM ]

Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Peter Huang <peter.huangpeng@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Peter Huang (Peng) and committed by
David S. Miller
a881e963 4d634ca3

+13 -6
+9
include/linux/netfilter_bridge.h
··· 104 104 } daddr; 105 105 }; 106 106 107 + static inline void br_drop_fake_rtable(struct sk_buff *skb) 108 + { 109 + struct dst_entry *dst = skb_dst(skb); 110 + 111 + if (dst && (dst->flags & DST_FAKE_RTABLE)) 112 + skb_dst_drop(skb); 113 + } 114 + 107 115 #else 108 116 #define nf_bridge_maybe_copy_header(skb) (0) 109 117 #define nf_bridge_pad(skb) (0) 118 + #define br_drop_fake_rtable(skb) do { } while (0) 110 119 #endif /* CONFIG_BRIDGE_NETFILTER */ 111 120 112 121 #endif /* __KERNEL__ */
+1
include/net/dst.h
··· 59 59 #define DST_NOCACHE 0x0010 60 60 #define DST_NOCOUNT 0x0020 61 61 #define DST_NOPEER 0x0040 62 + #define DST_FAKE_RTABLE 0x0080 62 63 63 64 short error; 64 65 short obsolete;
+1
net/bridge/br_forward.c
··· 47 47 kfree_skb(skb); 48 48 } else { 49 49 skb_push(skb, ETH_HLEN); 50 + br_drop_fake_rtable(skb); 50 51 dev_queue_xmit(skb); 51 52 } 52 53
+2 -6
net/bridge/br_netfilter.c
··· 156 156 rt->dst.dev = br->dev; 157 157 rt->dst.path = &rt->dst; 158 158 dst_init_metrics(&rt->dst, br_dst_default_metrics, true); 159 - rt->dst.flags = DST_NOXFRM | DST_NOPEER; 159 + rt->dst.flags = DST_NOXFRM | DST_NOPEER | DST_FAKE_RTABLE; 160 160 rt->dst.ops = &fake_dst_ops; 161 161 } 162 162 ··· 694 694 const struct net_device *out, 695 695 int (*okfn)(struct sk_buff *)) 696 696 { 697 - struct rtable *rt = skb_rtable(skb); 698 - 699 - if (rt && rt == bridge_parent_rtable(in)) 700 - skb_dst_drop(skb); 701 - 697 + br_drop_fake_rtable(skb); 702 698 return NF_ACCEPT; 703 699 } 704 700