• Greg Ungerer's avatar
    fs: binfmt_elf_efpic: fix personality for ELF-FDPIC · 7c315158
    Greg Ungerer authored
    The elf-fdpic loader hard sets the process personality to either
    PER_LINUX_FDPIC for true elf-fdpic binaries or to PER_LINUX for normal ELF
    binaries (in this case they would be constant displacement compiled with
    -pie for example).  The problem with that is that it will lose any other
    bits that may be in the ELF header personality (such as the "bug
    emulation" bits).
    
    On the ARM architecture the ADDR_LIMIT_32BIT flag is used to signify a
    normal 32bit binary - as opposed to a legacy 26bit address binary.  This
    matters since start_thread() will set the ARM CPSR register as required
    based on this flag.  If the elf-fdpic loader loses this bit the process
    will be mis-configured and crash out pretty quickly.
    
    Modify elf-fdpic loader personality setting so that it preserves the upper
    three bytes by using the SET_PERSONALITY macro to set it.  This macro in
    the generic case sets PER_LINUX and preserves the upper bytes. 
    Architectures can override this for their specific use case, and ARM does
    exactly this.
    
    The problem shows up quite easily running under qemu using the ARM
    architecture, but not necessarily on all types of real ARM hardware.  If
    the underlying ARM processor does not support the legacy 26-bit addressing
    mode then everything will work as expected.
    
    Link: https://lkml.kernel.org/r/20230907011808.2985083-1-gerg@kernel.org
    Fixes: 1bde925d ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries")
    Signed-off-by: default avatarGreg Ungerer <gerg@kernel.org>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Eric W. Biederman <ebiederm@xmission.com>
    Cc: Greg Ungerer <gerg@kernel.org>
    Cc: Kees Cook <keescook@chromium.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    7c315158
binfmt_elf_fdpic.c 43.3 KB