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 42458146f9ccab8846224c38c5c77e1494d02f47 Author: Bowen Wang <[email protected]> AuthorDate: Tue Jul 21 23:23:27 2026 +0800 net/rpmsg: do not send the shutdown to an unbound peer rpmsg_socket_shutdown() has the same race as rpmsg_socket_wakeup(): it checks conn->unbind and then calls rpmsg_send() without recvlock, so a NS_DESTROY in between makes rpmsg_send() wait the whole RPMSG_TICK_COUNT on a destroyed endpoint. Reserve the tx buffer first and check and send under recvlock, as rpmsg_socket_wakeup() does. If the peer is gone, release the buffer and return -ENOTCONN. Signed-off-by: Bowen Wang <[email protected]> --- net/rpmsg/rpmsg_sockif.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index 2a369f3fd71..03ad49692e8 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -1837,7 +1837,8 @@ static int rpmsg_socket_ioctl(FAR struct socket *psock, static int rpmsg_socket_shutdown(FAR struct socket *psock, int how) { FAR struct rpmsg_socket_conn_s *conn = psock->s_conn; - struct rpmsg_socket_shutdown_s msg; + FAR struct rpmsg_socket_shutdown_s *msg; + uint32_t len = sizeof(*msg); int ret; if (!conn->ept.rdev || atomic_read(&conn->unbind)) @@ -1847,16 +1848,36 @@ static int rpmsg_socket_shutdown(FAR struct socket *psock, int how) conn->how |= how; - msg.cmd = RPMSG_SOCKET_CMD_SHUTDOWN; - msg.how = how; + /* Reserve the tx buffer without holding recvlock, since it may block + * waiting for a free vring buffer. + */ - ret = rpmsg_send(&conn->ept, &msg, sizeof(msg)); - if (ret < 0) + msg = rpmsg_get_tx_payload_buffer(&conn->ept, &len, true); + if (msg == NULL) { - return ret; + return -ENOMEM; } - return OK; + DEBUGASSERT(len >= sizeof(*msg)); + nxmutex_lock(&conn->recvlock); + + /* See rpmsg_socket_wakeup() */ + + if (!is_rpmsg_ept_ready(&conn->ept) || atomic_read(&conn->unbind)) + { + nxmutex_unlock(&conn->recvlock); + rpmsg_release_tx_buffer(&conn->ept, msg); + return -ENOTCONN; + } + + msg->cmd = RPMSG_SOCKET_CMD_SHUTDOWN; + msg->how = how; + ret = rpmsg_send_offchannel_nocopy(&conn->ept, conn->ept.addr, + conn->ept.dest_addr, msg, + sizeof(*msg)); + + nxmutex_unlock(&conn->recvlock); + return ret < 0 ? ret : OK; } #ifdef CONFIG_NET_SOCKOPTS
