casaroli opened a new pull request, #20983:
URL: https://github.com/apache/nuttx/pull/20983
## Summary
`nx_umount2()` looks the target up with `inode_find()`. For a path inside a
mounted volume, `inode_find()` stops at the mount point and gives the rest of
the path in `relpath`. `nx_umount2()` did not check `relpath`, so
`umount("/mnt/sd/dir")` unmounted the volume at `/mnt/sd`. For example, `umount
/system/bin` in NSH with a volume at `/system` removed the whole `/system`
mount, and all programs in it were gone.
This PR makes `umount()` and `umount2()` fail with `EINVAL` when the target
is not the mount point itself, as POSIX and Linux do for a path that is not a
mount point.
## Impact
`umount()` and `umount2()` of a path inside a mounted volume fail with
`EINVAL` and the volume stays mounted. `umount()` of a mount point does not
change. Generic file system code: all build modes and architectures. No
documentation describes the errors of `umount()`, so there is no documentation
change.
## Testing
Test program `umountin.c` on `qemu-armv8a:knsh` (QEMU with HVF, `/system` is
a 9P volume): `umount("/system/bin")`, `umount("/system/bin/umountin")`, then
`stat()` of the program.
| | master | this PR |
|---|---|---|
| `umount("/system/bin")` | -1, `ENOENT`, and `/system` is unmounted | -1,
`EINVAL` |
| `umount("/system/bin/umountin")` | -1, `ENOENT` | -1, `EINVAL` |
| `/system/bin/umountin` is still there | no (`ENOENT`) | yes |
| ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | not run (`/system` is
gone) | status 0 |
Build, each OK: `qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel,
arm64), `lm3s6965-ek:qemu-protected` (protected, armv7-m), `rv-virt:nsh64`
(flat, rv64), `rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` (kernel,
rv64).
`tools/checkpatch.sh -c -u -m -g` passes.
--
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]