Patch "KVM: x86/vmx: Do not skip segment attributes if unusable bit is set" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    KVM: x86/vmx: Do not skip segment attributes if unusable bit is set

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     kvm-x86-vmx-do-not-skip-segment-attributes-if-unusab.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 8d5ec3063609eada0cbc79f51a7702bbf3daff29
Author: Hendrik Borghorst <hborghor@xxxxxxxxx>
Date:   Mon Nov 14 16:48:23 2022 +0000

    KVM: x86/vmx: Do not skip segment attributes if unusable bit is set
    
    [ Upstream commit a44b331614e6f7e63902ed7dff7adc8c85edd8bc ]
    
    When serializing and deserializing kvm_sregs, attributes of the segment
    descriptors are stored by user space. For unusable segments,
    vmx_segment_access_rights skips all attributes and sets them to 0.
    
    This means we zero out the DPL (Descriptor Privilege Level) for unusable
    entries.
    
    Unusable segments are - contrary to their name - usable in 64bit mode and
    are used by guests to for example create a linear map through the
    NULL selector.
    
    VMENTER checks if SS.DPL is correct depending on the CS segment type.
    For types 9 (Execute Only) and 11 (Execute Read), CS.DPL must be equal to
    SS.DPL [1].
    
    We have seen real world guests setting CS to a usable segment with DPL=3
    and SS to an unusable segment with DPL=3. Once we go through an sregs
    get/set cycle, SS.DPL turns to 0. This causes the virtual machine to crash
    reproducibly.
    
    This commit changes the attribute logic to always preserve attributes for
    unusable segments. According to [2] SS.DPL is always saved on VM exits,
    regardless of the unusable bit so user space applications should have saved
    the information on serialization correctly.
    
    [3] specifies that besides SS.DPL the rest of the attributes of the
    descriptors are undefined after VM entry if unusable bit is set. So, there
    should be no harm in setting them all to the previous state.
    
    [1] Intel SDM Vol 3C 26.3.1.2 Checks on Guest Segment Registers
    [2] Intel SDM Vol 3C 27.3.2 Saving Segment Registers and Descriptor-Table
    Registers
    [3] Intel SDM Vol 3C 26.3.2.2 Loading Guest Segment Registers and
    Descriptor-Table Registers
    
    Cc: Alexander Graf <graf@xxxxxxxxx>
    Cc: stable@xxxxxxxxxxxxxxx
    Signed-off-by: Hendrik Borghorst <hborghor@xxxxxxxxx>
    Reviewed-by: Jim Mattson <jmattson@xxxxxxxxxx>
    Reviewed-by: Alexander Graf <graf@xxxxxxxxxx>
    Message-Id: <20221114164823.69555-1-hborghor@xxxxxxxxx>
    Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 5c4d2758b1d9..ec821a5d131a 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -5521,18 +5521,15 @@ static u32 vmx_segment_access_rights(struct kvm_segment *var)
 {
 	u32 ar;
 
-	if (var->unusable || !var->present)
-		ar = 1 << 16;
-	else {
-		ar = var->type & 15;
-		ar |= (var->s & 1) << 4;
-		ar |= (var->dpl & 3) << 5;
-		ar |= (var->present & 1) << 7;
-		ar |= (var->avl & 1) << 12;
-		ar |= (var->l & 1) << 13;
-		ar |= (var->db & 1) << 14;
-		ar |= (var->g & 1) << 15;
-	}
+	ar = var->type & 15;
+	ar |= (var->s & 1) << 4;
+	ar |= (var->dpl & 3) << 5;
+	ar |= (var->present & 1) << 7;
+	ar |= (var->avl & 1) << 12;
+	ar |= (var->l & 1) << 13;
+	ar |= (var->db & 1) << 14;
+	ar |= (var->g & 1) << 15;
+	ar |= (var->unusable || !var->present) << 16;
 
 	return ar;
 }



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux