Skip to content

Commit fa95830

Browse files
committed
handle iomap before tss
1 parent fa5d40e commit fa95830

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/structures/gdt.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ impl Descriptor {
320320
return Err(InvalidIoMap::TooLong { len: iomap.len() });
321321
}
322322

323-
let base = iomap.as_ptr() as usize - tss as *const _ as usize;
323+
let iomap_addr = iomap.as_ptr() as usize;
324+
let tss_addr = tss as *const _ as usize;
325+
326+
if tss_addr > iomap_addr {
327+
return Err(InvalidIoMap::IoMapBeforeTss);
328+
}
329+
330+
let base = iomap_addr - tss_addr;
324331
if base > 0xdfff {
325332
return Err(InvalidIoMap::TooFarFromTss { distance: base });
326333
}

src/structures/tss.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ impl TaskStateSegment {
4242
/// The given IO permissions bitmap is invalid.
4343
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
4444
pub enum InvalidIoMap {
45+
/// The IO permissions bitmap is before the TSS. It must be located after the TSS.
46+
IoMapBeforeTss,
4547
/// The IO permissions bitmap is too far from the TSS. It must be within `0xdfff` bytes of the
46-
/// start of the TSS.
48+
/// start of the TSS. Note that if the IO permissions bitmap is located before the TSS, then
49+
/// `IoMapBeforeTss` will be returned instead.
4750
TooFarFromTss {
4851
/// The distance of the IO permissions bitmap from the beginning of the TSS.
4952
distance: usize,

0 commit comments

Comments
 (0)