From patchwork Wed May 6 15:25:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 11531437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2562714C0 for ; Wed, 6 May 2020 15:26:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAD4221582 for ; Wed, 6 May 2020 15:26:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qqNNQr31"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=axis.com header.i=@axis.com header.b="HX1d1HR5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAD4221582 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=axis.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=pOhoM0wNchQ/sxu2htatowGTORufva+bbYM3PPlx/Sc=; b=qqNNQr31TtDZp3 3nOnJ26dgO0APwiim11ymZRGCdHtIeV2YM6itjQq8JX/iOuuWAjhTAPwWZgncLX1o2xefwDJbW5S+ q8RN/Z8zO+9Xh0lzz6oBSz+xXcoeWqr2B+tRBqU9NFF60tGf3fUPvq7yJq1kugwvwf/ST2GUKThdp gbXmKFa9soQcY2mwrcErOeWTR8jVeTGmK7z1OPS/nceNYHWCt7i5gvsc+Nity9hi867Vx7PgP4NML dWPiMqr+kGkBWMIBpU9djQaoonVuC8nZe6eYLJHKfZNnALa9QD8n0f3uOpvJzo5lNnP7PcZSx/TGw Ylwg2hoXtEPvTLo74ysw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWLvz-0007jN-QF; Wed, 06 May 2020 15:26:07 +0000 Received: from smtp1.axis.com ([195.60.68.17]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWLvj-000793-Hw for linux-arm-kernel@lists.infradead.org; Wed, 06 May 2020 15:25:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=2609; q=dns/txt; s=axis-central1; t=1588778751; x=1620314751; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=O3zZXkaxPHeAY/TBjlQEWSHvqpGeNBw93CZThIyniZI=; b=HX1d1HR5BSLQbNOD+NYjXv4aVBbAhmQSePlTaitXTtBef4FFuWYPesQH 6YaoexPAqPZLjSlt9yTAoCkauZDC4Zdc9L7EA5u33CPOIjJbsEaHdkkwW f8h/kwo6IBJldestz5tK1CkgFzxeZ7pBlJuAbYB7HXFiaPc6XKwgP4GR/ dEo/NlK5du/4MpPSXIw+iwwrBEzx2+/dsFTeNsRJkFlp1ILdbQdtFLLW9 XTZWMXDa1bitCa4R9gBXm9faOzhQeSPSohUj0aDUaesWTQ4M9oXi8fQHB POUrELf8weOY4IfV9Wqrgl9KN42nwMVM0f+gG/AVky8GSFGuLfFB3zNxy Q==; IronPort-SDR: J8buDQ1P7x0El2fjyKL8g2YP8RC//BKjDSHr2nfNC3kJ4pY+gEB8kkY7IuGWzKvemotBhBO/wj BKVIeO0yfqDHt3Y78bC94BJDQVXowDJgFUGKO//+MmbGuSNPPuPLU/GfbWco/INACk9vK3kGgj 7sNYuD9aHKC9oTn8X0XMn9h53dLwbntWmrLfxKCcqDLp0YCoLjYaCp/evAUije215ZohFxuCgN aLLy+BwideKkwZ/1ynFaour1kzp7qJhhJjvepVjgaAnfY0jr/sP1zS8lW+YlYDjDBAncgpzBBs bOU= X-IronPort-AV: E=Sophos;i="5.73,359,1583190000"; d="scan'208";a="8454940" From: Vincent Whitchurch To: , Subject: [PATCH 1/2] module: allow arch overrides for .init section names Date: Wed, 6 May 2020 17:25:32 +0200 Message-ID: <20200506152533.31286-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200506_082552_887276_094F37C0 X-CRM114-Status: UNSURE ( 9.16 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.60.68.17 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Whitchurch , kernel@axis.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org ARM stores unwind information for .init.text in sections named .ARM.extab.init.text and .ARM.exidx.init.text. Since those aren't currently recognized as init sections, they're allocated along with the core section, and relocation fails if the core and the init section are allocated from different regions and can't reach other. final section addresses: ... 0x7f800000 .init.text .. 0xcbb54078 .ARM.exidx.init.text .. section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000) Allow architectures to override the section name so that ARM can fix this. Signed-off-by: Vincent Whitchurch --- include/linux/moduleloader.h | 2 ++ kernel/module.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index ca92aea8a6bd..07d079085f11 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -29,6 +29,8 @@ void *module_alloc(unsigned long size); /* Free memory returned from module_alloc. */ void module_memfree(void *module_region); +bool module_init_section(const char *name); + /* Determines if the section name is an exit section (that is only used during * module unloading) */ diff --git a/kernel/module.c b/kernel/module.c index 33569a01d6e1..a5f2b4e1ef53 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2370,6 +2370,11 @@ static long get_offset(struct module *mod, unsigned int *size, return ret; } +bool __weak module_init_section(const char *name) +{ + return strstarts(name, ".init"); +} + /* Lay out the SHF_ALLOC sections in a way not dissimilar to how ld might -- code, read-only data, read-write data, small data. Tally sizes, and place the offsets into sh_entsize fields: high bit means it @@ -2400,7 +2405,7 @@ static void layout_sections(struct module *mod, struct load_info *info) if ((s->sh_flags & masks[m][0]) != masks[m][0] || (s->sh_flags & masks[m][1]) || s->sh_entsize != ~0UL - || strstarts(sname, ".init")) + || module_init_section(sname)) continue; s->sh_entsize = get_offset(mod, &mod->core_layout.size, s, i); pr_debug("\t%s\n", sname); @@ -2433,7 +2438,7 @@ static void layout_sections(struct module *mod, struct load_info *info) if ((s->sh_flags & masks[m][0]) != masks[m][0] || (s->sh_flags & masks[m][1]) || s->sh_entsize != ~0UL - || !strstarts(sname, ".init")) + || !module_init_section(sname)) continue; s->sh_entsize = (get_offset(mod, &mod->init_layout.size, s, i) | INIT_OFFSET_MASK); From patchwork Wed May 6 15:25:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 11531435 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF02014B4 for ; Wed, 6 May 2020 15:25:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8F5A20B1F for ; Wed, 6 May 2020 15:25:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="M+eCWxrY"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=axis.com header.i=@axis.com header.b="oKjv5hKK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8F5A20B1F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=axis.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c7k5YIL9vkbeo0gy4FnCt2joHq0lw5jEE3yyICzHcJU=; b=M+eCWxrYZ2zUOB 9zaxmb/E+OVKyFKRZeDtM2RqIkJEdUuu3G3jYjkUWCzz3hDAjzSEpyWfBTf6catbWI36wBZYUmFyx jAF7MotbKWbCas1qOOU4+3gQXhtU3R9dUzuiy+UkOBgr3etdTbl/ca9y80WI6ss3gLW58QOt5AHZe IY5nCqUM1IkLTKCwfAoiCEa9vQDFR9MJtDQLxR4PKohKCGF+xXoqti9Cp2/0l1UxziKYCey/r3zS0 ZQEbvgExUJ9+LHBW42nNicL1QuZ55ynxxMBWARCTr3BfMFByls9sb6W8NMpfNfN00zaVgnnjr3H4Z J36PfFnmL/ku6sQKQVxw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWLvn-0007Fu-Q6; Wed, 06 May 2020 15:25:55 +0000 Received: from smtp2.axis.com ([195.60.68.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWLvj-00079C-V7 for linux-arm-kernel@lists.infradead.org; Wed, 06 May 2020 15:25:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=1984; q=dns/txt; s=axis-central1; t=1588778752; x=1620314752; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=g4pSnXC9ETSX82mL7jdj/f/E60NtYuVks+hnYgNlpAE=; b=oKjv5hKKLl4nJLmWrs861+z4gT/6fExAa83WZESxw7S642CRt20z/LJ5 d0vixxYY7hPmR/fxFm2YnbAV3wYGqosRHlp6f0Dzk/U69wuHCBFlWENTV 9uT0uMG+2m1TvVWnPwxoMgLiUbFHu2SI8KuaqcXfftEtMGtk5XLZaM8Uk +R2FVKl9Gui4f8lQ4F5o32bRLjI1Il8QtQIPclGXpPKZIp+bj7AME/Jyb gJsLTgyHRvilPOC32VU8nDENXYCwUEhtzNTwFByVEotTnntKViJZxzrZv Y5tGcAj9S3TtqDSw8y5hPbmfhXxR2Ho/Gvfe4ofupGYvari0SC72JR2bh g==; IronPort-SDR: AKBGHpcM8BafnapRQsr1FxP3dvICNjoNiKOvJze/+/IugtOp7sq8s6+xM8k6OISvdahdvSesLQ y+KB0pKhJ8uYqtklAe7SGgadnPokY0B7z8aizYJ5Srqi1xo7o5MaS/tYmg4H6Jrr+epHco5pwW ka31te4LKvOcNeWtTojZxFx6vZv41ZSHUhwyX2ATO4AtgKTRAH8aRAsvqlG65IU2O0z7tkpNPg HRYj9S7mulBTjiQxGRUJDvSgLvxhMrgEIHVfye8OLeqzM5NSWaZ3W+8jrQ+5HPyoVDXxRg5Abz utA= X-IronPort-AV: E=Sophos;i="5.73,359,1583190000"; d="scan'208";a="8222270" From: Vincent Whitchurch To: , Subject: [PATCH 2/2] ARM: module: fix handling of unwind init sections Date: Wed, 6 May 2020 17:25:33 +0200 Message-ID: <20200506152533.31286-2-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200506152533.31286-1-vincent.whitchurch@axis.com> References: <20200506152533.31286-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200506_082552_887268_57622130 X-CRM114-Status: GOOD ( 11.21 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.60.68.18 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vincent Whitchurch , kernel@axis.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Unwind information for init sections is placed in .ARM.exidx.init.text and .ARM.extab.init.text. The module core doesn't know that these are init sections so they are allocated along with the core sections, and if the core and init sections get allocated in different memory regions (which is possible with CONFIG_ARM_MODULE_PLTS=y) and they can't reach each other, relocation fails: final section addresses: ... 0x7f800000 .init.text .. 0xcbb54078 .ARM.exidx.init.text .. section 16 reloc 0 sym '': relocation 42 out of range (0xcbb54078 -> 0x7f800000) Fix this by informing the module core that these sections are init sections, and by removing the init unwind tables before the module core frees the init sections. Signed-off-by: Vincent Whitchurch --- arch/arm/kernel/module.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index deef17f34bd2..af0a8500a24e 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -55,6 +55,13 @@ void *module_alloc(unsigned long size) } #endif +bool module_init_section(const char *name) +{ + return strstarts(name, ".init") || + strstarts(name, ".ARM.extab.init") || + strstarts(name, ".ARM.exidx.init"); +} + bool module_exit_section(const char *name) { return strstarts(name, ".exit") || @@ -409,8 +416,17 @@ module_arch_cleanup(struct module *mod) #ifdef CONFIG_ARM_UNWIND int i; - for (i = 0; i < ARM_SEC_MAX; i++) - if (mod->arch.unwind[i]) - unwind_table_del(mod->arch.unwind[i]); + for (i = 0; i < ARM_SEC_MAX; i++) { + unwind_table_del(mod->arch.unwind[i]); + mod->arch.unwind[i] = NULL; + } +#endif +} + +void __weak module_arch_freeing_init(struct module *mod) +{ +#ifdef CONFIG_ARM_UNWIND + unwind_table_del(mod->arch.unwind[ARM_SEC_INIT]); + mod->arch.unwind[ARM_SEC_INIT] = NULL; #endif }