Skip to content

Commit 13626ba

Browse files
TaeheeYoogregkh
authored andcommitted
bonding: fix suspicious RCU usage in bond_ipsec_offload_ok()
[ Upstream commit 955b785 ] To dereference bond->curr_active_slave, it uses rcu_dereference(). But it and the caller doesn't acquire RCU so a warning occurs. So add rcu_read_lock(). Splat looks like: WARNING: suspicious RCU usage 5.13.0-rc6+ raspberrypi#1179 Not tainted drivers/net/bonding/bond_main.c:571 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by ping/974: #0: ffff888109e7db70 (sk_lock-AF_INET){+.+.}-{0:0}, at: raw_sendmsg+0x1303/0x2cb0 stack backtrace: CPU: 2 PID: 974 Comm: ping Not tainted 5.13.0-rc6+ raspberrypi#1179 Call Trace: dump_stack+0xa4/0xe5 bond_ipsec_offload_ok+0x1f4/0x260 [bonding] xfrm_output+0x179/0x890 xfrm4_output+0xfa/0x410 ? __xfrm4_output+0x4b0/0x4b0 ? __ip_make_skb+0xecc/0x2030 ? xfrm4_udp_encap_rcv+0x800/0x800 ? ip_local_out+0x21/0x3a0 ip_send_skb+0x37/0xa0 raw_sendmsg+0x1bfd/0x2cb0 Fixes: 18cb261 ("bonding: support hardware encryption offload to slaves") Signed-off-by: Taehee Yoo <ap420073@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 56ccdf8 commit 13626ba

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎drivers/net/bonding/bond_main.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,24 +557,34 @@ static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
557557
struct net_device *real_dev;
558558
struct slave *curr_active;
559559
struct bonding *bond;
560+
int err;
560561

561562
bond = netdev_priv(bond_dev);
563+
rcu_read_lock();
562564
curr_active = rcu_dereference(bond->curr_active_slave);
563565
real_dev = curr_active->dev;
564566

565-
if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
566-
return true;
567+
if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
568+
err = true;
569+
goto out;
570+
}
567571

568-
if (!xs->xso.real_dev)
569-
return false;
572+
if (!xs->xso.real_dev) {
573+
err = false;
574+
goto out;
575+
}
570576

571577
if (!real_dev->xfrmdev_ops ||
572578
!real_dev->xfrmdev_ops->xdo_dev_offload_ok ||
573579
netif_is_bond_master(real_dev)) {
574-
return false;
580+
err = false;
581+
goto out;
575582
}
576583

577-
return real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs);
584+
err = real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs);
585+
out:
586+
rcu_read_unlock();
587+
return err;
578588
}
579589

580590
static const struct xfrmdev_ops bond_xfrmdev_ops = {

0 commit comments

Comments
 (0)