public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Fangrui Song <maskray@google.com>, Arnd Bergmann <arnd@arndb.de>,
	Borislav Petkov <bp@suse.de>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <natechancellor@gmail.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	Sasha Levin <sashal@kernel.org>,
	clang-built-linux@googlegroups.com
Subject: [PATCH AUTOSEL 4.19 08/26] x86/build: Treat R_386_PLT32 relocation as R_386_PC32
Date: Wed, 24 Feb 2021 07:54:16 -0500	[thread overview]
Message-ID: <20210224125435.483539-8-sashal@kernel.org> (raw)
In-Reply-To: <20210224125435.483539-1-sashal@kernel.org>

From: Fangrui Song <maskray@google.com>

[ Upstream commit bb73d07148c405c293e576b40af37737faf23a6a ]

This is similar to commit

  b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32")

but for i386. As far as the kernel is concerned, R_386_PLT32 can be
treated the same as R_386_PC32.

R_386_PLT32/R_X86_64_PLT32 are PC-relative relocation types which
can only be used by branches. If the referenced symbol is defined
externally, a PLT will be used.

R_386_PC32/R_X86_64_PC32 are PC-relative relocation types which can be
used by address taking operations and branches. If the referenced symbol
is defined externally, a copy relocation/canonical PLT entry will be
created in the executable.

On x86-64, there is no PIC vs non-PIC PLT distinction and an
R_X86_64_PLT32 relocation is produced for both `call/jmp foo` and
`call/jmp foo@PLT` with newer (2018) GNU as/LLVM integrated assembler.
This avoids canonical PLT entries (st_shndx=0, st_value!=0).

On i386, there are 2 types of PLTs, PIC and non-PIC. Currently,
the GCC/GNU as convention is to use R_386_PC32 for non-PIC PLT and
R_386_PLT32 for PIC PLT. Copy relocations/canonical PLT entries
are possible ABI issues but GCC/GNU as will likely keep the status
quo because (1) the ABI is legacy (2) the change will drop a GNU
ld diagnostic for non-default visibility ifunc in shared objects.

clang-12 -fno-pic (since [1]) can emit R_386_PLT32 for compiler
generated function declarations, because preventing canonical PLT
entries is weighed over the rare ifunc diagnostic.

Further info for the more interested:

  https://github.com/ClangBuiltLinux/linux/issues/1210
  https://sourceware.org/bugzilla/show_bug.cgi?id=27169
  https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6 [1]

 [ bp: Massage commit message. ]

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Fangrui Song <maskray@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Link: https://lkml.kernel.org/r/20210127205600.1227437-1-maskray@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/x86/kernel/module.c |  1 +
 arch/x86/tools/relocs.c  | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 6645f123419c6..9f0be2c7e3466 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -126,6 +126,7 @@ int apply_relocate(Elf32_Shdr *sechdrs,
 			*location += sym->st_value;
 			break;
 		case R_386_PC32:
+		case R_386_PLT32:
 			/* Add the value, subtract its position */
 			*location += sym->st_value - (uint32_t)location;
 			break;
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index 3a6c8ebc8032e..aa046d46ff8ff 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -841,9 +841,11 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
 	case R_386_PC32:
 	case R_386_PC16:
 	case R_386_PC8:
+	case R_386_PLT32:
 		/*
-		 * NONE can be ignored and PC relative relocations don't
-		 * need to be adjusted.
+		 * NONE can be ignored and PC relative relocations don't need
+		 * to be adjusted. Because sym must be defined, R_386_PLT32 can
+		 * be treated the same way as R_386_PC32.
 		 */
 		break;
 
@@ -884,9 +886,11 @@ static int do_reloc_real(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
 	case R_386_PC32:
 	case R_386_PC16:
 	case R_386_PC8:
+	case R_386_PLT32:
 		/*
-		 * NONE can be ignored and PC relative relocations don't
-		 * need to be adjusted.
+		 * NONE can be ignored and PC relative relocations don't need
+		 * to be adjusted. Because sym must be defined, R_386_PLT32 can
+		 * be treated the same way as R_386_PC32.
 		 */
 		break;
 
-- 
2.27.0


  parent reply	other threads:[~2021-02-24 13:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 12:54 [PATCH AUTOSEL 4.19 01/26] staging: fwserial: Fix error handling in fwserial_create Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 02/26] x86/reboot: Add Zotac ZBOX CI327 nano PCI reboot quirk Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 03/26] vt/consolemap: do font sum unsigned Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 04/26] wlcore: Fix command execute failure 19 for wl12xx Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 05/26] Bluetooth: hci_h5: Set HCI_QUIRK_SIMULTANEOUS_DISCOVERY for btrtl Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 06/26] pktgen: fix misuse of BUG_ON() in pktgen_thread_worker() Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 07/26] ath10k: fix wmi mgmt tx queue full due to race condition Sasha Levin
2021-02-24 12:54 ` Sasha Levin [this message]
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 09/26] Bluetooth: Fix null pointer dereference in amp_read_loc_assoc_final_data Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 10/26] staging: most: sound: add sanity check for function argument Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 11/26] udlfb: Fix memory leak in dlfb_usb_probe Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 12/26] crypto: tcrypt - avoid signed overflow in byte count Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 13/26] PCI: Add a REBAR size quirk for Sapphire RX 5600 XT Pulse Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 14/26] drm/amd/display: Guard against NULL pointer deref when get_i2c_info fails Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 15/26] media: mceusb: sanity check for prescaler value Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 16/26] media: uvcvideo: Allow entities with no pads Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 17/26] f2fs: handle unallocated section and zone on pinned/atgc Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 18/26] f2fs: fix to set/clear I_LINKABLE under i_lock Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 19/26] tomoyo: ignore data race while checking quota Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 20/26] smackfs: restrict bytes count in smackfs write functions Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 21/26] Drivers: hv: vmbus: Resolve race condition in vmbus_onoffer_rescind() Sasha Levin
2021-02-24 13:21   ` Andrea Parri
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 22/26] btrfs: fix error handling in commit_fs_roots Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 23/26] parisc: Bump 64-bit IRQ stack size to 64 KB Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 24/26] ASoC: Intel: bytcr_rt5640: Add quirk for the Estar Beauty HD MID 7316R tablet Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 25/26] ASoC: Intel: bytcr_rt5640: Add quirk for the Voyo Winpad A15 tablet Sasha Levin
2021-02-24 12:54 ` [PATCH AUTOSEL 4.19 26/26] ASoC: Intel: bytcr_rt5640: Add quirk for the Acer One S1002 tablet Sasha Levin

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=20210224125435.483539-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bp@suse.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maskray@google.com \
    --cc=natechancellor@gmail.com \
    --cc=ndesaulniers@google.com \
    --cc=sedat.dilek@gmail.com \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox