From: Andrew Cooper Date: Mon, 9 Apr 2018 13:06:20 +0000 (+0100) Subject: Introduce __{KERN,USER}_{CS,DS}32 selector constants X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6f45086733cc1ce92ec093533097900a0de1c7b4;p=xtf.git Introduce __{KERN,USER}_{CS,DS}32 selector constants These are intended to facilitate 64bit compatiblity mode segments, but are exposed in 32bit builds as straight aliases of __{KERN,USER}_{CS,DS} for the benefit of common code. Fix up one opencoded use in the XSA-196 PoC. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/include/arch/segment.h b/arch/x86/include/arch/segment.h index 328d464..d915e97 100644 --- a/arch/x86/include/arch/segment.h +++ b/arch/x86/include/arch/segment.h @@ -50,17 +50,27 @@ #ifdef __x86_64__ -#define __KERN_CS (GDTE_CS64_DPL0 * 8) -#define __KERN_DS (0) -#define __USER_CS (GDTE_CS64_DPL3 * 8 + 3) -#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) +#define __KERN_CS (GDTE_CS64_DPL0 * 8) +#define __KERN_DS (0) +#define __KERN_CS32 (GDTE_CS32_DPL0 * 8) +#define __KERN_DS32 __KERN_DS + +#define __USER_CS (GDTE_CS64_DPL3 * 8 + 3) +#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) +#define __USER_CS32 (GDTE_CS32_DPL3 * 8 + 3) +#define __USER_DS32 __USER_DS #else /* __x86_64__ */ -#define __KERN_CS (GDTE_CS32_DPL0 * 8) -#define __KERN_DS (GDTE_DS32_DPL0 * 8) -#define __USER_CS (GDTE_CS32_DPL3 * 8 + 3) -#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) +#define __KERN_CS (GDTE_CS32_DPL0 * 8) +#define __KERN_DS (GDTE_DS32_DPL0 * 8) +#define __KERN_CS32 __KERN_CS +#define __KERN_DS32 __KERN_DS + +#define __USER_CS (GDTE_CS32_DPL3 * 8 + 3) +#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3) +#define __USER_CS32 __USER_CS +#define __USER_DS32 __USER_DS #endif /* __x86_64__ */ @@ -83,17 +93,27 @@ * __{KERN,USER}_DS are used for all data selectors including %ss, use the * FLAT_RING3_SS64 rather than FLAT_RING3_DS64. */ -#define __KERN_CS (FLAT_RING3_CS64 & ~3) -#define __KERN_DS (FLAT_RING3_SS64 & ~3) -#define __USER_CS FLAT_RING3_CS64 -#define __USER_DS FLAT_RING3_SS64 +#define __KERN_CS (FLAT_RING3_CS64 & ~3) +#define __KERN_DS (FLAT_RING3_SS64 & ~3) +#define __KERN_CS32 (FLAT_RING3_CS32 & ~3) +#define __KERN_DS32 __KERN_DS + +#define __USER_CS FLAT_RING3_CS64 +#define __USER_DS FLAT_RING3_SS64 +#define __USER_CS32 FLAT_RING3_CS32 +#define __USER_DS32 __USER_DS #else /* __x86_64__ */ -#define __KERN_CS FLAT_RING1_CS -#define __KERN_DS FLAT_RING1_DS -#define __USER_CS FLAT_RING3_CS -#define __USER_DS FLAT_RING3_DS +#define __KERN_CS FLAT_RING1_CS +#define __KERN_DS FLAT_RING1_DS +#define __KERN_CS32 __KERN_CS +#define __KERN_DS32 __KERN_DS + +#define __USER_CS FLAT_RING3_CS +#define __USER_DS FLAT_RING3_DS +#define __USER_CS32 __USER_CS +#define __USER_DS32 __USER_DS #endif /* __x86_64__ */ diff --git a/tests/xsa-196/main.c b/tests/xsa-196/main.c index 7d4a68f..504ea69 100644 --- a/tests/xsa-196/main.c +++ b/tests/xsa-196/main.c @@ -60,7 +60,7 @@ unsigned long compat_userspace(void) ".code64; 1:" : "+a" (fault) : [df] "i" (X86_EXC_DF), - [cs32] "i" (GDTE_CS32_DPL3 * 8 + 3), + [cs32] "i" (__USER_CS32), [cs] "i" (__USER_CS), "X" (ex_record_fault_eax));