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

Re: [PATCH v2 00/11] x86/EFI: prevent write-execute sections


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 1 Apr 2025 15:58:20 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Doug Goldstein <cardoe@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Shawn Anastasio <sanastasio@xxxxxxxxxxxxxxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 01 Apr 2025 13:58:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 01.04.2025 15:26, Roger Pau Monné wrote:
> On Tue, Apr 01, 2025 at 03:13:52PM +0200, Jan Beulich wrote:
>> On 01.04.2025 15:08, Roger Pau Monne wrote:
>>> Hello,
>>>
>>> The following series aim to remove the presence of any write and execute
>>> section in the PE Xen image.  This is required to support the NX
>>> compatible flag in the PE header.   By the end of the series the
>>> resulting PE image has no relocations that apply to text sections, as
>>> text sections are strictly mapped read-execute only.  Xen itself
>>> attempting to apply relocations to text would result in page-faults.
>>>
>>> A smoke test is added to Gitlab to ensure the PE NX support doesn't
>>> regress.
>>>
>>> Only patches 5 and 10 are carried over from v1, the rest are new.
>>>
>>> Thanks, Roger.
>>>
>>> Roger Pau Monne (11):
>>>   automation/dockers: add to README how to rebuild all containers
>>>   x86/mkreloc: fix obtaining PE image base address
>>>   x86/mkreloc: use the string table to get names
>>>   x86/mkreloc: print the linear address of relocations to read-only
>>>     sections
>>>   xen: remove -N from the linker command line
>>>   x86/efi: discard .text.header for PE binary
>>>   x86/efi: discard multiboot related entry code for PE binary
>>>   x86/boot: place trampoline code in a non-execute section
>>>   x86/efi: avoid a relocation in efi_arch_post_exit_boot()
>>>   x86/efi: do not merge all .init sections
>>>   automation/x86: add a xen.efi test with a strict NX OVMF build
>>>
>>>  automation/build/README.md                   |  7 ++
>>>  automation/build/fedora/41-x86_64.dockerfile |  5 ++
>>>  automation/gitlab-ci/test.yaml               |  9 +++
>>>  automation/scripts/qemu-smoke-x86-64-efi.sh  | 22 +++++-
>>>  xen/arch/arm/Makefile                        |  6 +-
>>>  xen/arch/ppc/Makefile                        |  6 +-
>>>  xen/arch/riscv/Makefile                      |  6 +-
>>>  xen/arch/x86/Makefile                        | 12 +--
>>>  xen/arch/x86/boot/head.S                     |  3 +-
>>>  xen/arch/x86/efi/efi-boot.h                  |  7 +-
>>>  xen/arch/x86/efi/mkreloc.c                   | 77 +++++++++++++++++---
>>>  xen/arch/x86/xen.lds.S                       | 20 +++--
>>>  12 files changed, 138 insertions(+), 42 deletions(-)
>>
>> From titles and diffstat (all Makefile changes being covered by patch 05)
>> it looks like you still don't add passing --nxcompat to the linker. Is
>> that intentionally left out here?
> 
> Hm, and I see I also failed to add (the already RB patch) "xen/build:
> warn about RWX load segments".
> 
> nxcompat should be enabled by default I think?  I can of course make
> it explicit by adding to the PE link command line.

It's not always the default for GNU ld:

#define DEFAULT_DLL_CHARACTERISTICS     (${cygwin_behavior} ? 0 : \
                                           
IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
                                         | 
IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
                                         | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)

And even that I'm not sure is entirely right. I think it goes from the 
assumption
that everything that isn't Cygwin is MinGW. EFI, however, is yet something else.
I'm further unconvinced that for any environment the linker may reasonably set
this bit without the programmer's consent. But of course that's also a matter of
how things are documented - there's a command line option after all to turn off
the flag.

Plus there's yet another concern I have. Historical knowledge (i.e. may no 
longer
be true) of mine is that the DLL characteristics field is applicable only for
binaries which have the IMAGE_FILE_DLL flag set in the respective header field.
EFI binaries aren't libraries, though. Otoh GNU ld, judging from source code,
apparently doesn't set the flag even for DLLs (or I'm simply failing to spot the
respective use of IMAGE_FILE_DLL). Whereas going from observations I find the 
bit
is set in DLLs of the Cygwin installation I have sitting around somewhere. (IOW 
-
I'm confused.)

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.