History

bonding: make tx_rebalance_counter an atomic

KCSAN reported a data-race [1] around tx_rebalance_counter which can be accessed from different contexts, without the protection of a lock/mutex. [1] BUG: KCSAN: data-race in bond_alb_init_slave / bond_alb_monitor write to 0xffff888157e8ca24 of 4 bytes by task 7075 on cpu 0: bond_alb_init_slave+0x713/0x860 drivers/net/bonding/bond_alb.c:1613 bond_enslave+0xd94/0x3010 drivers/net/bonding/bond_main.c:1949 do_set_master net/core/rtnetlink.c:2521 [inline] __rtnl_newlink net/core/rtnetlink.c:3475 [inline] rtnl_newlink+0x1298/0x13b0 net/core/rtnetlink.c:3506 rtnetlink_rcv_msg+0x745/0x7e0 net/core/rtnetlink.c:5571 netlink_rcv_skb+0x14e/0x250 net/netlink/af_netlink.c:2491 rtnetlink_rcv+0x18/0x20 net/core/rtnetlink.c:5589 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x5fc/0x6c0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x6e1/0x7d0 net/netlink/af_netlink.c:1916 sock_sendmsg_nosec net/socket.c:704 [inline] sock_sendmsg net/socket.c:724 [inline] ____sys_sendmsg+0x39a/0x510 net/socket.c:2409 ___sys_sendmsg net/socket.c:2463 [inline] __sys_sendmsg+0x195/0x230 net/socket.c:2492 __do_sys_sendmsg net/socket.c:2501 [inline] __se_sys_sendmsg net/socket.c:2499 [inline] __x64_sys_sendmsg+0x42/0x50 net/socket.c:2499 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae read to 0xffff888157e8ca24 of 4 bytes by task 1082 on cpu 1: bond_alb_monitor+0x8f/0xc00 drivers/net/bonding/bond_alb.c:1511 process_one_work+0x3fc/0x980 kernel/workqueue.c:2298 worker_thread+0x616/0xa70 kernel/workqueue.c:2445 kthread+0x2c7/0x2e0 kernel/kthread.c:327 ret_from_fork+0x1f/0x30 value changed: 0x00000001 -> 0x00000064 Reported by Kernel Concurrency Sanitizer on: CPU: 1 PID: 1082 Comm: kworker/u4:3 Not tainted 5.16.0-rc3-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Workqueue: bond1 bond_alb_monitor

Eric Dumazet committed 4 years ago

Commit dac8e001 parent 03cfda42 files · +9 −7Browse files

Unified · Split

2 files
  1. drivers/net/bonding/bond_alb.c +8 −6
  2. include/net/bond_alb.h +1 −1
drivers/net/bonding/bond_alb.c+8−6
@@ -1501,14 +1501,14 @@ void bond_alb_monitor(struct work_struct *work) · 1500 unmodified lines
15011501 struct slave *slave;
15021502
15031503 if (!bond_has_slaves(bond)) {
1504− bond_info->tx_rebalance_counter = 0;
1504+ atomic_set(&bond_info->tx_rebalance_counter, 0);
15051505 bond_info->lp_counter = 0;
15061506 goto re_arm;
15071507 }
15081508
15091509 rcu_read_lock();
15101510
1511− bond_info->tx_rebalance_counter++;
1511+ atomic_inc(&bond_info->tx_rebalance_counter);
15121512 bond_info->lp_counter++;
15131513
15141514 /* send learning packets */
@@ -1530,7 +1530,7 @@ void bond_alb_monitor(struct work_struct *work) · 15 unmodified lines
15301530 }
15311531
15321532 /* rebalance tx traffic */
1533− if (bond_info->tx_rebalance_counter >= BOND_TLB_REBALANCE_TICKS) {
1533+ if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) {
15341534 bond_for_each_slave_rcu(bond, slave, iter) {
15351535 tlb_clear_slave(bond, slave, 1);
15361536 if (slave == rcu_access_pointer(bond->curr_active_slave)) {
@@ -1540,7 +1540,7 @@ void bond_alb_monitor(struct work_struct *work) · 3 unmodified lines
15401540 bond_info->unbalanced_load = 0;
15411541 }
15421542 }
1543− bond_info->tx_rebalance_counter = 0;
1543+ atomic_set(&bond_info->tx_rebalance_counter, 0);
15441544 }
15451545
15461546 if (bond_info->rlb_enabled) {
@@ -1610,7 +1610,8 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave) · 63 unmodified lines
16101610 tlb_init_slave(slave);
16111611
16121612 /* order a rebalance ASAP */
1613− bond->alb_info.tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1613+ atomic_set(&bond->alb_info.tx_rebalance_counter,
1614+ BOND_TLB_REBALANCE_TICKS);
16141615
16151616 if (bond->alb_info.rlb_enabled)
16161617 bond->alb_info.rlb_rebalance = 1;
@@ -1647,7 +1648,8 @@ void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char · 30 unmodified lines
16471648 rlb_clear_slave(bond, slave);
16481649 } else if (link == BOND_LINK_UP) {
16491650 /* order a rebalance ASAP */
1650− bond_info->tx_rebalance_counter = BOND_TLB_REBALANCE_TICKS;
1651+ atomic_set(&bond_info->tx_rebalance_counter,
1652+ BOND_TLB_REBALANCE_TICKS);
16511653 if (bond->alb_info.rlb_enabled) {
16521654 bond->alb_info.rlb_rebalance = 1;
16531655 /* If the updelay module parameter is smaller than the
include/net/bond_alb.h+1−1
@@ -126,7 +126,7 @@ struct tlb_slave_info { · 125 unmodified lines
126126 struct alb_bond_info {
127127 struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */
128128 u32 unbalanced_load;
129− int tx_rebalance_counter;
129+ atomic_t tx_rebalance_counter;
130130 int lp_counter;
131131 /* -------- rlb parameters -------- */
132132 int rlb_enabled;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t