From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-kernel@vger.kernel.org, mpe@ellerman.id.au, jeyu@redhat.com
Cc: rusty@rustcorp.com.au, suzuki.poulose@arm.com,
will.deacon@arm.com, akpm@linux-foundation.org,
benh@kernel.crashing.org, paulus@samba.org, arnd@arndb.de,
torvalds@linux-foundation.org, viro@zeniv.linux.org.uk,
linuxppc-dev@lists.ozlabs.org,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v4 1/3] powerpc/reloc32: fix corrupted modversion CRCs
Date: Tue, 17 Jan 2017 19:26:11 +0000 [thread overview]
Message-ID: <1484681173-11644-2-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1484681173-11644-1-git-send-email-ard.biesheuvel@linaro.org>
Commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix causes
perf issues") fixed an issue with relocatable PIE kernels in a way that
essentially reintroduced the issue again for 32-bit builds.
Since the chosen approach does is not applicable to 32-bit, fix the
issue by updating the runtime relocation routine to ignore the load
offset for the interval [__start___kcrctab, __stop___kcrctab_gpl_future),
which is where the CRCs reside. This ensures that the values of the CRC
pseudo-symbols are no longer made dependent on the runtime load offset.
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/powerpc/kernel/reloc_32.S | 36 +++++++++++++++++---
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/kernel/reloc_32.S b/arch/powerpc/kernel/reloc_32.S
index f366fedb0872..150686b9febb 100644
--- a/arch/powerpc/kernel/reloc_32.S
+++ b/arch/powerpc/kernel/reloc_32.S
@@ -87,12 +87,12 @@ eodyn: /* End of Dyn Table scan */
* Work out the current offset from the link time address of .rela
* section.
* cur_offset[r7] = rela.run[r9] - rela.link [r7]
- * _stext.link[r12] = _stext.run[r10] - cur_offset[r7]
- * final_offset[r3] = _stext.final[r3] - _stext.link[r12]
+ * _stext.link[r11] = _stext.run[r10] - cur_offset[r7]
+ * final_offset[r3] = _stext.final[r3] - _stext.link[r11]
*/
subf r7, r7, r9 /* cur_offset */
- subf r12, r7, r10
- subf r3, r12, r3 /* final_offset */
+ subf r11, r7, r10
+ subf r3, r11, r3 /* final_offset */
subf r8, r6, r8 /* relaz -= relaent */
/*
@@ -101,6 +101,21 @@ eodyn: /* End of Dyn Table scan */
* r13 - points to the symbol table
*/
+#ifdef CONFIG_MODVERSIONS
+ /*
+ * Treat R_PPC_RELATIVE relocations differently when they target the
+ * interval [__start___kcrctab, __stop___kcrctab_gpl_future): in this
+ * case, the relocated quantities are CRC pseudo-symbols, which should
+ * be preserved as-is, rather than be modified to take the runtime
+ * offset into account.
+ */
+ lwz r10, (p_kcrc_start - 0b)(r12)
+ lwz r11, (p_kcrc_stop - 0b)(r12)
+ subf r12, r7, r12 /* link time addr of 0b */
+ add r10, r10, r12
+ add r11, r11, r12
+#endif
+
/*
* Check if we have a relocation based on symbol
* r5 will hold the value of the symbol.
@@ -135,7 +150,15 @@ get_type:
bne hi16
lwz r4, 0(r9) /* r_offset */
lwz r0, 8(r9) /* r_addend */
+#ifdef CONFIG_MODVERSIONS
+ cmplw r4, r10
+ blt do_add
+ cmplw r4, r11
+ blt skip_add
+do_add:
+#endif
add r0, r0, r3 /* final addend */
+skip_add:
stwx r0, r4, r7 /* memory[r4+r7]) = (u32)r0 */
b nxtrela /* continue */
@@ -207,3 +230,8 @@ p_dyn: .long __dynamic_start - 0b
p_rela: .long __rela_dyn_start - 0b
p_sym: .long __dynamic_symtab - 0b
p_st: .long _stext - 0b
+
+#ifdef CONFIG_MODVERSIONS
+p_kcrc_start: .long __start___kcrctab - 0b
+p_kcrc_stop: .long __stop___kcrctab_gpl_future - 0b
+#endif
--
2.7.4
next prev parent reply other threads:[~2017-01-17 19:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-17 19:26 [PATCH v4 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
2017-01-17 19:26 ` Ard Biesheuvel [this message]
2017-01-17 19:26 ` [PATCH v4 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Ard Biesheuvel
2017-01-18 15:30 ` Ard Biesheuvel
2017-01-17 19:26 ` [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs Ard Biesheuvel
2017-01-17 23:47 ` Linus Torvalds
2017-01-18 11:37 ` Ard Biesheuvel
2017-01-18 13:52 ` Ard Biesheuvel
2017-01-18 18:27 ` Linus Torvalds
2017-01-18 18:35 ` Linus Torvalds
2017-01-18 22:37 ` Ard Biesheuvel
2017-01-19 0:15 ` Linus Torvalds
2017-01-19 9:22 ` Ard Biesheuvel
2017-01-19 17:24 ` Linus Torvalds
2017-01-20 12:21 ` Ard Biesheuvel
2017-01-19 17:01 ` David Laight
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=1484681173-11644-2-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=jeyu@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
--cc=rusty@rustcorp.com.au \
--cc=suzuki.poulose@arm.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--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).