Skip to content

Commit 780a8d6

Browse files
committed
error if base =/= expected base
1 parent 7051f97 commit 780a8d6

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
@@ -320,16 +320,23 @@ impl Descriptor {
320320
return Err(InvalidIoMap::TooLong { len: iomap.len() })
321321
}
322322

323-
let distance = iomap.as_ptr() as usize - tss as *const _ as usize;
324-
if distance > 0xdfff {
325-
return Err(InvalidIoMap::TooFarFromTss { distance })
323+
let base = iomap.as_ptr() as usize - tss as *const _ as usize;
324+
if base > 0xdfff {
325+
return Err(InvalidIoMap::TooFarFromTss { distance: base })
326326
}
327327

328328
let last_byte = *iomap.last().unwrap_or(&0xff);
329329
if last_byte != 0xff {
330330
return Err(InvalidIoMap::InvalidTerminatingByte { byte: last_byte })
331331
}
332332

333+
if tss.iomap_base != base as u16 {
334+
return Err(InvalidIoMap::InvalidBase {
335+
expected: base as u16,
336+
got: tss.iomap_base
337+
});
338+
}
339+
333340
// SAFETY: all invariants checked above
334341
Ok(unsafe { Self::tss_segment_raw(tss, iomap.len() as u16) })
335342
}

src/structures/tss.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ pub enum InvalidIoMap {
5555
TooLong {
5656
len: usize
5757
},
58+
/// The `iomap_base` in the `TaskStateSegment` struct was not what was expected.
59+
InvalidBase {
60+
expected: u16,
61+
got: u16,
62+
}
5863
}

0 commit comments

Comments
 (0)