casaroli opened a new pull request, #22435:
URL: https://github.com/apache/nuttx/pull/22435

   ## Summary
   
   The callers of `local_release()` hold the lock of the local sockets, and 
`local_release()` does not take it (0ed9e99c198). But when a listening socket 
closes, `local_release()` released the lock around `local_subref()` for each 
connection that waits for `accept()` (8c2f25343b1, from #21614). So 
`local_release()` and `local_free()` of that connection ran without the lock, 
and `local_free()` removes the connection from `g_local_connections` and 
disconnects its peer.
   
   In this time another thread can use the local sockets. For example, a client 
that wakes up when its connection ends can `connect()` again to the listener 
that closes: the `connect()` succeeds, and the `close()` then ends the new 
connection too. Two threads can also change `g_local_connections` at the same 
time.
   
   Now the lock stays held. `local_subref()` and `local_release()` do not take 
the lock again, so the call does not wait for itself. A `connect()` in this 
time waits for the `close()`, and then fails with `ECONNREFUSED` or `ENOENT`.
   
   ## Impact
   
   Only the close of a listening local stream socket with connections that were 
not accepted. No API, ABI or Kconfig change. The same in all build modes and on 
all architectures.
   
   ## Testing
   
   New case `test_local_dgram_stream_listenconn` in `cmocka_net_local_dgram` 
(apache/nuttx-apps#NNNN): a client of higher priority waits in `recv()` on a 
connection that the listener did not accept; the listener closes, and the 
client connects again to the same name. On qemu-armv8a:nsh (flat, one CPU) with 
local stream and datagram sockets, CI image, QEMU TCG:
   
   | | master | this PR |
   |---|---|---|
   | test_local_dgram_stream_listenconn | FAILED (the second `connect()` 
returns 0) | PASSED |
   | the other cases of cmocka_net_local_dgram and cmocka_net_udp | 91 + 24 
PASSED | 91 + 24 PASSED |
   
   Builds with `-Werror` in the CI image, with local stream and datagram 
sockets: qemu-armv8a:nsh (flat), qemu-armv8a:knsh (kernel, with the apps), 
rv-virt:netnsh64 (flat), rv-virt:knetnsh64 (kernel, with the apps).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] net/local: Keep the lock... casaroli (via GitHub) via commits

Reply via email to