All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: luto@kernel.org, tglx@linutronix.de
Cc: hch@lst.de, hpa@zytor.com, bp@alien8.de, rric@kernel.org,
	peterz@infradead.org, mingo@redhat.com, x86@kernel.org,
	linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com,
	sean.j.christopherson@intel.com,
	Gabriel Krisman Bertazi <krisman@collabora.com>,
	kernel@collabora.com
Subject: [PATCH v3 05/10] elf: Expose ELF header in compat_start_thread
Date: Sat,  3 Oct 2020 23:25:31 -0400	[thread overview]
Message-ID: <20201004032536.1229030-6-krisman@collabora.com> (raw)
In-Reply-To: <20201004032536.1229030-1-krisman@collabora.com>

Like it is done for SET_PERSONALITY with x86, which requires the ELF
header to select correct personality parameters, x86 requires the
headers on compat_start_thread to choose starting CS for ELF32 binaries,
instead of relying on the going-away TIF_IA32/X32 flags.

This patch adds an indirection macro to ELF invocations of START_THREAD,
that x86 can reimplement to receive the extra parameter just for ELF
files.  This requires no changes to other architectures who don't need
the header information, they can continue to use the original
start_thread for ELF and non-ELF binaries, and it prevents affecting
non-ELF code paths for x86.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 fs/binfmt_elf.c        | 2 +-
 fs/compat_binfmt_elf.c | 9 +++++++--
 include/linux/elf.h    | 5 +++++
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 13d053982dd7..7fec77a38b8d 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1279,7 +1279,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
 #endif
 
 	finalize_exec(bprm);
-	start_thread(regs, elf_entry, bprm->p);
+	START_THREAD(elf_ex, regs, elf_entry, bprm->p);
 	retval = 0;
 out:
 	return retval;
diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
index 2d24c765cbd7..12b991368f0a 100644
--- a/fs/compat_binfmt_elf.c
+++ b/fs/compat_binfmt_elf.c
@@ -106,8 +106,13 @@
 #endif
 
 #ifdef	compat_start_thread
-#undef	start_thread
-#define	start_thread		compat_start_thread
+#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp)	\
+	compat_start_thread(regs, new_ip, new_sp)
+#endif
+
+#ifdef	COMPAT_START_THREAD
+#undef	START_THREAD
+#define START_THREAD		COMPAT_START_THREAD
 #endif
 
 #ifdef	compat_arch_setup_additional_pages
diff --git a/include/linux/elf.h b/include/linux/elf.h
index 5d5b0321da0b..6dbcfe7a3fd7 100644
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -22,6 +22,11 @@
 	SET_PERSONALITY(ex)
 #endif
 
+#ifndef START_THREAD
+#define START_THREAD(elf_ex, regs, elf_entry, start_stack)	\
+	start_thread(regs, elf_entry, start_stack)
+#endif
+
 #define ELF32_GNU_PROPERTY_ALIGN	4
 #define ELF64_GNU_PROPERTY_ALIGN	8
 
-- 
2.28.0


  parent reply	other threads:[~2020-10-04  3:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-04  3:25 [PATCH v3 00/10] Reclaim TIF_IA32 and TIF_X32 Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 01/10] x86: events: Avoid TIF_IA32 when checking 64bit mode Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] perf/x86: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 02/10] x86: Simplify compat syscall userspace allocation Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] x86/compat: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 03/10] x86: oprofile: Avoid TIF_IA32 when checking 64bit mode Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] x86/oprofile: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 04/10] x86: elf: Use e_machine to choose DLINFO in compat Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] x86/elf: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` Gabriel Krisman Bertazi [this message]
2020-10-26 12:52   ` [tip: x86/cleanups] elf: Expose ELF header in compat_start_thread() tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 06/10] x86: elf: Use e_machine to select start_thread for x32 Gabriel Krisman Bertazi
2020-10-08  0:05   ` Andy Lutomirski
2020-10-26 12:52   ` [tip: x86/cleanups] x86/elf: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 07/10] elf: Expose ELF header on arch_setup_additional_pages Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] elf: Expose ELF header on arch_setup_additional_pages() tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 08/10] x86: elf: Use e_machine to select additional_pages between x32 Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] x86/elf: Use e_machine to check for x32/ia32 in setup_additional_pages() tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 09/10] x86: Convert mmu context ia32_compat into a proper flags field Gabriel Krisman Bertazi
2020-10-08  0:07   ` Andy Lutomirski
2020-10-26 12:52   ` [tip: x86/cleanups] x86/mm: " tip-bot2 for Gabriel Krisman Bertazi
2020-10-04  3:25 ` [PATCH v3 10/10] x86: Reclaim TIF_IA32 and TIF_X32 Gabriel Krisman Bertazi
2020-10-26 12:52   ` [tip: x86/cleanups] " tip-bot2 for Gabriel Krisman Bertazi
2020-11-05 20:01   ` [PATCH v3 10/10] " Dmitry Safonov

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=20201004032536.1229030-6-krisman@collabora.com \
    --to=krisman@collabora.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hch@lst.de \
    --cc=hpa@zytor.com \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rric@kernel.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.