Skip to content

Commit d5cb957

Browse files
sohilmehhansendc
authored andcommitted
x86/cpu: Enable LASS during CPU initialization
Linear Address Space Separation (LASS) mitigates a class of side-channel attacks that rely on speculative access across the user/kernel boundary. Enable LASS along with similar security features if the platform supports it. While at it, remove the comment above the SMAP/SMEP/UMIP/LASS setup instead of updating it, as the whole sequence is quite self-explanatory. Some EFI runtime and boot services may rely on 1:1 mappings in the lower half during early boot and even after SetVirtualAddressMap(). To avoid tripping LASS, the initial CR4 programming would need to be delayed until EFI has completely finished entering virtual mode (including efi_free_boot_services()). Also, LASS would need to be temporarily disabled while switching to efi_mm to avoid potential faults on stray runtime accesses. Similarly, legacy vsyscall page accesses are flagged by LASS resulting in a #GP (instead of a #PF). Without LASS, the #PF handler emulates the accesses and returns the appropriate values. Equivalent emulation support is required in the #GP handler with LASS enabled. In case of vsyscall XONLY (execute only) mode, the faulting address is readily available in the RIP which would make it easier to reuse the #PF emulation logic. For now, keep it simple and disable LASS if either of those are compiled in. Though not ideal, this makes it easier to start testing LASS support in some environments. In future, LASS support can easily be expanded to support EFI and legacy vsyscalls. Signed-off-by: Sohil Mehta <sohil.mehta@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Dave Hansen <dave.hansen@linux.intel.com> Link: https://patch.msgid.link/20251118182911.2983253-9-sohil.mehta%40intel.com
1 parent c9129cf commit d5cb957

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

arch/x86/kernel/cpu/common.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,28 @@ static __always_inline void setup_umip(struct cpuinfo_x86 *c)
401401
cr4_clear_bits(X86_CR4_UMIP);
402402
}
403403

404+
static __always_inline void setup_lass(struct cpuinfo_x86 *c)
405+
{
406+
if (!cpu_feature_enabled(X86_FEATURE_LASS))
407+
return;
408+
409+
/*
410+
* Legacy vsyscall page access causes a #GP when LASS is active.
411+
* Disable LASS because the #GP handler doesn't support vsyscall
412+
* emulation.
413+
*
414+
* Also disable LASS when running under EFI, as some runtime and
415+
* boot services rely on 1:1 mappings in the lower half.
416+
*/
417+
if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) ||
418+
IS_ENABLED(CONFIG_EFI)) {
419+
setup_clear_cpu_cap(X86_FEATURE_LASS);
420+
return;
421+
}
422+
423+
cr4_set_bits(X86_CR4_LASS);
424+
}
425+
404426
/* These bits should not change their value after CPU init is finished. */
405427
static const unsigned long cr4_pinned_mask = X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_UMIP |
406428
X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED;
@@ -2007,10 +2029,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20072029
/* Disable the PN if appropriate */
20082030
squash_the_stupid_serial_number(c);
20092031

2010-
/* Set up SMEP/SMAP/UMIP */
20112032
setup_smep(c);
20122033
setup_smap(c);
20132034
setup_umip(c);
2035+
setup_lass(c);
20142036

20152037
/* Enable FSGSBASE instructions if available. */
20162038
if (cpu_has(c, X86_FEATURE_FSGSBASE)) {

0 commit comments

Comments
 (0)