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
commit f091a78da3aaa9acad6cd4b179f2e0e224b1bfa6 Author: zhanghongyu <[email protected]> AuthorDate: Mon Nov 16 14:59:25 2026 +0800 net/can: fix the problem of nested tx in the rxcb process The synchronous rx callback may transmit a CAN frame from within can_input(). That nested send reuses the device's current I/O buffer (dev->d_iob / dev->d_buf), corrupting the frame still being delivered to the callback and leading to wrong data or a crash. Detach the current buffer before invoking the callback, run the callback, then restore the buffer with netdev_iob_replace() and put dev->d_buf back. This isolates the nested transmit from the frame under delivery. The rx callback hook lives in can_input_conn() in net/can/can.c on the current architecture, so the fix is applied there. Signed-off-by: zhanghongyu <[email protected]> --- net/can/can.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/can/can.c b/net/can/can.c index 966c3536714..603832b36b1 100644 --- a/net/can/can.c +++ b/net/can/can.c @@ -322,14 +322,25 @@ static int can_input_conn(FAR struct net_driver_s *dev, { /* Synchronous receive callback: deliver the frame directly. A * return of OK means the callback consumed the frame. + * + * Detach the current buffer first so that a nested transmit from + * inside the callback does not reuse dev->d_iob, then restore it. */ + FAR uint8_t *frame = dev->d_buf; + FAR struct iob_s *iob = dev->d_iob; + + dev->d_buf = NULL; + dev->d_iob = NULL; flags = CAN_NEWDATA; - ret = conn->rxcb(conn->rxarg, dev->d_buf); + ret = conn->rxcb(conn->rxarg, frame); if (ret == OK) { flags = 0; } + + netdev_iob_replace(dev, iob); + dev->d_buf = frame; } else {
