Skip to content

Commit cfa2083

Browse files
RestiosonFreax13
authored andcommitted
handle iomap before tss
1 parent 7e49ece commit cfa2083

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/structures/gdt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,14 @@ impl Descriptor {
452452
return Err(InvalidIoMap::TooLong { len: iomap.len() });
453453
}
454454

455-
let base = iomap.as_ptr() as usize - tss as *const _ as usize;
455+
let iomap_addr = iomap.as_ptr() as usize;
456+
let tss_addr = tss as *const _ as usize;
457+
458+
if tss_addr > iomap_addr {
459+
return Err(InvalidIoMap::IoMapBeforeTss);
460+
}
461+
462+
let base = iomap_addr - tss_addr;
456463
if base > 0xdfff {
457464
return Err(InvalidIoMap::TooFarFromTss { distance: base });
458465
}

src/structures/tss.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ impl Default for TaskStateSegment {
5555
/// The given IO permissions bitmap is invalid.
5656
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5757
pub enum InvalidIoMap {
58+
/// The IO permissions bitmap is before the TSS. It must be located after the TSS.
59+
IoMapBeforeTss,
5860
/// The IO permissions bitmap is too far from the TSS. It must be within `0xdfff` bytes of the
59-
/// start of the TSS.
61+
/// start of the TSS. Note that if the IO permissions bitmap is located before the TSS, then
62+
/// `IoMapBeforeTss` will be returned instead.
6063
TooFarFromTss {
6164
/// The distance of the IO permissions bitmap from the beginning of the TSS.
6265
distance: usize,

0 commit comments

Comments
 (0)