casaroli opened a new pull request, #21650: URL: https://github.com/apache/nuttx/pull/21650
## Summary `bluetooth_recvmsg()` and `ieee802154_recvmsg()` take the connection and device locks after the device lookup. When the lookup finds no device, both jump to `errout_with_lock` and call `conn_dev_unlock()` on locks that they do not hold, through a NULL radio pointer. `nxrmutex_unlock()` then asserts on `count > 0`. Without assertions, the lock count wraps, and a later lock and unlock pair leaves the socket lock held. - net/bluetooth: a `recv()` on an L2CAP socket with no Bluetooth device for its local address, or on an HCI socket with no Bluetooth device at its device index, gets to this path. Return `-ENODEV` directly. - net/ieee802154: a `recv()` on an IEEE 802.15.4 socket that is not bound gets to this path. Return `-ENODEV` directly. ## Impact `recv()` in these cases fails with `ENODEV`, as before, but does not unlock the socket lock any more. No other path changes. The code is the same in flat, protected and kernel builds and on all arches. No Documentation change. Size: -8 bytes text for `bluetooth_recvmsg.o` on nrf52840-dk:sdc, -15 bytes for each object on sim:dynconns. ## Testing Test programs: an L2CAP socket that is not bound, an HCI socket bound to device index 200 and an IEEE 802.15.4 socket that is not bound, three `recvfrom()` calls each, `CONFIG_DEBUG_ASSERTIONS=y`. - sim:bluetooth and sim:pf_ieee802154 (IEEE 802.15.4 loopback radio), Linux host. master: the first `recvfrom()` fails with `Assertion failed : at file: misc/lib_mutex.c:486` and the program is killed. This PR: each `recvfrom()` fails with `ENODEV`, PASS. - qemu-armv8a:knsh (kernel build, `CONFIG_NET_BLUETOOTH`, `CONFIG_NET_IEEE802154`, no radio device), arm64 with HVF: the same result on master (each of the three sockets) and with this PR. - ostest with this PR, the same options: qemu-armv8a:knsh exit 0, qemu-armv8a:nsh (flat build) exit 0. - Builds with `-Wno-cpp -Werror`, no warnings: nrf52840-dk:sdc, sim:dynconns, sim:bthcisock, sim:bluetooth, sim:pf_ieee802154, qemu-armv8a:knsh, qemu-armv8a:nsh (Make); sim:dynconns (CMake). - checkpatch: `tools/checkpatch.sh -c -u -m -g` passes. - apache/nuttx-apps#NNNN adds the same cases as `cmocka_net_radio`: PASSED with this PR on sim:bluetooth and sim:pf_ieee802154; the same assertion on master. -- 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]
