]> git.baikalelectronics.ru Git - kernel.git/commit
net: bridge: fix ioctl locking
authorNikolay Aleksandrov <nikolay@nvidia.com>
Thu, 5 Aug 2021 08:29:01 +0000 (11:29 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 5 Aug 2021 10:36:59 +0000 (11:36 +0100)
commit795bf7390d33c2e01f8875b026dd8209485f2f59
treef5d98a9ed881302ccbbb53865b82f7d7e9fb8b6a
parentbfef41746072a183f70e9c20a437880831e4c415
net: bridge: fix ioctl locking

Before commit 9c5473136e3e ("net: bridge: move bridge ioctls out of
.ndo_do_ioctl") the bridge ioctl calls were divided in two parts:
one was deviceless called by sock_ioctl and didn't expect rtnl to be held,
the other was with a device called by dev_ifsioc() and expected rtnl to be
held. After the commit above they were united in a single ioctl stub, but
it didn't take care of the locking expectations.
For sock_ioctl now we acquire  (1) br_ioctl_mutex, (2) rtnl
and for dev_ifsioc we acquire  (1) rtnl,           (2) br_ioctl_mutex

The fix is to get a refcnt on the netdev for dev_ifsioc calls and drop rtnl
then to reacquire it in the bridge ioctl stub after br_ioctl_mutex has
been acquired. That will avoid playing locking games and make the rules
straight-forward: we always take br_ioctl_mutex first, and then rtnl.

Reported-by: syzbot+34fe5894623c4ab1b379@syzkaller.appspotmail.com
Fixes: 9c5473136e3e ("net: bridge: move bridge ioctls out of .ndo_do_ioctl")
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_if.c
net/bridge/br_ioctl.c
net/core/dev_ioctl.c