From patchwork Tue Jan 17 19:26:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 716352 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v30Xm6z0vz9sBR for ; Wed, 18 Jan 2017 06:29:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ycsr7Wjf"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3v30Xm5TjHzDqSP for ; Wed, 18 Jan 2017 06:29:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ycsr7Wjf"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3v30TJ08M2zDqKV for ; Wed, 18 Jan 2017 06:26:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ycsr7Wjf"; dkim-atps=neutral Received: by mail-wm0-x235.google.com with SMTP id d140so23297999wmd.0 for ; Tue, 17 Jan 2017 11:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6BjveLswiWLNoylGErZe8kvErpMFYGm152BnKNyqIQw=; b=Ycsr7Wjf96cqRBtEa5ON/g5dInCdzpSHsY4FBoiu4IDZ2EHeAnO+Lk6TpfPcMDboOs n+6w3uoURbt2rCBLolvIu8d5TNFHcrIxcm0I8GSKTy6HHFL9X6Qatx9dSHj9KGAkZF3+ Lq5LOFmxOp3EQN0vcSqa7EIgsjRf0bpv6VGqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6BjveLswiWLNoylGErZe8kvErpMFYGm152BnKNyqIQw=; b=SA1HdndNC9h3ZZqToOXGxhMcRENN0BxxZ/bVZyJ0vYCJmgCm3mb/uBwvt8w1swkAmI IjV83lkn6VaGp2Gj4q8iFDE/Swf+miKcokzIAA4xFrBBkkOhs1tXpgmUFYR7BTB8JSnW 19F/L3ATwSAK8I+06hhIlAc6Lxkp+wfDgEpteXUlWsNJZmn3ozReSDFsVlsZcbtxRDgd AyD7FQp7vTa9IPrqu6Jf7Q/iWdoF+WOyPfOxvVHDQeNBzK73Pdwc1xgNOJT5MhmYrddn Xv9Bf6XHmzZBRYxj8J0bZWh71nxIk5NSMmZ8APEkoO35kIfFArN7ErVmk1pyMlceFQbE 8iGg== X-Gm-Message-State: AIkVDXLxMcG5mvn10v0GaykeY0O8OsxvB3jfsRea2hh+lSSImzUTFXMcCRLQzjVDfLt7wpG2 X-Received: by 10.223.152.2 with SMTP id v2mr21780749wrb.109.1484681185343; Tue, 17 Jan 2017 11:26:25 -0800 (PST) Received: from localhost.localdomain ([160.167.203.25]) by smtp.gmail.com with ESMTPSA id 197sm39171953wmy.16.2017.01.17.11.26.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jan 2017 11:26:24 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, mpe@ellerman.id.au, jeyu@redhat.com Subject: [PATCH v4 1/3] powerpc/reloc32: fix corrupted modversion CRCs Date: Tue, 17 Jan 2017 19:26:11 +0000 Message-Id: <1484681173-11644-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484681173-11644-1-git-send-email-ard.biesheuvel@linaro.org> References: <1484681173-11644-1-git-send-email-ard.biesheuvel@linaro.org> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , arnd@arndb.de, suzuki.poulose@arm.com, rusty@rustcorp.com.au, will.deacon@arm.com, linuxppc-dev@lists.ozlabs.org, paulus@samba.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, torvalds@linux-foundation.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 Signed-off-by: Ard Biesheuvel --- 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