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: 91716 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp655150qgi; Tue, 17 Jan 2017 11:27:19 -0800 (PST) X-Received: by 10.84.224.199 with SMTP id k7mr61806746pln.25.1484681239790; Tue, 17 Jan 2017 11:27:19 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z43si25845773plh.111.2017.01.17.11.27.19; Tue, 17 Jan 2017 11:27:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751159AbdAQT03 (ORCPT + 25 others); Tue, 17 Jan 2017 14:26:29 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:36533 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbdAQT00 (ORCPT ); Tue, 17 Jan 2017 14:26:26 -0500 Received: by mail-wm0-f48.google.com with SMTP id c85so214373437wmi.1 for ; Tue, 17 Jan 2017 11:26:26 -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=EDSicuYKKlAw2tHft/L2wV81v3VFM1JuYR9DdQLjFnxUUKjzSgtxd0KFA83cIMrNL0 PoOkYFgSsnCVYIn2JdvMZO0aEbllWVB+P6GG9E4Qn59vqm82gmgHA0c4W4mOml1/EWzw ZZ0BPkplJ/LLHUn8BCADMW27s4XYmdTy2Aon80JQvUqcc0GtMmFx+R/0CQut6SkqG4PR f6k/lIBTUki5qWWXPFJkHIZutwjb6587ZcOfPqEJoqZXhTy5lmzNq9sq+e0W3T1mvM/y vwSKBL5vgLQjEgdS/DlpN25ruXheGRSkVt/q49MGEzXDRK/G9iiEVT8kqjv3hlfyNLz1 MafQ== X-Gm-Message-State: AIkVDXIMhpXjqgng1Maaa7yh1G6TJGZbOs/1+ZgLK7AIbrRjCOKqG0s8bXZPbNP+YVCvlt35 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 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 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 Signed-off-by: Ard Biesheuvel --- arch/powerpc/kernel/reloc_32.S | 36 +++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) -- 2.7.4 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