Skip to content

Commit 496a60c

Browse files
ebiedermdavem330
authored andcommitted
net: FIX bonding sysfs rtnl_lock deadlock
Sysfs files for a network device can not unconditionally take the rtnl_lock as the bonding sysfs files do. If someone accesses those sysfs files while the network device is being unregistered with the rtnl_lock held we will deadlock. So use trylock and restart_syscall to avoid this problem. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2657440 commit 496a60c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎drivers/net/bonding/bond_sysfs.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ static ssize_t bonding_store_slaves(struct device *d,
251251

252252
/* Note: We can't hold bond->lock here, as bond_create grabs it. */
253253

254-
rtnl_lock();
254+
if (!rtnl_trylock())
255+
return restart_syscall();
255256
down_write(&(bonding_rwsem));
256257

257258
sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
@@ -1171,7 +1172,8 @@ static ssize_t bonding_store_primary(struct device *d,
11711172
struct slave *slave;
11721173
struct bonding *bond = to_bond(d);
11731174

1174-
rtnl_lock();
1175+
if (!rtnl_trylock())
1176+
return restart_syscall();
11751177
read_lock(&bond->lock);
11761178
write_lock_bh(&bond->curr_slave_lock);
11771179

@@ -1288,7 +1290,8 @@ static ssize_t bonding_store_active_slave(struct device *d,
12881290
struct slave *new_active = NULL;
12891291
struct bonding *bond = to_bond(d);
12901292

1291-
rtnl_lock();
1293+
if (!rtnl_trylock())
1294+
return restart_syscall();
12921295
read_lock(&bond->lock);
12931296
write_lock_bh(&bond->curr_slave_lock);
12941297

0 commit comments

Comments
 (0)