From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 628F6326942; Thu, 13 Nov 2025 22:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073920; cv=none; b=tXik9x3EmtwIaZNs81T1mC3r0Uyt9quOX27gigEKQxBRzvMcFj1pgu/m1+zdkjyOI5AUhFI6bJFU+QuC2mW7KBCGUqVRG4bAznfcFIpDEARRvB/eY39Ngtw9+XyQLDfORrj38IMBv9DJuHhEHaRS9j+nwT9E6DLNAmPw0xxc/fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073920; c=relaxed/simple; bh=iGj4Bp38cIMAdXi3xTm5k9nWPfso400Ax3LsO+5Bkt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S2yYVuDP3APaD7/sYy4XRR2gokpbGcB7i4RV23EGmzMxOxurZQoiAW9IY3aOa/w5SmPnp/l9eZyVNGJ0SIGSLl/pWep2qgl8OeWXfyge9vO9cppXGow6i8ttPMB2XHWZ7ts3h9+JHdN1kLkNIBMfA0wFuzBEYDpbrjSuj9BzkQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=LRaSSnLm; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LRaSSnLm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073918; x=1794609918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iGj4Bp38cIMAdXi3xTm5k9nWPfso400Ax3LsO+5Bkt0=; b=LRaSSnLmHKuRNnGIZIdsIRtgY+GH4QoxidmG+mIQy1Rtviipkzxe7muv OQPPKTac8oev9rQBt9y2xR3JYYojJac85A0QRXn6cnagKJU6B6DS4G112 4EHV3UdYfsLi9f2q5P9CNpG6PbA1RDFZypJ0eS2xn7MlOF9kSQOl/o9qR sdaGGSYtpC6c9iZDfcljSDqhm0rg/qZ/865/F9kVE80luJw6FqyzoUtmg rlm+WnHbob07usWTpmKeakx5XTuzSTlqBjRoYHBGNwqkv9KdCxAbWSNIY QezU/A3Jjy0ALTnjOSujmnfFM2UUn/6cfrGIJTtFiyJrg2EKGfoK5uyJ9 g==; X-CSE-ConnectionGUID: VmDIYkm1Sim96wwJDukcDw== X-CSE-MsgGUID: KyNqWnMeQCKQbd7HGHcHYw== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051900" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051900" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:16 -0800 X-CSE-ConnectionGUID: LK5OceK0SFO1rOK39TwQLQ== X-CSE-MsgGUID: UEHLRbkPRkOOOEw+/P7YXg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611081" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:15 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 1/8] x86/cpufeatures: Enumerate the LASS feature bits Date: Thu, 13 Nov 2025 14:41:57 -0800 Message-ID: <20251113224204.50391-2-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Linear Address Space Separation (LASS) is a security feature that mitigates a class of side-channel attacks relying on speculative access across the user/kernel boundary. Privilege mode based access protection already exists today with paging and features such as SMEP and SMAP. However, to enforce these protections, the processor must traverse the paging structures in memory. An attacker can use timing information resulting from this traversal to determine details about the paging structures, and to determine the layout of the kernel memory. LASS provides the same mode-based protections as paging but without traversing the paging structures. Because the protections are enforced prior to page-walks, an attacker will not be able to derive paging-based timing information from the various caching structures such as the TLBs, mid-level caches, page walker, data caches, etc. LASS enforcement relies on the kernel implementation to divide the 64-bit virtual address space into two halves: Addr[63]=3D0 -> User address space Addr[63]=3D1 -> Kernel address space Any data access or code execution across address spaces typically results in a #GP fault, with an #SS generated in some rare cases. The LASS enforcement for kernel data accesses is dependent on CR4.SMAP being set. The enforcement can be disabled by toggling the RFLAGS.AC bit similar to SMAP. Define the CPU feature bits to enumerate LASS. Also, disable the feature at compile time on 32-bit kernels. Use a direct dependency on X86_32 (instead of !X86_64) to make it easier to combine with similar 32-bit specific dependencies in the future. LASS mitigates a class of side-channel speculative attacks, such as Spectre LAM, described in the paper, "Leaky Address Masking: Exploiting Unmasked Spectre Gadgets with Noncanonical Address Translation". Add the "lass" flag to /proc/cpuinfo to indicate that the feature is supported by hardware and enabled by the kernel. This allows userspace to determine if the system is secure against such attacks. Signed-off-by: Sohil Mehta Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Xin Li (Intel) Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - Split the SMAP dependency hunk into a separate patch (patch 2). - Improve commit message. --- arch/x86/Kconfig.cpufeatures | 4 ++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/uapi/asm/processor-flags.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/arch/x86/Kconfig.cpufeatures b/arch/x86/Kconfig.cpufeatures index 250c10627ab3..733d5aff2456 100644 --- a/arch/x86/Kconfig.cpufeatures +++ b/arch/x86/Kconfig.cpufeatures @@ -124,6 +124,10 @@ config X86_DISABLED_FEATURE_PCID def_bool y depends on !X86_64 =20 +config X86_DISABLED_FEATURE_LASS + def_bool y + depends on X86_32 + config X86_DISABLED_FEATURE_PKU def_bool y depends on !X86_INTEL_MEMORY_PROTECTION_KEYS diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpuf= eatures.h index 4091a776e37a..8d872eb08c16 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -314,6 +314,7 @@ #define X86_FEATURE_SM4 (12*32+ 2) /* SM4 instructions */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* "avx_vnni" AVX VNNI instructio= ns */ #define X86_FEATURE_AVX512_BF16 (12*32+ 5) /* "avx512_bf16" AVX512 BFLOAT= 16 instructions */ +#define X86_FEATURE_LASS (12*32+ 6) /* "lass" Linear Address Space Separa= tion */ #define X86_FEATURE_CMPCCXADD (12*32+ 7) /* CMPccXADD instructio= ns */ #define X86_FEATURE_ARCH_PERFMON_EXT (12*32+ 8) /* Intel Architectural Per= fMon Extension */ #define X86_FEATURE_FZRM (12*32+10) /* Fast zero-length REP MOVSB */ diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include= /uapi/asm/processor-flags.h index f1a4adc78272..81d0c8bf1137 100644 --- a/arch/x86/include/uapi/asm/processor-flags.h +++ b/arch/x86/include/uapi/asm/processor-flags.h @@ -136,6 +136,8 @@ #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) #define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement Technology = */ #define X86_CR4_CET _BITUL(X86_CR4_CET_BIT) +#define X86_CR4_LASS_BIT 27 /* enable Linear Address Space Separation supp= ort */ +#define X86_CR4_LASS _BITUL(X86_CR4_LASS_BIT) #define X86_CR4_LAM_SUP_BIT 28 /* LAM for supervisor pointers */ #define X86_CR4_LAM_SUP _BITUL(X86_CR4_LAM_SUP_BIT) =20 --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D08E326956; Thu, 13 Nov 2025 22:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073921; cv=none; b=jAaVuy6MGLlVGUA3AErmhpeJeFW1Lxtbmc+twAAqwp9LX1TP+MfVjrTqSUNpU4oYQ0btJMndJBrlVIXT3MHQMxZogU6chIPyXbTGeKqLQUYhd26HNbVHCkljkaGbsNBDUF7LZ6KsGSY0+qkivo22uqcVBgAAz5vCVrxzvwbnP7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073921; c=relaxed/simple; bh=m0p/Fqdj/eRp0iccSvGc99dMObdenY1CDe3HNWqJxKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MhFOQ2PXYEHFOyGhW8PXRuO/eG814ugcmXD5+/21eZZlTrqs85+p3GowSKPUYB3COOm6fhAI5htOasNWgVSuJKlY4SkIq8TduvnM28NboBrZ6s8ZGBlx7Xhxuwp+bbj4PeARHckaU5Fs/mqojEPfhrG09HgAjQp8QkvZL00JINc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KQvZAs4e; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KQvZAs4e" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073919; x=1794609919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m0p/Fqdj/eRp0iccSvGc99dMObdenY1CDe3HNWqJxKw=; b=KQvZAs4ePgBOD7OvOMAMk4Nvx9IMDmRI/+BTjSWCepK+xEmGM94q8aOd Jo6ewY0JwPjEs+3zEOGsD7fj89usrtWlxfOzOH6BZVpQ1SRlXNwwxo9lP MhGD2gVmo96XGvTPJD6H/bm5RK5Dm31Kr0Dps5ROsM13t6wHRKceZaA6O 21r2EH45Qo4vpUNoBIIFLcm9zMaBL+Ar+2aHZVKIOPEiZoViPgoD1i2wS SqDpPyxNLeU+wPtEMGrsuE5wnXbHE/ezG5ZwIx2E5Cc8yJwdk6dIOULSs k1CMBx1bXfijZIesuZcN+xdpyVkYkeVR6JQKlQbKEc22ebWuV6Dlv4ooL w==; X-CSE-ConnectionGUID: 2vR9V+1jSXWpa4o0dzFV6w== X-CSE-MsgGUID: J2S5yswzQZO8RNa0t2mwEw== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051912" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051912" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:16 -0800 X-CSE-ConnectionGUID: zRFYNAJISp6EPC71UBuD5A== X-CSE-MsgGUID: eR1d7Rp+S4ChXh+J3vWwWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611084" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:16 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 2/8] x86/cpu: Add an LASS dependency on SMAP Date: Thu, 13 Nov 2025 14:41:58 -0800 Message-ID: <20251113224204.50391-3-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With LASS enabled, any kernel data access to userspace typically results in a #GP, or a #SS in some stack-related cases. When the kernel needs to access user memory, it can suspend LASS enforcement by toggling the RFLAGS.AC bit. Most of these cases are already covered by the stac()/clac() pairs used to avoid SMAP violations. Even though LASS could potentially be enabled independently, it would be very painful without SMAP and the related stac()/clac() calls. There is no reason to support such a configuration because all future hardware with LASS is expected to have SMAP as well. Also, the STAC/CLAC instructions are architected to: #UD - If CPUID.(EAX=3D07H, ECX=3D0H):EBX.SMAP[bit 20] =3D 0. So, make LASS depend on SMAP to conveniently reuse the existing AC bit toggling already in place. Note: Additional STAC/CLAC would still be needed for accesses such as text poking which are not flagged by SMAP. This is because such mappings are in the lower half but do not have the _PAGE_USER bit set which SMAP uses for enforcement. Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - New patch (split from patch 1). --- arch/x86/kernel/cpu/cpuid-deps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-d= eps.c index 46efcbd6afa4..98d0cdd82574 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -89,6 +89,7 @@ static const struct cpuid_dep cpuid_deps[] =3D { { X86_FEATURE_SHSTK, X86_FEATURE_XSAVES }, { X86_FEATURE_FRED, X86_FEATURE_LKGS }, { X86_FEATURE_SPEC_CTRL_SSBD, X86_FEATURE_SPEC_CTRL }, + { X86_FEATURE_LASS, X86_FEATURE_SMAP }, {} }; =20 --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3B03326D4C; Thu, 13 Nov 2025 22:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073921; cv=none; b=cQojEki7e6PwGUxypPW4WpPAF3tuFHok19d6+KCvyJfgE6lyc/LxcQsiEftJpaQze0r60GTGM7aoI/nVlfNNPj+TK3HAteCfgL1FIV+38NfT2bPT+qgjsBzxesqsll/G3h5R7erogNRPkCAf3g/0pFysjLF7YPLkFGIzqddrmN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073921; c=relaxed/simple; bh=3v51fqgW7yBK6B/AFGSul1SUT9hseHQhv6m1LfAlgx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nT7SU9OC9lUxkDUJSbulWd/R/Ys0Y0wILDaz/ISPafIixtn8pGrSCp23+XbiKbTu+HbaDGzJomt3yapeY8puW4/l5LyGzWyj5xwRDCLtZSQGk5T95hwD8Zf0li1AGMktnZj0zgfcPYLVN8PjJOk1iHQZpFhnMv9SQufmWBaH7EA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OsKmTkPX; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OsKmTkPX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073920; x=1794609920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3v51fqgW7yBK6B/AFGSul1SUT9hseHQhv6m1LfAlgx4=; b=OsKmTkPXvi5fpHtaT8/TX1YYQivCSllHM/X1jWYi38BDAN+pT/1XT7NP h2q1kaPTBGREyFY26lOFmQ0TD9XNPJq9lwCWXIJ2KwvMXXCe9eDGiUgqY k7eONZxQkC+jffqgYwtfm5FCswjQJ7PCsjdOx962dAXPbchJbqBU3swlF Rldh8ZBrNwqGIx/AVyYKHIwE+WhIzZpq/tTlbQM3lDr4V0NM3tb0/dauK YdP+K3BOZAH4xk5iYb0Vi9WrofD+iivkX18mGoI7D/usNBM6CsRWFAURk OGBx0Y0jPh0IiWsmsHKecl342V0DdkPFd0K/9s+a5Alkl5X1vf8cGEv6s A==; X-CSE-ConnectionGUID: A/RvpQKVQgS2ky2XZ1A3Bw== X-CSE-MsgGUID: QWsIBu1uQUyDqreM17eXkg== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051927" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051927" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:17 -0800 X-CSE-ConnectionGUID: Nm/O97BUTSuR0PH3F97WlQ== X-CSE-MsgGUID: 8a00V92+Q4GVpFzlhcdWJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611088" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:16 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 3/8] x86/asm: Introduce inline memcpy and memset Date: Thu, 13 Nov 2025 14:41:59 -0800 Message-ID: <20251113224204.50391-4-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Peter Zijlstra (Intel)" Provide inline memcpy and memset functions that can be used instead of the GCC builtins when necessary. The immediate use case is for the text poking functions to avoid the standard memcpy()/memset() calls because objtool complains about such dynamic calls within an AC=3D1 region. See tools/objtool/Documentation/objtool.txt, warning #9, regarding function calls with UACCESS enabled. Some user copy functions such as copy_user_generic() and __clear_user() have similar rep_{movs,stos} usages. But, those are highly specialized and hard to combine or reuse for other things. Define these new helpers for all other usages that need a completely unoptimized, strictly inline version of memcpy() or memset(). Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - Improve commit log. --- arch/x86/include/asm/string.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index c3c2c1914d65..9cb5aae7fba9 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -1,6 +1,32 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_STRING_H +#define _ASM_X86_STRING_H + #ifdef CONFIG_X86_32 # include #else # include #endif + +static __always_inline void *__inline_memcpy(void *to, const void *from, s= ize_t len) +{ + void *ret =3D to; + + asm volatile("rep movsb" + : "+D" (to), "+S" (from), "+c" (len) + : : "memory"); + return ret; +} + +static __always_inline void *__inline_memset(void *s, int v, size_t n) +{ + void *ret =3D s; + + asm volatile("rep stosb" + : "+D" (s), "+c" (n) + : "a" ((uint8_t)v) + : "memory"); + return ret; +} + +#endif /* _ASM_X86_STRING_H */ --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71A33326D6E; Thu, 13 Nov 2025 22:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073922; cv=none; b=JUC6C670oUYSn9OIZHn0Z5iT2m1yLB1/eCTZDASNpaU8o5Hbw9DQIpz1I24Uq0RACUzEvH9kIeNsNL8CfBnAb9rDT2glpV9Z6JQTStffgLUU/PtFh9mdvV0UBWbZBpvQV3gaRejod0Sk5VeFWpGnn0WG64OnCZV0LC6nlBnu+Yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073922; c=relaxed/simple; bh=gvbT3BHteEQ6s+AC0t6voXLmJ8qwMJg0xNxsHAAJFeg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VzD5gJjFL1wPOCgHZ6tmSKdo27F0drDTNLgho+01v1gXGDX0UdN3p+pkbqtWU1mB+VqSFSfDD0GP0skC3Wrb5RSle4WMAd3AacX8Gq/xU6hbqfFL3snFUkZNzfEUx7ZpmKE6HH1FA8lq0tK276dcY2cL2Jd/toM59Z0WAt+sUOE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QzT6ehgS; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QzT6ehgS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073920; x=1794609920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gvbT3BHteEQ6s+AC0t6voXLmJ8qwMJg0xNxsHAAJFeg=; b=QzT6ehgSHgtcJJXnc5z991kVckhPophCvzSmbGBkEUbRRHZaPR2JXwot CvibLNy00iL7JUA2qHPpu4HSsW/fDB2wqg0f8makyszRICIryaHr6nvyQ AaOgGzgn5LWO3XCigP/pv7CAfxmEmPyX79rZoHR9DZR/pvVWm9g7pNFn8 CMZCDb5VbrTSbxdKohp8Qz3ujhZlt3SLFyZI0bePz3c0aeyiaw6DtOASl +u7KXmVKOjaqNB3l3rP7Fs9mTwlAdfYuJb0eYEVmq7fCKL7k9ztIAg3id 04kNXD//byrTyTAY5AE2R+zUVRl+BrAVWMmOmNX5SvzyiCxv8f/Lj6dG4 w==; X-CSE-ConnectionGUID: Go3znnJRRQq6CmPcLu5zGw== X-CSE-MsgGUID: Q5L4xATFRGWp70PIiGLTfw== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051941" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051941" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:17 -0800 X-CSE-ConnectionGUID: pZQDxvYSSiKFC5rfihB15Q== X-CSE-MsgGUID: fITss5VlQ8KQ5Du+cgXcEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611092" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:17 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 4/8] x86/alternatives: Disable LASS when patching kernel code Date: Thu, 13 Nov 2025 14:42:00 -0800 Message-ID: <20251113224204.50391-5-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For patching, the kernel initializes a temporary mm area in the lower half of the address range. LASS blocks these accesses because its enforcement relies on bit 63 of the virtual address as opposed to SMAP which depends on the _PAGE_BIT_USER bit in the page table. Disable LASS enforcement by toggling the RFLAGS.AC bit during patching to avoid triggering a #GP fault. Introduce LASS-specific STAC/CLAC helpers to set the AC bit only on platforms that need it. Name the wrappers as lass_stac()/_clac() instead of lass_disable()/_enable() because they only control the kernel data access enforcement. The entire LASS mechanism (including instruction fetch enforcement) is controlled by the CR4.LASS bit. Describe the usage of the new helpers in comparison to the ones used for SMAP. Also, add comments to explain when the existing stac()/clac() should be used. While at it, move the duplicated "barrier" comment to the same block. The Text poking functions use standard memcpy()/memset() while patching kernel code. However, objtool complains about calling such dynamic functions within an AC=3D1 region. See warning #9, regarding function calls with UACCESS enabled, in tools/objtool/Documentation/objtool.txt. To pacify objtool, one option is to add memcpy() and memset() to the list of allowed-functions. However, that would provide a blanket exemption for all usages of memcpy() and memset(). Instead, replace the standard calls in the text poking functions with their unoptimized, always-inlined versions. Considering that patching is usually small, there is no performance impact expected. Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Revert to lass_clac()/lass_stac() naming. - Pick up review tag. v11: - Use lass_enable()/lass_disable() naming. - Improve commit log and code comments. --- arch/x86/include/asm/smap.h | 41 +++++++++++++++++++++++++++++++++-- arch/x86/kernel/alternative.c | 18 +++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h index 4f84d421d1cf..20a3baae9568 100644 --- a/arch/x86/include/asm/smap.h +++ b/arch/x86/include/asm/smap.h @@ -23,18 +23,55 @@ =20 #else /* __ASSEMBLER__ */ =20 +/* + * The CLAC/STAC instructions toggle the enforcement of + * X86_FEATURE_SMAP along with X86_FEATURE_LASS. + * + * SMAP enforcement is based on the _PAGE_BIT_USER bit in the page + * tables. The kernel is not allowed to touch pages with that bit set + * unless the AC bit is set. + * + * Use stac()/clac() when accessing userspace (_PAGE_USER) mappings, + * regardless of location. + * + * Note: a barrier is implicit in alternative(). + */ + static __always_inline void clac(void) { - /* Note: a barrier is implicit in alternative() */ alternative("", "clac", X86_FEATURE_SMAP); } =20 static __always_inline void stac(void) { - /* Note: a barrier is implicit in alternative() */ alternative("", "stac", X86_FEATURE_SMAP); } =20 +/* + * LASS enforcement is based on bit 63 of the virtual address. The + * kernel is not allowed to touch memory in the lower half of the + * virtual address space. + * + * Use lass_stac()/lass_clac() to toggle the AC bit for kernel data + * accesses (!_PAGE_USER) that are blocked by LASS, but not by SMAP. + * + * Even with the AC bit set, LASS will continue to block instruction + * fetches from the user half of the address space. To allow those, + * clear CR4.LASS to disable the LASS mechanism entirely. + * + * Note: a barrier is implicit in alternative(). + */ + +static __always_inline void lass_clac(void) +{ + alternative("", "clac", X86_FEATURE_LASS); +} + +static __always_inline void lass_stac(void) +{ + alternative("", "stac", X86_FEATURE_LASS); +} + static __always_inline unsigned long smap_save(void) { unsigned long flags; diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 8ee5ff547357..5b09f89070f0 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2469,16 +2469,30 @@ void __init_or_module text_poke_early(void *addr, c= onst void *opcode, __ro_after_init struct mm_struct *text_poke_mm; __ro_after_init unsigned long text_poke_mm_addr; =20 +/* + * Text poking creates and uses a mapping in the lower half of the + * address space. Relax LASS enforcement when accessing the poking + * address. + * + * objtool enforces a strict policy of "no function calls within AC=3D1 + * regions". Adhere to the policy by using inline versions of + * memcpy()/memset() that will never result in a function call. + */ + static void text_poke_memcpy(void *dst, const void *src, size_t len) { - memcpy(dst, src, len); + lass_stac(); + __inline_memcpy(dst, src, len); + lass_clac(); } =20 static void text_poke_memset(void *dst, const void *src, size_t len) { int c =3D *(const int *)src; =20 - memset(dst, c, len); + lass_stac(); + __inline_memset(dst, c, len); + lass_clac(); } =20 typedef void text_poke_f(void *dst, const void *src, size_t len); --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 510283271E6; Thu, 13 Nov 2025 22:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073923; cv=none; b=HH0JUcckxwItoIw0dVF+2RAf2aVy9MMZ2OhQjrs7wQd+Foqeh7Sg83Il+Qev/HLpUCqsBnP1l59aNODuqd+uIeiM2Ywr6c5cU/A5+DrkRXGC6SSuCGWjVa6HpIl1eWxuPGhhG1bk/+3WEnhfgdhw4XbYA9xlZTQLDOmdJBU/xfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073923; c=relaxed/simple; bh=8d3y0tuH+JUD4QfSiQiDm9n5LoaQCNgr1flLLNl4hIs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d3OvCEygsdgVMnBy6q0o+IVKwXjXRkBy12JL+HYstLyCjBq+fgZc/g15bn7JSXjIi0qQW62Wgf5yQfyTAoI40Pu7oNAMkhkMFREo5GyzTpX/LdnJmgfvLpz94ErXZGYBOEUppDV8ww1Ycb/zm4KUVGZz+PCZgfPfDEDXXi2HATU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gG8uvZO4; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gG8uvZO4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073921; x=1794609921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8d3y0tuH+JUD4QfSiQiDm9n5LoaQCNgr1flLLNl4hIs=; b=gG8uvZO4y2mKMn0bx/zyMQt0xrqD9eUKLAWpOoBlWouTL3jUcOl869KH AeafT6BiQqXY5XE0ZOrq3E4fy/5tjIrQbicgc5jLNab7r6TnrkVYVY4dd lVJD5vX2jEBrozFw1F/1wcBSi/C41CawBjKeY/5BUUQccggKnz1oeyMNg iqO5TVyIfFHiMF6gd3R1OFIlncNl3WEEcJPBYMJI4O2oaMDR+LOUeXxoV QibgBqjp8lw4rvpKzIuUNhR8fwfd8cs/uztEA7OK3+xayndxURCzqM2VH 6abc86OJr+nuYTk8IPnzFdhvKF2DansNqsFTAy5luC7VNOjfVJGvqtFzK Q==; X-CSE-ConnectionGUID: NW7lxVjNQRSSaK3Msy5dxw== X-CSE-MsgGUID: RDir1IuQQluj3iePe43Upw== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051955" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051955" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:18 -0800 X-CSE-ConnectionGUID: W9e7q+1JSKeTswLKg78olA== X-CSE-MsgGUID: D/llQ+22SlOQa0E9bRNSQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611095" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:17 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 5/8] x86/kexec: Disable LASS during relocate kernel Date: Thu, 13 Nov 2025 14:42:01 -0800 Message-ID: <20251113224204.50391-6-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The relocate kernel mechanism uses an identity mapping to copy the new kernel, which leads to a LASS violation when executing from a low address. LASS must be disabled after the original CR4 value is saved because kexec paths that preserve context need to restore CR4.LASS. But, disabling it along with CET during identity_mapped() is too late. So, disable LASS immediately after saving CR4, along with PGE, and before jumping to the identity-mapped page. Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - Improve commit message. --- arch/x86/kernel/relocate_kernel_64.S | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocat= e_kernel_64.S index 11e20bb13aca..4ffba68dc57b 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -95,9 +95,12 @@ SYM_CODE_START_NOALIGN(relocate_kernel) /* Leave CR4 in %r13 to enable the right paging mode later. */ movq %cr4, %r13 =20 - /* Disable global pages immediately to ensure this mapping is RWX */ + /* + * Disable global pages immediately to ensure this mapping is RWX. + * Disable LASS before jumping to the identity mapped page. + */ movq %r13, %r12 - andq $~(X86_CR4_PGE), %r12 + andq $~(X86_CR4_PGE | X86_CR4_LASS), %r12 movq %r12, %cr4 =20 /* Save %rsp and CRs. */ --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B65843271E2; Thu, 13 Nov 2025 22:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073923; cv=none; b=qlEXxDv4M0UDjlRirgk1cDHITD87qx3C3/TzWx3a/4Ih8/FC73bCk7B/L5Fxp3bgVEvDIWt/k+5UhkTkO0+O9XownGToPzf/bzfazrjbYUz5t9F8ZGumcdlTOzfoK+AYXbGowMB0cFx1zbvfTclNSqp9b2PnOdvob1HeADuQPZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073923; c=relaxed/simple; bh=FMmtFZ5dyAmInWmEgEfrEufXRj0thkkit9CXc/uLAnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DXEgeQ46uXx1vyRZ5TJnRE3e2PElaF+6eScrX4qRjpBLMiT8laL0xk17a8uKkGfOGwol1kA0xWh9oYPXU+V9UKefIdZ2BhkLPqLMW3DJBap7jS8I1Joj41HStGN8k8zpn28ibhwwGbYghkw8y9ObJctyzSe5WMJJx6o7Rmrq8MU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bhhnJUm8; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bhhnJUm8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073922; x=1794609922; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FMmtFZ5dyAmInWmEgEfrEufXRj0thkkit9CXc/uLAnA=; b=bhhnJUm8kD4vUQMfmZS4YAjiKv3OuFqHJzdCsg+4mKBjuZyYZSJk8IEv 66hTW4/bjx0UrCJRlcKHTBN+dkwEcqYkHRXKt9WsphCYI8CjT7zlsamIv X/qjrB/SJb/kWN4ciBjnlsH19KtyLgW/iY8swLYW4DBHiKNsyyTzwuA6d SqSGXaSotE8ygIceE4c4fJrx47qM9bEEWAtKaTNDkOBpHBpP50Vm+FvRV Y5B7l6+G1d4E8eIDqvSdZgqVGZu9EA1bhk26uFPhE5Oni91dinI1AcCRc dd9hzIM6XKZY93wraNt88eiIRuM010/X+S5UKTlMyz2Jb28oMUl96zafc w==; X-CSE-ConnectionGUID: rAQ4huBMSHSSxPMZVOtnTw== X-CSE-MsgGUID: wHdQHLsNRy+YGNptdbBm6g== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051966" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051966" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:18 -0800 X-CSE-ConnectionGUID: EfkjGwVWRomRvrVTPZc1Uw== X-CSE-MsgGUID: faF83c4sTb6SsH5bYPq0Gw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611102" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:17 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 6/8] x86/traps: Communicate a LASS violation in #GP message Date: Thu, 13 Nov 2025 14:42:02 -0800 Message-ID: <20251113224204.50391-7-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexander Shishkin A LASS violation typically results in a #GP. With LASS active, any invalid access to user memory (including the first page frame) would be reported as a #GP, instead of a #PF. Unfortunately, the #GP error messages provide limited information about the cause of the fault. This could be confusing for kernel developers and users who are accustomed to the friendly #PF messages. To make the transition easier, enhance the #GP Oops message to include a hint about LASS violations. Also, add a special hint for kernel NULL pointer dereferences to match with the existing #PF message. Signed-off-by: Alexander Shishkin Signed-off-by: Kirill A. Shutemov Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - Improve commit log. --- arch/x86/kernel/traps.c | 45 ++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 6b22611e69cc..30d5c690f9a1 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -635,13 +635,23 @@ DEFINE_IDTENTRY(exc_bounds) enum kernel_gp_hint { GP_NO_HINT, GP_NON_CANONICAL, - GP_CANONICAL + GP_CANONICAL, + GP_LASS_VIOLATION, + GP_NULL_POINTER, +}; + +static const char * const kernel_gp_hint_help[] =3D { + [GP_NON_CANONICAL] =3D "probably for non-canonical address", + [GP_CANONICAL] =3D "maybe for address", + [GP_LASS_VIOLATION] =3D "probably LASS violation for address", + [GP_NULL_POINTER] =3D "kernel NULL pointer dereference", }; =20 /* * When an uncaught #GP occurs, try to determine the memory address access= ed by * the instruction and return that address to the caller. Also, try to fig= ure - * out whether any part of the access to that address was non-canonical. + * out whether any part of the access to that address was non-canonical or + * across privilege levels. */ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs, unsigned long *addr) @@ -663,14 +673,27 @@ static enum kernel_gp_hint get_kernel_gp_address(stru= ct pt_regs *regs, return GP_NO_HINT; =20 #ifdef CONFIG_X86_64 - /* - * Check that: - * - the operand is not in the kernel half - * - the last byte of the operand is not in the user canonical half - */ - if (*addr < ~__VIRTUAL_MASK && - *addr + insn.opnd_bytes - 1 > __VIRTUAL_MASK) + /* Operand is in the kernel half */ + if (*addr >=3D ~__VIRTUAL_MASK) + return GP_CANONICAL; + + /* The last byte of the operand is not in the user canonical half */ + if (*addr + insn.opnd_bytes - 1 > __VIRTUAL_MASK) return GP_NON_CANONICAL; + + /* + * If LASS is active, a NULL pointer dereference generates a #GP + * instead of a #PF. + */ + if (*addr < PAGE_SIZE) + return GP_NULL_POINTER; + + /* + * Assume that LASS caused the exception, because the address is + * canonical and in the user half. + */ + if (cpu_feature_enabled(X86_FEATURE_LASS)) + return GP_LASS_VIOLATION; #endif =20 return GP_CANONICAL; @@ -833,9 +856,7 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) =20 if (hint !=3D GP_NO_HINT) snprintf(desc, sizeof(desc), GPFSTR ", %s 0x%lx", - (hint =3D=3D GP_NON_CANONICAL) ? "probably for non-canonical address" - : "maybe for address", - gp_addr); + kernel_gp_hint_help[hint], gp_addr); =20 /* * KASAN is interested only in the non-canonical case, clear it --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A5732826F; Thu, 13 Nov 2025 22:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073924; cv=none; b=aE0HhRori/B6RJn1tZ5delHa0t9PENJ4EjH/zZX16RVpL6sMFBx4fiyaVZdKVtGsNUYLPBhDCk75IIFXgLk76FKn5FIoNUdn0vwoUeCFZPoTdBb87a7nZetejqqnEYZU97VInttljnVDDBXZ/yoVq0AEuv14fPQiWomL1Y9Kxyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073924; c=relaxed/simple; bh=Of1UkDgA+A8BDxzkeo8tPZu02XdKsJjP//uVe66ASjQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ItVrn4E7ETc9P3G9AuNMRBmX79vYZqHx6KdeLpHrN1gEvzBAn39A+EUpst3wkWlYzV2iznboYNEJT9g62hGKPqVS5VfiKnrWlgiU4qmE9OFJs4O0pMIo5foXXtj1AryRTu3JHEtxWGa4+xz/MkPaQF0Oym2mbNvAzPlXkLcETYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FdOleITJ; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FdOleITJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073923; x=1794609923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Of1UkDgA+A8BDxzkeo8tPZu02XdKsJjP//uVe66ASjQ=; b=FdOleITJIndbYKMCpO11kKi0fhmkG7vF9nEou8MZJO/ty7tH5xBryqLQ X/BfW0FLlCPsGZ8OE4HupyPIUtUpU3Oe6MyZxrwDibuAzfsFEflqTjrSM ZtHXjFdQecylro/x+/pQDzpcWYkG4P90P5ly8BM50tlcASf686Wc05zrV j5iPVqsEOoB7oDvT06Wx/cIXlAzM2uussjiv407KU44tHst8syLIVhveL T4V+ffjpxQpId584AOgpvoW/duGSa9T2jif9LPXmcNWSmSuOZejJ24MTQ uiFmEIRBxFwrfWNGko80zlV/3a5yZ0owsrH5WfdfWPKXU3Tioi0bfsrME A==; X-CSE-ConnectionGUID: 0SMk1iW4TdCGTSJDd7ac9A== X-CSE-MsgGUID: FBQAl6mOTt+BtxY2bgGESA== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051981" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051981" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:19 -0800 X-CSE-ConnectionGUID: VHbPE4F8T+mG96PnYUqm6A== X-CSE-MsgGUID: s0Es68gKQpKnvRfIz/cSPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611105" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:18 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 7/8] selftests/x86: Update the negative vsyscall tests to expect a #GP Date: Thu, 13 Nov 2025 14:42:03 -0800 Message-ID: <20251113224204.50391-8-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some of the vsyscall selftests expect a #PF when vsyscalls are disabled. However, with LASS enabled, an invalid access results in a SIGSEGV due to a #GP instead of a #PF. One such negative test fails because it is expecting X86_PF_INSTR to be set. Update the failing test to expect either a #GP or a #PF. Also, update the printed messages to show the trap number (denoting the type of fault) instead of assuming a #PF. Signed-off-by: Sohil Mehta Reviewed-by: Dave Hansen --- v12: - Pick up review tag. v11: - New patch (Fixes a vsyscall selftest failure) --- tools/testing/selftests/x86/test_vsyscall.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/se= lftests/x86/test_vsyscall.c index 05e1e6774fba..918eaec8bfbe 100644 --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c @@ -308,12 +308,13 @@ static void test_getcpu(int cpu) #ifdef __x86_64__ =20 static jmp_buf jmpbuf; -static volatile unsigned long segv_err; +static volatile unsigned long segv_err, segv_trapno; =20 static void sigsegv(int sig, siginfo_t *info, void *ctx_void) { ucontext_t *ctx =3D (ucontext_t *)ctx_void; =20 + segv_trapno =3D ctx->uc_mcontext.gregs[REG_TRAPNO]; segv_err =3D ctx->uc_mcontext.gregs[REG_ERR]; siglongjmp(jmpbuf, 1); } @@ -336,7 +337,8 @@ static void test_vsys_r(void) else if (can_read) ksft_test_result_pass("We have read access\n"); else - ksft_test_result_pass("We do not have read access: #PF(0x%lx)\n", segv_e= rr); + ksft_test_result_pass("We do not have read access (trap=3D%ld, error=3D0= x%lx)\n", + segv_trapno, segv_err); } =20 static void test_vsys_x(void) @@ -347,7 +349,7 @@ static void test_vsys_x(void) return; } =20 - ksft_print_msg("Make sure that vsyscalls really page fault\n"); + ksft_print_msg("Make sure that vsyscalls really cause a fault\n"); =20 bool can_exec; if (sigsetjmp(jmpbuf, 1) =3D=3D 0) { @@ -358,13 +360,14 @@ static void test_vsys_x(void) } =20 if (can_exec) - ksft_test_result_fail("Executing the vsyscall did not page fault\n"); - else if (segv_err & (1 << 4)) /* INSTR */ - ksft_test_result_pass("Executing the vsyscall page failed: #PF(0x%lx)\n", - segv_err); + ksft_test_result_fail("Executing the vsyscall did not fault\n"); + /* #GP or #PF (with X86_PF_INSTR) */ + else if ((segv_trapno =3D=3D 13) || ((segv_trapno =3D=3D 14) && (segv_err= & (1 << 4)))) + ksft_test_result_pass("Executing the vsyscall page failed (trap=3D%ld, e= rror=3D0x%lx)\n", + segv_trapno, segv_err); else - ksft_test_result_fail("Execution failed with the wrong error: #PF(0x%lx)= \n", - segv_err); + ksft_test_result_fail("Execution failed with the wrong error (trap=3D%ld= , error=3D0x%lx)\n", + segv_trapno, segv_err); } =20 /* --=20 2.43.0 From nobody Sun Feb 8 05:35:28 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4517832825A; Thu, 13 Nov 2025 22:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073925; cv=none; b=tSh1Wv4I6uIskZawDH7G6MOOr1/HSSUIMXLpucJy5mHn+PIdW1olLjpLedwCzVeCXnAd4o74US9kPXHpOWv0yGEnYuJY2n9f6C5TUGdeaNG1ozsMTin9Wnft6+hZbigwYyXjcTLuihW/XhA76ilv/aVNOSOkRo7tadQ2lXFxMlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763073925; c=relaxed/simple; bh=kBdXhc+A+wT4FZp9yNpWWziklK2/ynCoRGDow6mU3dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lzyinBkG2pvk4w7REoXyBuo8SvoKO6tW9NFZxvnHgGL/R2gtGskwCNOdivZMpubS8wqlkmxyi7DigjVdFjmafAd0cHpXwLcAUy5AJTKgq2JgH+/DQjleR58O9oCg1thk4rshU17vIfB4wzC2PjyN4Ws13Fdm0/jW/m9oFGY3JQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=U5o2GcYR; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="U5o2GcYR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763073923; x=1794609923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kBdXhc+A+wT4FZp9yNpWWziklK2/ynCoRGDow6mU3dw=; b=U5o2GcYRZj4WbcWzFacejASsuxPhAAKhphsUTDXMdrCRQRp3xmVHrmQy vGQgnt3PxziiO7I9mHSZu4Zyvh74xXLz1/npGQoka/rn3IK2PqttWNP59 csPnmtzrj8B6/RlwnFUiQNxNeVu2t1wXhY//YFXKDxua0iqwBOWyIgxau hGHyvlqK4tdF2qMtgOiXxEqLgNyG5PStpbia5UPgwPjDC6IOqWvs3oOrl zAwQnB8RaV9xLnDQN7FIdimGQXTJbB7nPqe1Fr93W1fLbeZylqA9Jx5my GBpncO5dv9nDYEtUCcNP5dSI3QoY0USeH78VVUuR6av+yyQNmoxuMQEj0 w==; X-CSE-ConnectionGUID: vv7chruJSemBiQFkk20WtQ== X-CSE-MsgGUID: FhtaYQvORNqugYCwHgiAnA== X-IronPort-AV: E=McAfee;i="6800,10657,11612"; a="65051994" X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="65051994" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2025 14:45:19 -0800 X-CSE-ConnectionGUID: 4JKiUxG/Rf+LCTLpacaxMg== X-CSE-MsgGUID: LbL2JpExQFSwUZ6RY5ku3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,303,1754982000"; d="scan'208";a="194611110" Received: from sohilmeh.sc.intel.com ([172.25.103.65]) by fmviesa004.fm.intel.com with ESMTP; 13 Nov 2025 14:45:19 -0800 From: Sohil Mehta To: x86@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Jonathan Corbet , "H . Peter Anvin" , Andy Lutomirski , Josh Poimboeuf , Peter Zijlstra , Ard Biesheuvel , "Kirill A . Shutemov" , Sohil Mehta , Xin Li , David Woodhouse , Sean Christopherson , Rick Edgecombe , Vegard Nossum , Andrew Cooper , Randy Dunlap , Geert Uytterhoeven , Kees Cook , Tony Luck , Alexander Shishkin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v12 8/8] x86/cpu: Enable LASS during CPU initialization Date: Thu, 13 Nov 2025 14:42:04 -0800 Message-ID: <20251113224204.50391-9-sohil.mehta@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251113224204.50391-1-sohil.mehta@intel.com> References: <20251113224204.50391-1-sohil.mehta@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Dave Hansen --- For reference, here are the relevant discussion links regarding EFI and legacy vsyscalls: https://lore.kernel.org/lkml/CAMj1kXGyTo=3D4Va1PevMQyCauEKSutfSPo6je0Ps09Ta= bhTe4zQ@mail.gmail.com/ https://lore.kernel.org/lkml/bbb68600-eea9-45d8-90d1-bc4619186a4d@intel.com/ https://lore.kernel.org/lkml/CAMj1kXFQaGaz37MNKXXjhUKy_mP-5teCDj80-hjUPHw4x= +TKrA@mail.gmail.com/ https://lore.kernel.org/lkml/d1b5698e-94ab-45a2-a472-4488895d55bb@intel.com/ v12: - Disable LASS when EFI support is compiled in. - Pick up review tag. v11: - Disable LASS if vsyscall emulation support is compiled in. - Drop Rick's review tag because of the new changes. --- arch/x86/kernel/cpu/common.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 02d97834a1d4..8afcbfd48a8a 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -405,6 +405,28 @@ static __always_inline void setup_umip(struct cpuinfo_= x86 *c) cr4_clear_bits(X86_CR4_UMIP); } =20 +static __always_inline void setup_lass(struct cpuinfo_x86 *c) +{ + if (!cpu_feature_enabled(X86_FEATURE_LASS)) + return; + + /* + * Legacy vsyscall page access causes a #GP when LASS is active. + * Disable LASS because the #GP handler doesn't support vsyscall + * emulation. + * + * Also disable LASS when running under EFI, as some runtime and + * boot services rely on 1:1 mappings in the lower half. + */ + if (IS_ENABLED(CONFIG_X86_VSYSCALL_EMULATION) || + IS_ENABLED(CONFIG_EFI)) { + setup_clear_cpu_cap(X86_FEATURE_LASS); + return; + } + + cr4_set_bits(X86_CR4_LASS); +} + /* These bits should not change their value after CPU init is finished. */ static const unsigned long cr4_pinned_mask =3D X86_CR4_SMEP | X86_CR4_SMAP= | X86_CR4_UMIP | X86_CR4_FSGSBASE | X86_CR4_CET | X86_CR4_FRED; @@ -2015,10 +2037,10 @@ static void identify_cpu(struct cpuinfo_x86 *c) /* Disable the PN if appropriate */ squash_the_stupid_serial_number(c); =20 - /* Set up SMEP/SMAP/UMIP */ setup_smep(c); setup_smap(c); setup_umip(c); + setup_lass(c); =20 /* Enable FSGSBASE instructions if available. */ if (cpu_has(c, X86_FEATURE_FSGSBASE)) { --=20 2.43.0