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

   ## Summary
   
   **fs/v9fs: Fail readlink() of a file that is not a symbolic link.** 
`readlink()` of a regular file or a directory must fail with `EINVAL`. v9fs 
sent `Treadlink` for any file. With the "mapped" security models of QEMU 
(`security_model=mapped-xattr` or `mapped-file`), a symbolic link is stored on 
the host as a regular file that holds the target, and the server answers 
`Treadlink` for any regular file with its contents:
   
   - `readlink("/etc/hostname")` returned the host name, with no error;
   - `readlink()` of a large file gives a reply that does not fit the receive 
buffer: QEMU stops the 9p device (`Failed to encode VirtFS reply type 23`) and 
the caller waits forever. CPython calls `readlink()` on its own executable at 
start, so every Python run hung on such a root file system.
   
   The change gets the attributes of the file (`Tgetattr`) first and returns 
`-EINVAL` when it is not a symbolic link. A directory now also gives `EINVAL` 
(it gave `EISDIR`).
   
   ## Impact
   
   - `readlink()` on a v9fs volume behaves as POSIX requires with every server 
security model. With `security_model=none` or `passthrough` nothing changes for 
regular files (the host `readlink()` already failed with `EINVAL`).
   - One more round trip (`Tgetattr`) per `readlink()` call.
   - Same behavior in flat, protected and kernel builds; v9fs code only, no 
architecture code.
   
   ## Testing
   
   Test program `readlinkreg.c` on the 9p volume `/system` of 
`qemu-armv8a:knsh` (kernel build) with `CONFIG_FS_LINKS=y`, QEMU with HVF, 
`-fsdev local,...,security_model=mapped-xattr`:
   
   | Case | master | this PR |
   |---|---|---|
   | `readlink()` of a small regular file: -1 `EINVAL` | FAIL (returns 8, the 
contents) | PASS |
   | `readlink()` of a directory: -1 `EINVAL` | FAIL (`EISDIR`) | PASS |
   | `readlink()` of a symbolic link: the target | PASS | PASS |
   | `readlink()` of a 64 KiB regular file: -1 `EINVAL` | FAIL (returns 0) | 
PASS |
   
   ostest exits with status 0 on `qemu-armv8a:knsh` and `qemu-armv8a:nsh`.
   
   Build check with `CONFIG_FS_V9FS=y`: qemu-armv8a:nsh, qemu-armv8a:knsh, 
rv-virt:nsh64, rv-virt:pnsh64, rv-virt:knsh64, qemu-intel64:knsh_romfs, 
sim:nsh, qemu-armv7a:knsh: all OK, `v9fs.c` compiled in each.
   
   `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]

Reply via email to