Skip to content

Commit b84122b

Browse files
committed
Fix bug where mem io instruction could be truncated
This fix also allows us to use unmodified seabios
1 parent 1480463 commit b84122b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

mythril/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spin = "0.5"
2626
ux = { version = "0.1.3", default-features = false }
2727

2828
[dependencies.iced-x86]
29-
version = "1.1.0"
29+
version = "1.8.0"
3030
default-features = false
3131
features = ["no_std", "decoder"]
3232

mythril/src/memory.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,8 @@ impl GuestAddressSpace {
409409
let mut out = vec![];
410410
let iter = self.frame_iter(cr3, addr, access)?;
411411

412-
// How many frames this region spans
413-
let count = (length + HostPhysFrame::SIZE - 1) / HostPhysFrame::SIZE;
414-
415412
let mut start_offset = addr.as_u64() as usize % HostPhysFrame::SIZE;
416-
for frame in iter.take(count) {
413+
for frame in iter {
417414
let frame = frame?;
418415
let array = unsafe { frame.as_array() };
419416
let slice = if start_offset + length <= HostPhysFrame::SIZE {
@@ -425,6 +422,10 @@ impl GuestAddressSpace {
425422

426423
length -= slice.len();
427424

425+
if length == 0 {
426+
break;
427+
}
428+
428429
// All frames after the first have no start_offset
429430
start_offset = 0;
430431
}
@@ -441,15 +442,11 @@ impl GuestAddressSpace {
441442
) -> Result<()> {
442443
let iter = self.frame_iter(cr3, addr, access)?;
443444

444-
// How many frames this region spans
445-
let count =
446-
(bytes.len() + HostPhysFrame::SIZE - 1) / HostPhysFrame::SIZE;
447-
448445
let mut start_offset = addr.as_u64() as usize % HostPhysFrame::SIZE;
449-
for frame in iter.take(count) {
446+
for frame in iter {
450447
let mut frame = frame?;
451448
let array = unsafe { frame.as_mut_array() };
452-
let _slice = if start_offset + bytes.len() <= HostPhysFrame::SIZE {
449+
if start_offset + bytes.len() <= HostPhysFrame::SIZE {
453450
array[start_offset..start_offset + bytes.len()]
454451
.copy_from_slice(&bytes);
455452
break;
@@ -458,7 +455,7 @@ impl GuestAddressSpace {
458455
&bytes[..(HostPhysFrame::SIZE - start_offset)],
459456
);
460457
bytes = &bytes[(HostPhysFrame::SIZE - start_offset)..];
461-
};
458+
}
462459

463460
// All frames after the first have no start_offset
464461
start_offset = 0;

seabios

0 commit comments

Comments
 (0)