Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43cf2ed

Browse files
committedFeb 20, 2025·
softmmu: Always initialize xlat in address_space_translate_for_iotlb
The bug is an uninitialized memory read, along the translate_fail path, which results in garbage being read from iotlb_to_section, which can lead to a crash in io_readx/io_writex. The bug may be fixed by writing any value with zero in ~TARGET_PAGE_MASK, so that the call to iotlb_to_section using the xlat'ed address returns io_mem_unassigned, as desired by the translate_fail path. It is most useful to record the original physical page address, which will eventually be logged by memory_region_access_valid when the access is rejected by unassigned_mem_accepts. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1065 Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20220621153829.366423-1-richard.henderson@linaro.org>
1 parent 56ba347 commit 43cf2ed

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

‎qemu/exec.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ MemoryRegion *flatview_translate(struct uc_struct *uc, FlatView *fv, hwaddr addr
487487

488488
/* Called from RCU critical section */
489489
MemoryRegionSection *
490-
address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
490+
address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,
491491
hwaddr *xlat, hwaddr *plen,
492492
MemTxAttrs attrs, int *prot)
493493
{
@@ -496,6 +496,7 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
496496
IOMMUMemoryRegionClass *imrc;
497497
IOMMUTLBEntry iotlb;
498498
int iommu_idx;
499+
hwaddr addr = orig_addr;
499500
AddressSpaceDispatch *d = cpu->cpu_ases[asidx].memory_dispatch;
500501

501502
for (;;) {
@@ -551,6 +552,16 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,
551552
return section;
552553

553554
translate_fail:
555+
/*
556+
* We should be given a page-aligned address -- certainly
557+
* tlb_set_page_with_attrs() does so. The page offset of xlat
558+
* is used to index sections[], and PHYS_SECTION_UNASSIGNED = 0.
559+
* The page portion of xlat will be logged by memory_region_access_valid()
560+
* when this memory access is rejected, so use the original untranslated
561+
* physical address.
562+
*/
563+
assert((orig_addr & ~TARGET_PAGE_MASK) == 0);
564+
*xlat = orig_addr;
554565
return &d->map.sections[PHYS_SECTION_UNASSIGNED];
555566
}
556567

0 commit comments

Comments
 (0)
Please sign in to comment.