Skip to contentSkip to conversation

target/i386/tcg: Check for valid descriptor table before loading segment descriptor

PATCH New Rayhan Faizel 1 participant 1 message Aug 24, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386/tcg: Check for valid descriptor table before loading segment descriptor

LSL and LAR can cause segmentation faults in certain scenarios under QEMU. This occurs particularly when the base of either GDT or LDT depending on bit 2 of selector is NULL.

On real CPU, invalid LSL/LAR does nothing besides clearing ZF.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1376

---
 target/i386/tcg/seg_helper.c | 4 ++++
 1 file changed, 4 insertions(+)
target/i386/tcg/seg_helper.c +4 -0
index e8d19c65fd..4c36462162 100644
@@ -78,6 +78,10 @@ static inline int load_segment_ra(CPUX86State *env, uint32_t *e1_ptr,
     } else {
         dt = &env->gdt;
     }
+    /* Check valid DT base before fetching segment descriptor*/
+    if (!dt->base) {
+        return -1;
+    }
     index = selector & ~7;
     if ((index + 7) > dt->limit) {
         return -1;
Signature · 1 line
2.41.0