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
1501 struct slave *slave;1501 struct slave *slave;
1502 1502
1503 if (!bond_has_slaves(bond)) {1503 if (!bond_has_slaves(bond)) {
1504 bond_info->tx_rebalance_counter = 0;1504 atomic_set(&bond_info->tx_rebalance_counter, 0);
1505 bond_info->lp_counter = 0;1505 bond_info->lp_counter = 0;
1506 goto re_arm;1506 goto re_arm;
1507 }1507 }
1508 1508
1509 rcu_read_lock();1509 rcu_read_lock();
1510 1510
1511 bond_info->tx_rebalance_counter++;1511 atomic_inc(&bond_info->tx_rebalance_counter);
1512 bond_info->lp_counter++;1512 bond_info->lp_counter++;
1513 1513
1514 /* send learning packets */1514 /* send learning packets */
@@ -1530,7 +1530,7 @@ void bond_alb_monitor(struct work_struct *work) · 15 unmodified lines
1530 }1530 }
1531 1531
1532 /* rebalance tx traffic */1532 /* 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) {
1534 bond_for_each_slave_rcu(bond, slave, iter) {1534 bond_for_each_slave_rcu(bond, slave, iter) {
1535 tlb_clear_slave(bond, slave, 1);1535 tlb_clear_slave(bond, slave, 1);
1536 if (slave == rcu_access_pointer(bond->curr_active_slave)) {1536 if (slave == rcu_access_pointer(bond->curr_active_slave)) {
@@ -1540,7 +1540,7 @@ void bond_alb_monitor(struct work_struct *work) · 3 unmodified lines
1540 bond_info->unbalanced_load = 0;1540 bond_info->unbalanced_load = 0;
1541 }1541 }
1542 }1542 }
1543 bond_info->tx_rebalance_counter = 0;1543 atomic_set(&bond_info->tx_rebalance_counter, 0);
1544 }1544 }
1545 1545
1546 if (bond_info->rlb_enabled) {1546 if (bond_info->rlb_enabled) {
@@ -1610,7 +1610,8 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave) · 63 unmodified lines
1610 tlb_init_slave(slave);1610 tlb_init_slave(slave);
1611 1611
1612 /* order a rebalance ASAP */1612 /* 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);
1614 1615
1615 if (bond->alb_info.rlb_enabled)1616 if (bond->alb_info.rlb_enabled)
1616 bond->alb_info.rlb_rebalance = 1;1617 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
1647 rlb_clear_slave(bond, slave);1648 rlb_clear_slave(bond, slave);
1648 } else if (link == BOND_LINK_UP) {1649 } else if (link == BOND_LINK_UP) {
1649 /* order a rebalance ASAP */1650 /* 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);
1651 if (bond->alb_info.rlb_enabled) {1653 if (bond->alb_info.rlb_enabled) {
1652 bond->alb_info.rlb_rebalance = 1;1654 bond->alb_info.rlb_rebalance = 1;
1653 /* If the updelay module parameter is smaller than the1655 /* 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
126struct alb_bond_info {126struct alb_bond_info {
127 struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */127 struct tlb_client_info *tx_hashtbl; /* Dynamically allocated */
128 u32 unbalanced_load;128 u32 unbalanced_load;
129 int tx_rebalance_counter;129 atomic_t tx_rebalance_counter;
130 int lp_counter;130 int lp_counter;
131 /* -------- rlb parameters -------- */131 /* -------- rlb parameters -------- */
132 int rlb_enabled;132 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