Skip to content

passthrough: fall back to caller's flags when writeback open promotio… - #263

Merged
jiangliu merged 1 commit into
cloud-hypervisor:masterfrom
jiangliu:fix/writeback-owronly-fallback
Oct 10, 2026
Merged

jiangliu merged 1 commit into
cloud-hypervisor:masterfrom
jiangliu:fix/writeback-owronly-fallback

Conversation

@jiangliu

@jiangliu jiangliu commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

With writeback cache enabled, get_writeback_open_flags() promotes O_WRONLY to O_RDWR so the kernel can issue read requests through the handle. For a file the caller may only write (e.g. mode 0o200, where the owner has no read permission) the promoted open fails with EACCES, turning a valid O_WRONLY open or CREATE into a spurious failure: without writeback the kernel would never issue reads on the handle anyway.

Retry with the caller's access mode when the promoted open fails with EACCES, keeping the other writeback adjustments (O_APPEND stays cleared): the handle is then genuinely write-only and a kernel READ on it fails with the real error instead. The same fallback covers CREATE, where a mode that denies read access to the owner would otherwise fail the whole creation; if the first attempt already created the file the retry answers EEXIST and the existing-file path opens it with the caller's flags.

The fallback is guarded on the access mode actually having been promoted, so an explicit O_RDWR request on a write-only file still fails with EACCES.

Ported from PR #220 ("Fix O_WRONLY open for files without read permission").

…n fails

With writeback cache enabled, get_writeback_open_flags() promotes O_WRONLY
to O_RDWR so the kernel can issue read requests through the handle.  For a
file the caller may only write (e.g. mode 0o200, where the owner has no
read permission) the promoted open fails with EACCES, turning a valid
O_WRONLY open or CREATE into a spurious failure: without writeback the
kernel would never issue reads on the handle anyway.

Retry with the caller's access mode when the promoted open fails with
EACCES, keeping the other writeback adjustments (O_APPEND stays cleared):
the handle is then genuinely write-only and a kernel READ on it fails with
the real error instead.  The same fallback covers CREATE, where a mode
that denies read access to the owner would otherwise fail the whole
creation; if the first attempt already created the file the retry answers
EEXIST and the existing-file path opens it with the caller's flags.

The fallback is guarded on the access mode actually having been promoted,
so an explicit O_RDWR request on a write-only file still fails with EACCES.

Ported from PR cloud-hypervisor#220 ("Fix O_WRONLY open for files without read permission").

Co-authored-by: EJ Campbell <ejc3@users.noreply.github.com>
Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
@jiangliu jiangliu added the run-benchmark Run performance benchmark for the PR label Oct 10, 2026
@jiangliu
jiangliu merged commit 33a7369 into cloud-hypervisor:master Oct 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-benchmark Run performance benchmark for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant