linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Greg Ungerer <gerg@kernel.org>
To: linux-arm@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, ebiederm@xmission.com,
	keescook@chromium.org, brauner@kernel.org,
	Greg Ungerer <gerg@kernel.org>
Subject: [PATCH] fs: binfmt_elf_efpic: fix personality for fdpic ELF
Date: Tue, 11 Jul 2023 23:39:55 +1000	[thread overview]
Message-ID: <20230711133955.483393-1-gerg@kernel.org> (raw)

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 loaders personality setting for ELF binaries 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 but and
preserves the upper bytes. Architectures can override this for their
specific use case, and ARM does exactly this.

Signed-off-by: Greg Ungerer <gerg@kernel.org>
---

Is anyone out there using elf-fdpic on ARM?
This seems to break it rather badly due to the loss of that ADDR_LIMIT_32BIT
bit from the process personality.

 fs/binfmt_elf_fdpic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index a05eafcacfb2..f29ae1d96fd7 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -348,7 +348,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
 	if (elf_check_fdpic(&exec_params.hdr))
 		set_personality(PER_LINUX_FDPIC);
 	else
-		set_personality(PER_LINUX);
+		SET_PERSONALITY(exec_params.hdr);
 	if (elf_read_implies_exec(&exec_params.hdr, executable_stack))
 		current->personality |= READ_IMPLIES_EXEC;
 
-- 
2.25.1



             reply	other threads:[~2023-07-11 13:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 13:39 Greg Ungerer [this message]
2023-07-11 16:11 ` Kees Cook
2023-07-12  3:43   ` Greg Ungerer
2023-09-07  1:10     ` Greg Ungerer

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=20230711133955.483393-1-gerg@kernel.org \
    --to=gerg@kernel.org \
    --cc=brauner@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=viro@zeniv.linux.org.uk \
    /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