提交 c021f6a3 编写于 作者: N Nikolay Aleksandrov 提交者: Yang Yingliang

net: bridge: fix vlan tunnel dst null pointer dereference

stable inclusion
from linux-4.19.196
commit 24a6e55f17aa123bc1fc54b7d3c410b41bc16530

--------------------------------

commit 58e20717 upstream.

This patch fixes a tunnel_dst null pointer dereference due to lockless
access in the tunnel egress path. When deleting a vlan tunnel the
tunnel_dst pointer is set to NULL without waiting a grace period (i.e.
while it's still usable) and packets egressing are dereferencing it
without checking. Use READ/WRITE_ONCE to annotate the lockless use of
tunnel_id, use RCU for accessing tunnel_dst and make sure it is read
only once and checked in the egress path. The dst is already properly RCU
protected so we don't need to do anything fancy than to make sure
tunnel_id and tunnel_dst are read only once and checked in the egress path.

Cc: stable@vger.kernel.org
Fixes: 11538d03 ("bridge: vlan dst_metadata hooks in ingress and egress paths")
Signed-off-by: NNikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 04c6b407
...@@ -100,8 +100,8 @@ struct br_vlan_stats { ...@@ -100,8 +100,8 @@ struct br_vlan_stats {
}; };
struct br_tunnel_info { struct br_tunnel_info {
__be64 tunnel_id; __be64 tunnel_id;
struct metadata_dst *tunnel_dst; struct metadata_dst __rcu *tunnel_dst;
}; };
/** /**
......
...@@ -46,26 +46,33 @@ static struct net_bridge_vlan *br_vlan_tunnel_lookup(struct rhashtable *tbl, ...@@ -46,26 +46,33 @@ static struct net_bridge_vlan *br_vlan_tunnel_lookup(struct rhashtable *tbl,
br_vlan_tunnel_rht_params); br_vlan_tunnel_rht_params);
} }
static void vlan_tunnel_info_release(struct net_bridge_vlan *vlan)
{
struct metadata_dst *tdst = rtnl_dereference(vlan->tinfo.tunnel_dst);
WRITE_ONCE(vlan->tinfo.tunnel_id, 0);
RCU_INIT_POINTER(vlan->tinfo.tunnel_dst, NULL);
dst_release(&tdst->dst);
}
void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg, void vlan_tunnel_info_del(struct net_bridge_vlan_group *vg,
struct net_bridge_vlan *vlan) struct net_bridge_vlan *vlan)
{ {
if (!vlan->tinfo.tunnel_dst) if (!rcu_access_pointer(vlan->tinfo.tunnel_dst))
return; return;
rhashtable_remove_fast(&vg->tunnel_hash, &vlan->tnode, rhashtable_remove_fast(&vg->tunnel_hash, &vlan->tnode,
br_vlan_tunnel_rht_params); br_vlan_tunnel_rht_params);
vlan->tinfo.tunnel_id = 0; vlan_tunnel_info_release(vlan);
dst_release(&vlan->tinfo.tunnel_dst->dst);
vlan->tinfo.tunnel_dst = NULL;
} }
static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg, static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg,
struct net_bridge_vlan *vlan, u32 tun_id) struct net_bridge_vlan *vlan, u32 tun_id)
{ {
struct metadata_dst *metadata = NULL; struct metadata_dst *metadata = rtnl_dereference(vlan->tinfo.tunnel_dst);
__be64 key = key32_to_tunnel_id(cpu_to_be32(tun_id)); __be64 key = key32_to_tunnel_id(cpu_to_be32(tun_id));
int err; int err;
if (vlan->tinfo.tunnel_dst) if (metadata)
return -EEXIST; return -EEXIST;
metadata = __ip_tun_set_dst(0, 0, 0, 0, 0, TUNNEL_KEY, metadata = __ip_tun_set_dst(0, 0, 0, 0, 0, TUNNEL_KEY,
...@@ -74,8 +81,8 @@ static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg, ...@@ -74,8 +81,8 @@ static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg,
return -EINVAL; return -EINVAL;
metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX | IP_TUNNEL_INFO_BRIDGE; metadata->u.tun_info.mode |= IP_TUNNEL_INFO_TX | IP_TUNNEL_INFO_BRIDGE;
vlan->tinfo.tunnel_dst = metadata; rcu_assign_pointer(vlan->tinfo.tunnel_dst, metadata);
vlan->tinfo.tunnel_id = key; WRITE_ONCE(vlan->tinfo.tunnel_id, key);
err = rhashtable_lookup_insert_fast(&vg->tunnel_hash, &vlan->tnode, err = rhashtable_lookup_insert_fast(&vg->tunnel_hash, &vlan->tnode,
br_vlan_tunnel_rht_params); br_vlan_tunnel_rht_params);
...@@ -84,9 +91,7 @@ static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg, ...@@ -84,9 +91,7 @@ static int __vlan_tunnel_info_add(struct net_bridge_vlan_group *vg,
return 0; return 0;
out: out:
dst_release(&vlan->tinfo.tunnel_dst->dst); vlan_tunnel_info_release(vlan);
vlan->tinfo.tunnel_dst = NULL;
vlan->tinfo.tunnel_id = 0;
return err; return err;
} }
...@@ -186,12 +191,15 @@ int br_handle_ingress_vlan_tunnel(struct sk_buff *skb, ...@@ -186,12 +191,15 @@ int br_handle_ingress_vlan_tunnel(struct sk_buff *skb,
int br_handle_egress_vlan_tunnel(struct sk_buff *skb, int br_handle_egress_vlan_tunnel(struct sk_buff *skb,
struct net_bridge_vlan *vlan) struct net_bridge_vlan *vlan)
{ {
struct metadata_dst *tunnel_dst;
__be64 tunnel_id;
int err; int err;
if (!vlan || !vlan->tinfo.tunnel_id) if (!vlan)
return 0; return 0;
if (unlikely(!skb_vlan_tag_present(skb))) tunnel_id = READ_ONCE(vlan->tinfo.tunnel_id);
if (!tunnel_id || unlikely(!skb_vlan_tag_present(skb)))
return 0; return 0;
skb_dst_drop(skb); skb_dst_drop(skb);
...@@ -199,7 +207,9 @@ int br_handle_egress_vlan_tunnel(struct sk_buff *skb, ...@@ -199,7 +207,9 @@ int br_handle_egress_vlan_tunnel(struct sk_buff *skb,
if (err) if (err)
return err; return err;
skb_dst_set(skb, dst_clone(&vlan->tinfo.tunnel_dst->dst)); tunnel_dst = rcu_dereference(vlan->tinfo.tunnel_dst);
if (tunnel_dst)
skb_dst_set(skb, dst_clone(&tunnel_dst->dst));
return 0; return 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册