|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH 1/2] x86/PV: correct descriptor read sanity check
On 24.11.2026 18:11, Andrew Cooper wrote:
> On 24/11/2026 1:30 pm, Jan Beulich wrote:
>> Checking what LAR returns against what we read from the descriptor table
>> requires that we check unaltered values. The clearing of L therefore needs
>> limiting: Do that just in *ar, and use the then unaltered desc.b in the
>> BUG_ON() instead.
>>
>> Fixes: 8d6e195a2def ("Adjust emulation code to deal with compatibility mode
>> guests")
>> Reported-by: Roger Pau Monné <roger.pau@xxxxxxx>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>>
>> --- a/xen/arch/x86/pv/emulate.c
>> +++ b/xen/arch/x86/pv/emulate.c
>> @@ -37,11 +37,12 @@ int pv_emul_read_descriptor(unsigned int
>> return 0;
>> }
>>
>> - if ( !insn_fetch )
>> - desc.b &= ~_SEGMENT_L;
>>
>> *ar = desc.b & 0x00f0ff00;
>> - if ( !(desc.b & _SEGMENT_L) )
>> + if ( !insn_fetch )
>> + *ar &= ~_SEGMENT_L;
>> +
>> + if ( !(*ar & _SEGMENT_L) )
>> {
>> *base = ((desc.a >> 16) + ((desc.b & 0xff) << 16) +
>> (desc.b & 0xff000000U));
>> @@ -57,7 +58,8 @@ int pv_emul_read_descriptor(unsigned int
>> asm volatile (
>> "larl %2,%0 ; setz %1"
>> : "=r" (a), "=qm" (valid) : "rm" (sel));
>> - BUG_ON(valid && ((a & 0x00f0ff00) != *ar));
>> + BUG_ON(valid && ((a ^ desc.b) & 0x00f0ff00));
>> +
>> asm volatile (
>> "lsll %2,%0 ; setz %1"
>> : "=r" (l), "=qm" (valid) : "rm" (sel));
>>
>
> This is a TOCTOU race, which reads the GDT/LDT 3 separate times.
Yes, hence why it's debug-only code.
> Nothing prevents another CPU issuing do_update_descriptor() against this
> descriptor, and hitting the BUG_ON() despite the care taken in this
> patch. Nor is it legitimate for there to be such an interlock.
Non-malicious code isn't going to update descriptors when they may be
in use on another (v)CPU.
> I suggest we just delete the CONFIG_DEBUG section. Because the segment
> registers aren't architecturally available for PV guests, this check
> simply cannot be made safe.
Sure, we can also delete the section, but double checking our "manual"
calculations seemed like a good idea to me back at the time, and still
does. Hence if you want the section removed, may I suggest that you
send a patch with what you think is a suitable justification? I'm okay
to ack such a patch, but I'd be less okay to make one.
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |