Skip to content

Commit ff10e36

Browse files
haokexingregkh
authored andcommitted
net: macb: Protect access to net_device::ip_ptr with RCU lock
commit baa35a698cea26930679a20a7550bbb4c8319725 upstream. Access to net_device::ip_ptr and its associated members must be protected by an RCU lock. Since we are modifying this piece of code, let's also move it to execute only when WAKE_ARP is enabled. To minimize the duration of the RCU lock, a local variable is used to temporarily store the IP address. This change resolves the following RCU check warning: WARNING: suspicious RCU usage 7.0.0-rc3-next-20260310-yocto-standard+ #122 Not tainted ----------------------------- drivers/net/ethernet/cadence/macb_main.c:5944 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 5 locks held by rtcwake/518: #0: ffff000803ab1408 (sb_writers#5){.+.+}-{0:0}, at: vfs_write+0xf8/0x368 #1: ffff0008090bf088 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0xbc/0x1c8 #2: ffff00080098d588 (kn->active#70){.+.+}-{0:0}, at: kernfs_fop_write_iter+0xcc/0x1c8 #3: ffff800081c84888 (system_transition_mutex){+.+.}-{4:4}, at: pm_suspend+0x1ec/0x290 #4: ffff0008009ba0f8 (&dev->mutex){....}-{4:4}, at: device_suspend+0x118/0x4f0 stack backtrace: CPU: 3 UID: 0 PID: 518 Comm: rtcwake Not tainted 7.0.0-rc3-next-20260310-yocto-standard+ #122 PREEMPT Hardware name: ZynqMP ZCU102 Rev1.1 (DT) Call trace: show_stack+0x24/0x38 (C) __dump_stack+0x28/0x38 dump_stack_lvl+0x64/0x88 dump_stack+0x18/0x24 lockdep_rcu_suspicious+0x134/0x1d8 macb_suspend+0xd8/0x4c0 device_suspend+0x218/0x4f0 dpm_suspend+0x244/0x3a0 dpm_suspend_start+0x50/0x78 suspend_devices_and_enter+0xec/0x560 pm_suspend+0x194/0x290 state_store+0x110/0x158 kobj_attr_store+0x1c/0x30 sysfs_kf_write+0xa8/0xd0 kernfs_fop_write_iter+0x11c/0x1c8 vfs_write+0x248/0x368 ksys_write+0x7c/0xf8 __arm64_sys_write+0x28/0x40 invoke_syscall+0x4c/0xe8 el0_svc_common+0x98/0xf0 do_el0_svc+0x28/0x40 el0_svc+0x54/0x1e0 el0t_64_sync_handler+0x84/0x130 el0t_64_sync+0x198/0x1a0 Fixes: 0cb8de3 ("net: macb: Add ARP support to WOL") Signed-off-by: Kevin Hao <haokexin@gmail.com> Cc: stable@vger.kernel.org Reviewed-by: Théo Lebrun <theo.lebrun@bootlin.com> Link: https://patch.msgid.link/20260318-macb-irq-v2-2-f1179768ab24@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 17970e0 commit ff10e36

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5352,9 +5352,9 @@ static int __maybe_unused macb_suspend(struct device *dev)
53525352
struct macb_queue *queue;
53535353
struct in_device *idev;
53545354
unsigned long flags;
5355+
u32 tmp, ifa_local;
53555356
unsigned int q;
53565357
int err;
5357-
u32 tmp;
53585358

53595359
if (!device_may_wakeup(&bp->dev->dev))
53605360
phy_exit(bp->sgmii_phy);
@@ -5363,14 +5363,21 @@ static int __maybe_unused macb_suspend(struct device *dev)
53635363
return 0;
53645364

53655365
if (bp->wol & MACB_WOL_ENABLED) {
5366-
/* Check for IP address in WOL ARP mode */
5367-
idev = __in_dev_get_rcu(bp->dev);
5368-
if (idev)
5369-
ifa = rcu_dereference(idev->ifa_list);
5370-
if ((bp->wolopts & WAKE_ARP) && !ifa) {
5371-
netdev_err(netdev, "IP address not assigned as required by WoL walk ARP\n");
5372-
return -EOPNOTSUPP;
5366+
if (bp->wolopts & WAKE_ARP) {
5367+
/* Check for IP address in WOL ARP mode */
5368+
rcu_read_lock();
5369+
idev = __in_dev_get_rcu(bp->dev);
5370+
if (idev)
5371+
ifa = rcu_dereference(idev->ifa_list);
5372+
if (!ifa) {
5373+
rcu_read_unlock();
5374+
netdev_err(netdev, "IP address not assigned as required by WoL walk ARP\n");
5375+
return -EOPNOTSUPP;
5376+
}
5377+
ifa_local = be32_to_cpu(ifa->ifa_local);
5378+
rcu_read_unlock();
53735379
}
5380+
53745381
spin_lock_irqsave(&bp->lock, flags);
53755382

53765383
/* Disable Tx and Rx engines before disabling the queues,
@@ -5408,7 +5415,7 @@ static int __maybe_unused macb_suspend(struct device *dev)
54085415
if (bp->wolopts & WAKE_ARP) {
54095416
tmp |= MACB_BIT(ARP);
54105417
/* write IP address into register */
5411-
tmp |= MACB_BFEXT(IP, be32_to_cpu(ifa->ifa_local));
5418+
tmp |= MACB_BFEXT(IP, ifa_local);
54125419
}
54135420
spin_unlock_irqrestore(&bp->lock, flags);
54145421

0 commit comments

Comments
 (0)