Skip to content

Commit

Permalink
exec: Relax range check in ram_block_discard_range()
Browse files Browse the repository at this point in the history
We want to make use of ram_block_discard_range() in the RAM block resize
callback when growing a RAM block, *before* used_length is changed.
Let's relax the check. As RAM blocks always mmap the whole max_length area,
we cannot corrupt unrelated data.

Reviewed-by: Peter Xu <[email protected]>
Signed-off-by: David Hildenbrand <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Dr. David Alan Gilbert <[email protected]>
  • Loading branch information
davidhildenbrand authored and dagrh committed May 13, 2021
1 parent c7c0e72 commit dcdc460
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions softmmu/physmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
goto err;
}

if ((start + length) <= rb->used_length) {
if ((start + length) <= rb->max_length) {
bool need_madvise, need_fallocate;
if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
error_report("ram_block_discard_range: Unaligned length: %zx",
Expand Down Expand Up @@ -3567,7 +3567,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
} else {
error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu64
"/%zx/" RAM_ADDR_FMT")",
rb->idstr, start, length, rb->used_length);
rb->idstr, start, length, rb->max_length);
}

err:
Expand Down

0 comments on commit dcdc460

Please sign in to comment.