OSDN Git Service

rtnetlink: avoid RCU read lock when holding RTNL
authorCong Wang <cong.wang@bytedance.com>
Sat, 8 May 2021 18:00:33 +0000 (11:00 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 10 May 2021 21:33:10 +0000 (14:33 -0700)
commita100243d95a60d74ae9bb9df1f5f2192e9aed6a7
tree5c614edec5ccc729eae58fb83e8ef43026f9e9ad
parent3f8fca5d43357ab3ae678d908ac3c74e07503f0d
rtnetlink: avoid RCU read lock when holding RTNL

When we call af_ops->set_link_af() we hold a RCU read lock
as we retrieve af_ops from the RCU protected list, but this
is unnecessary because we already hold RTNL lock, which is
the writer lock for protecting rtnl_af_ops, so it is safer
than RCU read lock. Similar for af_ops->validate_link_af().

This was not a problem until we begin to take mutex lock
down the path of ->set_link_af() in __ipv6_dev_mc_dec()
recently. We can just drop the RCU read lock there and
assert RTNL lock.

Reported-and-tested-by: syzbot+7d941e89dd48bcf42573@syzkaller.appspotmail.com
Fixes: 63ed8de4be81 ("mld: add mc_lock for protecting per-interface mld data")
Tested-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/rtnetlink.c
net/ipv4/devinet.c