Repository navigation
Commit b37617f
virtiofs: refuse a write through a handle not open for writing
VirtioFs::write checked whether the guest may write the handle's file,
which fails with EROFS on a read-only share or outside a microVM's
writable paths, and then wrote through the handle, leaving it to the
host to refuse a handle that the guest had not opened for writing. So
a FUSE_WRITE through an O_RDONLY handle of a file that the guest may
not write failed with EROFS on every host, where Linux's write(2)
fails with EBADF first (microsoft/nvx#1609), and whether a write
through such a handle of a writable file failed depended on the host's
handle, which a Windows host opened with write access for
O_RDONLY | O_TRUNC until the previous commit.
write now fails with EBADF before it checks whether the guest may
write the file, unless the access mode of the guest's open flags,
which the handle records and a microVM snapshot saves, is O_WRONLY or
O_RDWR. A guest kernel writes only through handles that it opened for
writing, so only a guest that drives the queue itself can see the
change.
writes_need_a_handle_open_for_writing, in a microVM share whose only
writable path is out, writes through handles of out/existing that
FUSE_OPEN opened O_RDONLY and O_RDONLY | O_TRUNC, of a new file that
FUSE_CREATE opened O_RDONLY | O_CREAT | O_TRUNC, and of build.log that
FUSE_OPEN opened O_RDONLY, and checks that each write fails with EBADF
and changes nothing, while a write through an O_WRONLY handle
succeeds. Without the fix, at feature/microvm/dev b51f915, the write
through the O_RDONLY | O_TRUNC handle succeeds on Windows, and the
write through build.log fails with EROFS on Linux (Azure Linux 3.0,
nvx-kvm-test) and, once the previous commit refuses the first, on
Windows; with it, the test and the package's others pass on both.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 8e3306e commit b37617f
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
467 | 475 | | |
468 | 476 | | |
469 | 477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
266 | 303 | | |
267 | 304 | | |
268 | 305 | | |
| |||
0 commit comments