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 2e268bfa07def744140852b251c62a096589e46b Author: Marco Casaroli <[email protected]> AuthorDate: Wed Nov 18 14:47:42 2026 +0100 net/tcp: Lock the device in tcp_ioctl(). tcp_ioctl() took only the lock of the connection. The input path changes the read-ahead and the write queues of a connection with only the device locked: an ACK trims or frees write buffers, and new data goes to the read-ahead. FIONREAD, FIONSPACE and FIOC_FILEPATH read those queues, and tcp_wrbuffer_inqueue_size() (CONFIG_NET_SEND_BUFSIZE > 0) walks them, so they could see a write buffer while it is released. Now tcp_ioctl() takes the device lock and then the connection lock, as the send and receive paths do. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- net/tcp/tcp_ioctl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/tcp/tcp_ioctl.c b/net/tcp/tcp_ioctl.c index 39ad37d95c5..73077a7384f 100644 --- a/net/tcp/tcp_ioctl.c +++ b/net/tcp/tcp_ioctl.c @@ -120,9 +120,16 @@ static void tcp_path(FAR struct tcp_conn_s *conn, FAR char *buf, size_t len) int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd, unsigned long arg) { + FAR struct net_driver_s *dev = conn->dev; int ret = OK; - conn_lock(&conn->sconn); + /* The input path changes the read-ahead and the write queues with only + * the device locked (an ACK frees a write buffer): take the device lock + * too, as the send path does, before FIONREAD, FIONSPACE or the path + * look at them. + */ + + conn_dev_lock(&conn->sconn, dev); switch (cmd) { @@ -154,7 +161,7 @@ int tcp_ioctl(FAR struct tcp_conn_s *conn, int cmd, unsigned long arg) break; } - conn_unlock(&conn->sconn); + conn_dev_unlock(&conn->sconn, dev); return ret; }
