Repository navigation
fw_cfg device fixes - #579
Merged
Merged
Conversation
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>
Coverage Report for CI Build 47013604486Warning No base build found for commit Coverage: 48.229%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.