Skip to content

fw_cfg device fixes - #579

Merged
Lencerf merged 5 commits into
google:mainfrom
Lencerf:fix/fw-cfg
Dec 3, 2026
Merged

Lencerf merged 5 commits into
google:mainfrom
Lencerf:fix/fw-cfg

Conversation

@Lencerf

@Lencerf Lencerf commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

FwCfgContentAccess::read() previously never advanced self.offset across
calls and returned Err(ErrorKind::UnexpectedEof) when reading at or past
EOF. If a guest memory write spanned multiple slices (causing multiple
Read::read() calls), subsequent calls re-read from the original offset.

Advance self.offset by the bytes read, return Ok(0) at EOF per the
std::io::Read contract, and use FileExt::read_at() for file-backed items.

Fixes: 01ff8cf ("feat(dev): implement QEMU's fw_cfg device")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
FwCfg::dma_read_content() only wrote min(content_size, len) bytes to
guest memory and left the remainder untouched. When a guest reads an
unset (empty) item such as FW_CFG_KERNEL_SIZE or FW_CFG_INITRD_SIZE via
DMA into an uninitialized stack variable (as EDK2 QemuFwCfgRead32()
does), the guest observes stale stack contents instead of zeros.

Chain io::repeat(0) onto the item reader and write the full requested
length, matching QEMU's fw_cfg_dma_transfer() behavior.

Fixes: 01ff8cf ("feat(dev): implement QEMU's fw_cfg device")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
Per the QEMU fw_cfg specification, a guest submitting a 32-bit DMA
descriptor address only needs to write the low 32 bits (DMA_LO) and may
omit writing DMA_HI. Because FwCfg::do_dma() never cleared
self.dma_address, a 32-bit DMA transfer following a >4 GiB transfer
inherited the stale upper 32 bits.

Reset self.dma_address to 0 at the start of do_dma().

Fixes: 01ff8cf ("feat(dev): implement QEMU's fw_cfg device")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
In FwCfg::do_dma(), handling the SELECT control bit assigned
control.select() as u16 (always 1) instead of control.selector() as u16,
did not reset self.data_offset to 0, and rejected select-only DMA
descriptors with an error.

Read the selector from control.selector(), reset self.data_offset to 0,
and treat select-only DMA descriptors as valid no-op transfers.

Fixes: 01ff8cf ("feat(dev): implement QEMU's fw_cfg device")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
A malicious or misbehaving guest could crash the VMM via fw_cfg DMA by
either issuing a WRITE request (hitting unimplemented!() in dma_write())
or issuing SKIP requests whose lengths overflow data_offset.

Return ErrorKind::Unsupported from dma_write() so do_dma() reports the
DMA error bit to the guest, and use saturating_add() for DMA SKIP.

Fixes: 01ff8cf ("feat(dev): implement QEMU's fw_cfg device")
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
@coveralls

coveralls commented Dec 3, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 47013604486

Warning

No base build found for commit 23e6d20 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 48.229%

Details

  • Patch coverage: 1 uncovered change across 1 file (24 of 25 lines covered, 96.0%).

Uncovered Changes

File Changed Covered %
alioth/src/device/fw_cfg/fw_cfg.rs 25 24 96.0%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 17090
Covered Lines: 8024
Line Coverage: 46.95%
Relevant Branches: 1992
Covered Branches: 1179
Branch Coverage: 59.19%
Branches in Coverage %: Yes
Coverage Strength: 964.68 hits per line

💛 - Coveralls

@Lencerf
Lencerf added this pull request to the merge queue Dec 3, 2026
Merged via the queue into google:main with commit 0e6b81d Dec 3, 2026
20 checks passed
@Lencerf
Lencerf deleted the fix/fw-cfg branch December 3, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants