CV-Bowen opened a new pull request, #22285:
URL: https://github.com/apache/nuttx/pull/22285
## Summary
Two use-after-free / double-free fixes in the release of an rptun
instance (`rm /dev/rptun/<cpu>` / `rptun_uninitialize()`):
- `fix the double free when autostart fails`: when
`rptun_dev_start()` fails in `rptun_initialize()`,
`unregister_driver()` unlinks the node, so `rptun_dev_unlink()` frees
priv and `rptun_initialize()` frees it again; the unlink also did
`dq_rem()` on a priv that was never queued.
- `keep the instance until the last close after unlink`: a file opened
before the unlink keeps the inode, whose `i_private` still points at
the freed priv. Open files are counted now; the last close frees priv,
and an `ioctl()` after the unlink returns -ENODEV.
## Impact
- Only `drivers/rptun/rptun.c`; the driver gets open/close ops with
`!CONFIG_DISABLE_PSEUDOFS_OPERATIONS`.
- `ioctl()` on a file of an unlinked instance returns -ENODEV.
## 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
Every commit builds sim:rpserver, sim:rpproxy, qemu-armv8a:rpserver and
qemu-armv8a:rpproxy with 0 warnings, plus sim:rpserver with
`CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y`.
sim:rpserver + sim:rpproxy with `CONFIG_MM_KASAN_ALL=y`, master vs this
PR.
**Unlink while open.** A test-only app (not in this PR) opens
`/dev/rptun/proxy`, unlinks it, then calls `ioctl(RPTUNIOC_DUMP)` and
`close()` on the fd:
```
master:
p143rm: open /dev/rptun/proxy fd 3
p143rm: unlink ret 0 errno 0
[ 5.100289] [server] kasan_report: kasan detected a read access error,
address at 0xf1d8f680,size is 4, return address: 0x4000d9ef
[ 5.100690] [server] dump_assert_info: Assertion failed panic: at file:
:0 task: p143rm process: p143rm 0x400e34ae
this PR:
p143rm: open /dev/rptun/proxy fd 3
p143rm: unlink ret 0 errno 0
p143rm: ioctl ret -1 errno 19
p143rm: close ret 0
```
**Autostart failure.** A test-only change makes `rptun_dev_start()`
fail in `rptun_initialize()`:
```
master:
[ 0.003987] [server] dump_assert_info: Assertion failed : at file:
/mm/mm_heap/mm_malloc_size.c:73 task: AppBringUp process: Kernel 0x4002881b
this PR: boots to nsh, /dev/rptun is empty
```
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]