CV-Bowen opened a new pull request, #22262:
URL: https://github.com/apache/nuttx/pull/22262
## Summary
Three patches to the OpenAMP copy that NuttX builds, in the order they
were made. They prepare the name service handling for the rpmsg_port
transport.
- `openamp: hold the endpoint across the ns bound callback` (patch
0026): `rpmsg_virtio_ns_callback()` drops `rdev->lock` before it calls
`ns_bound_cb()` for `NS_CREATE` and `NS_CREATE_ACK`, so a concurrent
`close()` can free the endpoint while the callback still uses it. Take
a reference around the callback, as the `NS_DESTROY` path already does
around `ns_unbind_cb()`.
- `openamp: move the name service handling into rpmsg_ns.c` (patch
0027): the transport independent part of that callback becomes
`rpmsg_ns_handle_msg()` in the new `lib/rpmsg/rpmsg_ns.c`, so that
rpmsg_port can call it instead of keeping its own copy (follow-up PR).
No functional change. `open-amp.defs` builds the new file; CMake picks
it up from the OpenAMP `CMakeLists.txt` the patch extends.
- `openamp: take the ns endpoint reference just once` (patch 0028): one
reference taken after the lookup and dropped at the end, instead of
one per branch.
In this OpenAMP version `rpmsg_ept_incref()` / `rpmsg_ept_decref()`
still have to be called with `rdev->lock` held, so the decrement after
the callbacks retakes the lock, as the existing `NS_DESTROY` path does.
## Impact
- OpenAMP gains `lib/rpmsg/rpmsg_ns.c` and the internal
`rpmsg_ns_handle_msg()`. No public API, Kconfig or protocol change.
- Closes the use-after-free window on the bound callbacks.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
`openamp/open-amp` extracted with the new patch list is identical
(`diff -r`) to the tree the patches were generated from. Every commit
builds sim:rpserver, sim:rpproxy, qemu-armv8a:rpserver,
qemu-armv8a:rpproxy, sim:rpserver_uart, sim:rpserver with
`CONFIG_OPENAMP_VIRTIO_DEVICE_SUPPORT=n` and sim:rpserver with
`CONFIG_RPMSG_POOL_COUNT=8` + `CONFIG_RPMSG_WQUEUE_NUMBER=2` with 0
warnings (CMake), and sim:rpserver with make, which compiles
`open-amp/lib/rpmsg/rpmsg_ns.c`.
Not tested at runtime: the use-after-free itself, which needs a
`close()` racing the bound callback.
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC
disabled, which current master needs for nxinit to start nsh there; unrelated
to this change.
--
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]