This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c7b787f8b46 drivers/net: Take the device lock around each received
frame.
c7b787f8b46 is described below
commit c7b787f8b4672848746d52d00951cd7ae220202f
Author: zhanghongyu <[email protected]>
AuthorDate: Thu Nov 19 16:52:28 2026 +0800
drivers/net: Take the device lock around each received frame.
Commit 7f04498f157 ("drivers/net/vlan: strip vlan devices from their
reliance on real device lock") removed netdev_lock() from around the
receive loop in netdev_upper_rxpoll_work() so that a VLAN frame could be
dispatched without the real device lock. The non-VLAN branch of the loop
lost the lock as well, although netdev_upper_input() requires it and
netdev_upper_txavail_work() still takes it. Receive and transmit then
raced on dev->d_iob: devif_send() prepares dev->d_iob and copies into it,
and an unlocked receive could replace or release that IOB in between, so
iob_trycopyin() got a NULL chain:
Assertion failed : at file: iob/iob_copyin.c:69 task: hpwork
Take the lock around each non-VLAN frame instead of around the whole
loop. The lock is restored for netdev_upper_input() while the VLAN
dispatch keeps running without it.
Assisted-by: Kiro:claude-opus-5
Signed-off-by: zhanghongyu <[email protected]>
---
drivers/net/netdev_upperhalf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c
index 9c43464dcc9..36c5ebd38cc 100644
--- a/drivers/net/netdev_upperhalf.c
+++ b/drivers/net/netdev_upperhalf.c
@@ -821,7 +821,8 @@ static void netdev_upper_input(FAR struct net_driver_s *dev)
* upper - Reference to the upper half driver structure
*
* Assumptions:
- * Called with the network locked.
+ * Called without the network device locked. The lock is taken around
+ * each non-VLAN frame while it is handed to the network stack.
*
****************************************************************************/
@@ -848,8 +849,14 @@ static void netdev_upper_rxpoll_work(FAR struct
netdev_upperhalf_s *upper)
}
#endif
+ /* netdev_upper_input() requires the device lock, and the TX path
+ * takes it too, so both sides must hold it to not race on d_iob.
+ */
+
+ netdev_lock(dev);
netpkt_put(dev, pkt, NETPKT_RX);
netdev_upper_input(dev);
+ netdev_unlock(dev);
}
}