Patch "x86/purgatory: Switch to the position-independent small code model" has been added to the 6.6-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

    x86/purgatory: Switch to the position-independent small code model

to the 6.6-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:
     x86-purgatory-switch-to-the-position-independent-sma.patch
and it can be found in the queue-6.6 subdirectory.

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



commit 1a3c18233417cea1ba37431c2ddda2b75303d289
Author: Ard Biesheuvel <ardb@xxxxxxxxxx>
Date:   Thu Apr 18 22:17:06 2024 +0200

    x86/purgatory: Switch to the position-independent small code model
    
    [ Upstream commit cba786af84a0f9716204e09f518ce3b7ada8555e ]
    
    On x86, the ordinary, position dependent small and kernel code models
    only support placement of the executable in 32-bit addressable memory,
    due to the use of 32-bit signed immediates to generate references to
    global variables. For the kernel, this implies that all global variables
    must reside in the top 2 GiB of the kernel virtual address space, where
    the implicit address bits 63:32 are equal to sign bit 31.
    
    This means the kernel code model is not suitable for other bare metal
    executables such as the kexec purgatory, which can be placed arbitrarily
    in the physical address space, where its address may no longer be
    representable as a sign extended 32-bit quantity. For this reason,
    commit
    
      e16c2983fba0 ("x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors")
    
    switched to the large code model, which uses 64-bit immediates for all
    symbol references, including function calls, in order to avoid relying
    on any assumptions regarding proximity of symbols in the final
    executable.
    
    The large code model is rarely used, clunky and the least likely to
    operate in a similar fashion when comparing GCC and Clang, so it is best
    avoided. This is especially true now that Clang 18 has started to emit
    executable code in two separate sections (.text and .ltext), which
    triggers an issue in the kexec loading code at runtime.
    
    The SUSE bugzilla fixes tag points to gcc 13 having issues with the
    large model too and that perhaps the large model should simply not be
    used at all.
    
    Instead, use the position independent small code model, which makes no
    assumptions about placement but only about proximity, where all
    referenced symbols must be within -/+ 2 GiB, i.e., in range for a
    RIP-relative reference. Use hidden visibility to suppress the use of a
    GOT, which carries absolute addresses that are not covered by static ELF
    relocations, and is therefore incompatible with the kexec loader's
    relocation logic.
    
      [ bp: Massage commit message. ]
    
    Fixes: e16c2983fba0 ("x86/purgatory: Change compiler flags from -mcmodel=kernel to -mcmodel=large to fix kexec relocation errors")
    Fixes: https://bugzilla.suse.com/show_bug.cgi?id=1211853
    Closes: https://github.com/ClangBuiltLinux/linux/issues/2016
    Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>
    Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx>
    Reviewed-by: Nathan Chancellor <nathan@xxxxxxxxxx>
    Reviewed-by: Fangrui Song <maskray@xxxxxxxxxx>
    Acked-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
    Tested-by: Nathan Chancellor <nathan@xxxxxxxxxx>
    Link: https://lore.kernel.org/all/20240417-x86-fix-kexec-with-llvm-18-v1-0-5383121e8fb7@xxxxxxxxxx/
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 08aa0f25f12a0..8d1c82795ea1d 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -42,7 +42,8 @@ KCOV_INSTRUMENT := n
 # make up the standalone purgatory.ro
 
 PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
-PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss -g0
+PURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss -g0
+PURGATORY_CFLAGS += -fpic -fvisibility=hidden
 PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
 PURGATORY_CFLAGS += -fno-stack-protector
 




[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