Skip to content

Commit c03a90a

Browse files
RestiosonFreax13
authored andcommitted
error if base =/= expected base
1 parent f13551e commit c03a90a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/structures/gdt.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,23 @@ impl Descriptor {
453453
return Err(InvalidIoMap::TooLong { len: iomap.len() })
454454
}
455455

456-
let distance = iomap.as_ptr() as usize - tss as *const _ as usize;
457-
if distance > 0xdfff {
458-
return Err(InvalidIoMap::TooFarFromTss { distance })
456+
let base = iomap.as_ptr() as usize - tss as *const _ as usize;
457+
if base > 0xdfff {
458+
return Err(InvalidIoMap::TooFarFromTss { distance: base })
459459
}
460460

461461
let last_byte = *iomap.last().unwrap_or(&0xff);
462462
if last_byte != 0xff {
463463
return Err(InvalidIoMap::InvalidTerminatingByte { byte: last_byte })
464464
}
465465

466+
if tss.iomap_base != base as u16 {
467+
return Err(InvalidIoMap::InvalidBase {
468+
expected: base as u16,
469+
got: tss.iomap_base
470+
});
471+
}
472+
466473
// SAFETY: all invariants checked above
467474
Ok(unsafe { Self::tss_segment_raw(tss, iomap.len() as u16) })
468475
}

src/structures/tss.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ pub enum InvalidIoMap {
6868
TooLong {
6969
len: usize
7070
},
71+
/// The `iomap_base` in the `TaskStateSegment` struct was not what was expected.
72+
InvalidBase {
73+
expected: u16,
74+
got: u16,
75+
}
7176
}
7277

7378
#[cfg(test)]

0 commit comments

Comments
 (0)