From: Ard Biesheuvel <ardb@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Dave Hansen <dave.hansen@intel.com>,
Sohil Mehta <sohil.mehta@intel.com>,
x86@kernel.org, Borislav Petkov <bp@alien8.de>,
Jonathan Corbet <corbet@lwn.net>,
Andy Lutomirski <luto@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
"Kirill A . Shutemov" <kas@kernel.org>, Xin Li <xin@zytor.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Sean Christopherson <seanjc@google.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Vegard Nossum <vegard.nossum@oracle.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Randy Dunlap <rdunlap@infradead.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Kees Cook <kees@kernel.org>, Tony Luck <tony.luck@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-efi@vger.kernel.org,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH v11 4/9] x86/alternatives: Disable LASS when patching kernel code
Date: Wed, 12 Nov 2025 16:18:33 +0100 [thread overview]
Message-ID: <CAMj1kXGyTo=4Va1PevMQyCauEKSutfSPo6je0Ps09TabhTe4zQ@mail.gmail.com> (raw)
In-Reply-To: <DDEF6164-D1E6-4003-A251-804738CB59E0@zytor.com>
On Wed, 12 Nov 2025 at 15:58, H. Peter Anvin <hpa@zytor.com> wrote:
>
> On November 12, 2025 6:51:45 AM PST, Dave Hansen <dave.hansen@intel.com> wrote:
> >On 11/12/25 05:56, Ard Biesheuvel wrote:
> >...
> >>> it looks like we would now need to toggle
> >>> CR4.LASS every time we switch to efi_mm. The lass_enable()/_disable()
> >>> naming would be more suitable for those wrappers.
> >>>
> >> Note that Linux/x86 uses SetVirtualAddressMap() to remap all EFI
> >> runtime regions into the upper [kernel] half of the address space.
> >>
> >> SetVirtualAddressMap() itself is a terrible idea, but given that we
> >> are already stuck with it, we should be able to rely on ordinary EFI
> >> runtime calls to only execute from the upper address range. The only
> >> exception is the call to SetVirtualAddressMap() itself, which occurs
> >> only once during early boot.
> >
> >Gah, I had it in my head that we needed to use the lower mapping at
> >runtime. The efi_mm gets used for that SetVirtualAddressMap() and the
> >efi_mm continues to get used at runtime. So I think I just assumed that
> >the lower mappings needed to get used too.
> >
> >Thanks for the education!
> >
> >Let's say we simply delayed CR4.LASS=1 until later in boot. Could we
> >completely ignore LASS during EFI calls, since the calls only use the
> >upper address range?
> >
> >Also, in practice, are there buggy EFI implementations that use the
> >lower address range even though they're not supposed to? *If* we just
> >keep LASS on for these calls is there a chance it will cause a
> >regression in some buggy EFI implementations?
>
> Yes, they are. And there are buggy ones which die if set up with virtual addresses in the low half.
To elaborate on that, there are systems where
a) not calling SetVirtualAddressMap() crashes the firmware, because,
in spite of being clearly documented as optional, not calling it
results in some event hook not being called, causing the firmware to
misbehave
b) calling SetVirtualAddressMap() with an 1:1 mapping crashes the
firmware (and so this is not a possible workaround for a))
c) calling SetVirtualAddressMap() crashes the firmware when not both
the old 1:1 and the new kernel mapping are already live (which
violates the UEFI spec)
d) calling SetVirtualAddressMap() does not result in all 1:1
references being converted to the new mapping.
To address d), the x86_64 implementation of efi_map_region() indeed
maps an 1:1 alias of each remapped runtime regions, so that stray
accesses don't fault. But the code addresses are all remapped, and so
the firmware routines are always invoked via their remapped aliases in
the kernel VA space. Not calling SetVirtualAddressMap() at all, or
calling it with a 1:1 mapping is not feasible, essentially because
Windows doesn't do that, and that is the only thing that is tested on
all x86 PCs by the respective OEMs.
Given that remapping the code is dealt with by the firmware's PE/COFF
loader, whereas remapping [dynamically allocated] data requires effort
on the part of the programmer, I'd hazard a guess that 99.9% of those
bugs do not involve attempts to execute via the lower mapping, but
stray references to data objects that were not remapped properly.
So we might consider
a) remapping those 1:1 aliases NX, so we don't have those patches of
RWX memory around
b) keeping LASS enabled during ordinary EFI runtime calls, as you suggest.
next prev parent reply other threads:[~2025-11-12 15:18 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 21:03 [PATCH v11 0/9] x86: Enable Linear Address Space Separation support Sohil Mehta
2025-10-29 21:03 ` [PATCH v11 1/9] x86/cpufeatures: Enumerate the LASS feature bits Sohil Mehta
2025-10-31 17:03 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 2/9] x86/cpu: Add an LASS dependency on SMAP Sohil Mehta
2025-10-31 17:04 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 3/9] x86/asm: Introduce inline memcpy and memset Sohil Mehta
2025-10-31 17:06 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 4/9] x86/alternatives: Disable LASS when patching kernel code Sohil Mehta
2025-10-31 17:10 ` Dave Hansen
2025-11-10 18:15 ` Sohil Mehta
2025-11-10 19:09 ` H. Peter Anvin
2025-11-10 19:24 ` Borislav Petkov
2025-11-12 13:56 ` Ard Biesheuvel
2025-11-12 14:51 ` Dave Hansen
2025-11-12 14:57 ` H. Peter Anvin
2025-11-12 15:18 ` Ard Biesheuvel [this message]
2025-11-12 15:23 ` H. Peter Anvin
2025-11-12 15:28 ` Ard Biesheuvel
2025-11-12 15:47 ` H. Peter Anvin
2025-11-12 16:18 ` Sohil Mehta
2025-11-12 16:26 ` H. Peter Anvin
2025-11-12 16:29 ` H. Peter Anvin
2025-10-29 21:03 ` [PATCH v11 5/9] x86/efi: Disable LASS while mapping the EFI runtime services Sohil Mehta
2025-10-31 17:11 ` Dave Hansen
2025-10-31 17:38 ` Andy Lutomirski
2025-10-31 17:41 ` Dave Hansen
2025-10-31 18:03 ` Sohil Mehta
2025-10-31 18:12 ` Dave Hansen
2025-11-07 9:04 ` Peter Zijlstra
2025-11-07 9:22 ` Ard Biesheuvel
2025-11-07 9:27 ` H. Peter Anvin
2025-11-07 9:35 ` Ard Biesheuvel
2025-11-07 9:40 ` Peter Zijlstra
2025-11-07 10:09 ` Ard Biesheuvel
2025-11-07 10:27 ` Peter Zijlstra
2025-11-08 0:48 ` Andy Lutomirski
2025-11-08 16:18 ` H. Peter Anvin
2025-11-08 22:50 ` H. Peter Anvin
2025-11-07 10:10 ` Peter Zijlstra
2025-11-07 10:17 ` Ard Biesheuvel
2025-10-31 19:04 ` Sohil Mehta
2025-11-07 7:36 ` Sohil Mehta
2025-10-31 18:32 ` Sohil Mehta
2025-10-29 21:03 ` [PATCH v11 6/9] x86/kexec: Disable LASS during relocate kernel Sohil Mehta
2025-10-31 17:14 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 7/9] x86/traps: Communicate a LASS violation in #GP message Sohil Mehta
2025-10-31 17:16 ` Dave Hansen
2025-10-31 19:59 ` Sohil Mehta
2025-10-31 20:03 ` Andy Lutomirski
2025-10-31 20:56 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 8/9] selftests/x86: Update the negative vsyscall tests to expect a #GP Sohil Mehta
2025-10-31 17:20 ` Dave Hansen
2025-10-29 21:03 ` [PATCH v11 9/9] x86/cpu: Enable LASS by default during CPU initialization Sohil Mehta
2025-10-30 8:40 ` H. Peter Anvin
2025-10-30 15:45 ` Andy Lutomirski
2025-10-30 16:44 ` Sohil Mehta
2025-10-30 16:53 ` Andy Lutomirski
2025-10-30 17:24 ` Sohil Mehta
2025-10-30 17:31 ` Andy Lutomirski
2025-10-30 21:13 ` David Laight
2025-10-31 6:41 ` H. Peter Anvin
2025-10-31 16:55 ` Dave Hansen
2025-10-30 16:27 ` Dave Hansen
2025-11-07 8:01 ` H. Peter Anvin
2025-11-07 20:08 ` Sohil Mehta
2025-10-31 17:21 ` Dave Hansen
2025-10-31 20:04 ` Sohil Mehta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMj1kXGyTo=4Va1PevMQyCauEKSutfSPo6je0Ps09TabhTe4zQ@mail.gmail.com' \
--to=ardb@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw@amazon.co.uk \
--cc=geert@linux-m68k.org \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=kas@kernel.org \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=sohil.mehta@intel.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vegard.nossum@oracle.com \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).