Skip to content

Commit f653363

Browse files
Peter Huang (Peng)bwhacks
authored andcommitted
set fake_rtable's dst to NULL to avoid kernel Oops
[ Upstream commit a881e96 ] 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> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 4a59003 commit f653363

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎include/linux/netfilter_bridge.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,18 @@ struct bridge_skb_cb {
104104
} daddr;
105105
};
106106

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+
107115
#else
108116
#define nf_bridge_maybe_copy_header(skb) (0)
109117
#define nf_bridge_pad(skb) (0)
118+
#define br_drop_fake_rtable(skb) do { } while (0)
110119
#endif /* CONFIG_BRIDGE_NETFILTER */
111120

112121
#endif /* __KERNEL__ */

‎include/net/dst.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct dst_entry {
5454
#define DST_NOCACHE 0x0010
5555
#define DST_NOCOUNT 0x0020
5656
#define DST_NOPEER 0x0040
57+
#define DST_FAKE_RTABLE 0x0080
5758

5859
short error;
5960
short obsolete;

‎net/bridge/br_forward.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int br_dev_queue_push_xmit(struct sk_buff *skb)
4747
kfree_skb(skb);
4848
} else {
4949
skb_push(skb, ETH_HLEN);
50+
br_drop_fake_rtable(skb);
5051
dev_queue_xmit(skb);
5152
}
5253

‎net/bridge/br_netfilter.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void br_netfilter_rtable_init(struct net_bridge *br)
147147
rt->dst.dev = br->dev;
148148
rt->dst.path = &rt->dst;
149149
dst_init_metrics(&rt->dst, br_dst_default_metrics, true);
150-
rt->dst.flags = DST_NOXFRM | DST_NOPEER;
150+
rt->dst.flags = DST_NOXFRM | DST_NOPEER | DST_FAKE_RTABLE;
151151
rt->dst.ops = &fake_dst_ops;
152152
}
153153

@@ -687,11 +687,7 @@ static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff *skb,
687687
const struct net_device *out,
688688
int (*okfn)(struct sk_buff *))
689689
{
690-
struct rtable *rt = skb_rtable(skb);
691-
692-
if (rt && rt == bridge_parent_rtable(in))
693-
skb_dst_drop(skb);
694-
690+
br_drop_fake_rtable(skb);
695691
return NF_ACCEPT;
696692
}
697693

0 commit comments

Comments
 (0)