提交 410b3d48 编写于 作者: N Nikolay Aleksandrov 提交者: David S. Miller

bridge: fdb: add proper lock checks in searching functions

In order to avoid new errors add checks to br_fdb_find and fdb_find_rcu
functions. The first requires hash_lock, the second obviously RCU.
Signed-off-by: NNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 bfd0aeac
...@@ -89,6 +89,8 @@ static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head, ...@@ -89,6 +89,8 @@ static struct net_bridge_fdb_entry *fdb_find_rcu(struct hlist_head *head,
{ {
struct net_bridge_fdb_entry *f; struct net_bridge_fdb_entry *f;
WARN_ON_ONCE(!rcu_read_lock_held());
hlist_for_each_entry_rcu(f, head, hlist) hlist_for_each_entry_rcu(f, head, hlist)
if (ether_addr_equal(f->addr.addr, addr) && f->vlan_id == vid) if (ether_addr_equal(f->addr.addr, addr) && f->vlan_id == vid)
break; break;
...@@ -104,6 +106,8 @@ static struct net_bridge_fdb_entry *br_fdb_find(struct net_bridge *br, ...@@ -104,6 +106,8 @@ static struct net_bridge_fdb_entry *br_fdb_find(struct net_bridge *br,
struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)]; struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
struct net_bridge_fdb_entry *fdb; struct net_bridge_fdb_entry *fdb;
WARN_ON_ONCE(!br_hash_lock_held(br));
rcu_read_lock(); rcu_read_lock();
fdb = fdb_find_rcu(head, addr, vid); fdb = fdb_find_rcu(head, addr, vid);
rcu_read_unlock(); rcu_read_unlock();
......
...@@ -531,6 +531,15 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, ...@@ -531,6 +531,15 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
const unsigned char *addr, u16 vid); const unsigned char *addr, u16 vid);
static inline bool br_hash_lock_held(struct net_bridge *br)
{
#ifdef CONFIG_LOCKDEP
return lockdep_is_held(&br->hash_lock);
#else
return true;
#endif
}
/* br_forward.c */ /* br_forward.c */
enum br_pkt_type { enum br_pkt_type {
BR_PKT_UNICAST, BR_PKT_UNICAST,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册