Skip to content

Commit 3cfd6ee

Browse files
nested-svm-vmrun: document and name GDT descriptor size checks
Agent-Logs-Url: https://github.com/bernhard-xs/xtf/sessions/ff7f3b83-f4cf-44a0-be6e-69decc50df9f Co-authored-by: bernhardkaindl <43588962+bernhardkaindl@users.noreply.github.com>
1 parent 6ea74c3 commit 3cfd6ee

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/nested-svm-vmrun/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void svm_vmrun(unsigned long l2_vmcb_pa);
4141
#define L2_SENTINEL 0xc0ffeeULL
4242
static volatile uint64_t l2_handshake;
4343

44+
#define GDT_DESC_BYTES 8
45+
4446
static uint16_t user_desc_vmcb_attr(const user_desc *desc)
4547
{
4648
return desc->type |
@@ -63,7 +65,6 @@ static bool selector_is_null(uint16_t sel)
6365
static void vmcb_set_seg_desc(struct vmcb_seg *seg, const user_desc *gdt,
6466
uint16_t gdt_limit, uint16_t sel)
6567
{
66-
const uint16_t desc_size = 8;
6768
uint16_t sel_offset = sel & ~(X86_SEL_TI | X86_SEL_RPL_MASK);
6869
const user_desc *desc;
6970

@@ -77,8 +78,9 @@ static void vmcb_set_seg_desc(struct vmcb_seg *seg, const user_desc *gdt,
7778
return;
7879
}
7980

81+
/* Verify the descriptor's last byte still lies within the GDT limit. */
8082
if ( (sel & X86_SEL_TI) ||
81-
(sel_offset + desc_size - 1 > gdt_limit) )
83+
(sel_offset + GDT_DESC_BYTES - 1 > gdt_limit) )
8284
{
8385
seg->attr = 0;
8486
seg->limit = 0;

0 commit comments

Comments
 (0)