linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, mpe@ellerman.id.au,
	jeyu@redhat.com
Cc: will.deacon@arm.com, rusty@rustcorp.com.au,
	akpm@linux-foundation.org, benh@kernel.crashing.org,
	paulus@samba.org, Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
Date: Thu, 27 Oct 2016 17:27:10 +0100	[thread overview]
Message-ID: <1477585631-18574-3-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1477585631-18574-1-git-send-email-ard.biesheuvel@linaro.org>

In preparation of modifying the core modversions code to emit the CRCs
as 32-bit quantities, ensure that 64-bit PowerPC will be able to deal
with this when CONFIG_RELOCATABLE=y, in which case the CRCs will be
emitted into the final ELF binary as R_PPC64_ADDR32 relocations.

Since 32-bit relocations cannot be used to relocate memory addresses on
64-bit architectures, and since the CRC pseudo-symbol references are
emitted as anonymous relocations (i.e., against the NULL symbol in the
.dynsym section) with the final value recorded in the addend (*), we
can disregard any relocations where the symbol index != 0.

* Note that unsatisfied CRC pseudo-symbol references are emitted as
  R_PPC64_ADDR32 relocations against named symbols that are typed as
  weak undefined in the .dynsym symbol table. These can simply be
  ignored (as before), considering that zero CRCs are interpreted as
  missing, and the module code deals with that accordingly.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/powerpc/kernel/reloc_64.S | 22 ++++++++++++++++----
 arch/powerpc/relocs_check.sh   |  3 ++-
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S
index d88736fbece6..7927e00be746 100644
--- a/arch/powerpc/kernel/reloc_64.S
+++ b/arch/powerpc/kernel/reloc_64.S
@@ -14,6 +14,7 @@
 RELA = 7
 RELACOUNT = 0x6ffffff9
 R_PPC64_RELATIVE = 22
+R_PPC64_ADDR32 = 1
 
 /*
  * r3 = desired final address of kernel
@@ -66,10 +67,10 @@ _GLOBAL(relocate)
 
 	/*
 	 * Run through the list of relocations and process the
-	 * R_PPC64_RELATIVE ones.
+	 * R_PPC64_RELATIVE and R_PPC64_ADDR32 ones.
 	 */
 	mtctr	r8
-5:	ld	r0,8(9)		/* ELF64_R_TYPE(reloc->r_info) */
+5:	ld	r0,8(9)		/* reloc->r_info (type *and* symbol index) */
 	cmpdi	r0,R_PPC64_RELATIVE
 	bne	6f
 	ld	r6,0(r9)	/* reloc->r_offset */
@@ -77,9 +78,22 @@ _GLOBAL(relocate)
 	add	r0,r0,r3
 	stdx	r0,r7,r6
 	addi	r9,r9,24
-	bdnz	5b
+	b	7f
+
+	/*
+	 * CRCs of exported symbols are emitted as 32-bit relocations against
+	 * the NULL .dynsym entry, with the CRC value recorded in the addend.
+	 */
+6:	cmpdi	r0,R_PPC64_ADDR32
+	bne	7f
+	ld	r6,0(r9)	/* reloc->r_offset */
+	ld	r0,16(r9)	/* reloc->r_addend */
+	stwx	r0,r7,r6
+	addi	r9,r9,24
+
+7:	bdnz	5b
+	blr
 
-6:	blr
 
 .balign 8
 p_dyn:	.llong	__dynamic_start - 0b
diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh
index ec2d5c835170..2f510fbc87da 100755
--- a/arch/powerpc/relocs_check.sh
+++ b/arch/powerpc/relocs_check.sh
@@ -43,7 +43,8 @@ R_PPC_ADDR16_HA
 R_PPC_RELATIVE
 R_PPC_NONE' |
 	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
-	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
+	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_' |
+	grep -E -v '\<R_PPC64_ADDR32[[:space:]]+\*ABS\*'
 )
 
 if [ -z "$bad_relocs" ]; then
-- 
2.7.4

  parent reply	other threads:[~2016-10-27 16:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
2016-10-28 10:27   ` Suzuki K Poulose
2016-10-27 16:27 ` Ard Biesheuvel [this message]
2016-11-25 11:29   ` [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Michael Ellerman
2016-11-25 12:48     ` Ard Biesheuvel
2016-12-01  9:39       ` Michael Ellerman
2016-12-01  9:45         ` Ard Biesheuvel
2016-12-01 16:28           ` Ard Biesheuvel
2016-10-27 16:27 ` [PATCH v3 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs Ard Biesheuvel
2016-11-04  9:55 ` [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
2016-11-10  4:22   ` Michael Ellerman
2016-11-15  9:13     ` Ard Biesheuvel
2016-11-25  8:44       ` Ard Biesheuvel
2016-11-25 11:12         ` Michael Ellerman
2016-11-16 19:23 ` Uwe Kleine-König
2016-11-16 20:29   ` Ard Biesheuvel

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=1477585631-18574-3-git-send-email-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=jeyu@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=rusty@rustcorp.com.au \
    --cc=will.deacon@arm.com \
    /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;
as well as URLs for NNTP newsgroup(s).