From patchwork Fri Jun 7 10:49:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 10981391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C35E01515 for ; Fri, 7 Jun 2019 10:50:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE9E028B4A for ; Fri, 7 Jun 2019 10:50:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DEA228B53; Fri, 7 Jun 2019 10:50:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3479E28B4A for ; Fri, 7 Jun 2019 10:50:14 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Kn7Mop0Dgdrb5scUq10DnC7+LLiHjW53qgLWkZdL7K4=; b=EfcaHb3rBQV8eAZEGVFz1Ek+LD U+fPL9g5f20AdOSAp1uXqbl7860hOuCOBhKG60CkXqSqCz4TioCkAC+zDKJmHR/PZCBD0MRTG2mFb ft4lyvzNu1beXq82um+KlYk5Zv7cuRYXGk/3B2QXN0d0TgkO7TPOZaYGzmrN+a+gseGv6Xbhooa3W G8VqJnjeD7uXtB0ZrzvHLWM+0h63ND+7rHZY9VWsL2dLNsdW3pMKBCOnW2q3XUSKCmxBdLSjH7zH6 ZpUsIm8lBM0N1k3OAaIls1u5/BtUSrmjwFHfcvFweIqaWnUNTSCrbAvPx0PFJdMvsFsUKVSpUhaVA 6BLNoyMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZCRg-000118-NR; Fri, 07 Jun 2019 10:50:04 +0000 Received: from mx1.tq-group.com ([62.157.118.193]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZCRT-0000qh-14 for linux-arm-kernel@lists.infradead.org; Fri, 07 Jun 2019 10:49:52 +0000 X-IronPort-AV: E=Sophos;i="5.60,562,1549926000"; d="scan'208";a="7741350" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 07 Jun 2019 12:49:39 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Fri, 07 Jun 2019 12:49:39 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Fri, 07 Jun 2019 12:49:39 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1559904579; x=1591440579; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=fKg2mD/qwL/cmX0j2krbwJOZX3Iu3z3MEa+o5iUU+44=; b=DBwoQNWKuPzt9rGLL4dgvkecWPdqa/WmG7lsqMJ9xUabMGOucUf3q9Bf Cs0ltAZKpy2NzHybDGFLhOextb8ZaeI9Uq1EN2+EAPT2GPZT4xSMcjojr RJ8Yuqzl9cC08fJlxJHSO07rQ+a/sSNi9NMlaUTbFQc3C+wyzmzKR1sc4 0NkKB1CMoljyIne2UBxcpQNmCRyoDKIvdLAJKx/W6WEZyhNXMsUt5aB78 2vfql7zPufxPG6pJq+Cl0bLDNgDZxbarLxKo0S8K2MFL8I8JZ3Uk+zgzJ 8yCdCbdNN51jYgRkJkTgxsr1HraJFraanXsIBdw5bsMB2t7WeT8W0AuTA g==; X-IronPort-AV: E=Sophos;i="5.60,562,1549926000"; d="scan'208";a="7741349" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 07 Jun 2019 12:49:39 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.117.49.26]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 5D9FA280074; Fri, 7 Jun 2019 12:49:46 +0200 (CEST) From: Matthias Schiffer To: Russell King , Jessica Yu Subject: [PATCH modules v2 1/2] module: allow arch overrides for .exit section names Date: Fri, 7 Jun 2019 12:49:11 +0200 Message-Id: <20190607104912.6252-2-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607104912.6252-1-matthias.schiffer@ew.tq-group.com> References: <20190607104912.6252-1-matthias.schiffer@ew.tq-group.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190607_034951_392226_0DFA0ECD X-CRM114-Status: GOOD ( 11.11 ) 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: Matthias Schiffer , linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some archs like ARM store unwind information for .exit.text in sections with unusual names. As this unwind information refers to .exit.text, it must not be loaded when .exit.text is not loaded (when CONFIG_MODULE_UNLOAD is unset); otherwise, loading a module can fail due to relocation failures. Signed-off-by: Matthias Schiffer --- v2: Use __weak function as suggested by Jessica include/linux/moduleloader.h | 5 +++++ kernel/module.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 31013c2effd3..5229c18025e9 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -29,6 +29,11 @@ void *module_alloc(unsigned long size); /* Free memory returned from module_alloc. */ void module_memfree(void *module_region); +/* Determines if the section name is an exit section (that is only used during + * module unloading) + */ +bool module_exit_section(const char *name); + /* * Apply the given relocation to the (simplified) ELF. Return -error * or 0. diff --git a/kernel/module.c b/kernel/module.c index 6e6712b3aaf5..043c0f965be2 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2735,6 +2735,11 @@ void * __weak module_alloc(unsigned long size) return vmalloc_exec(size); } +bool __weak module_exit_section(const char *name) +{ + return strstarts(name, ".exit"); +} + #ifdef CONFIG_DEBUG_KMEMLEAK static void kmemleak_load_module(const struct module *mod, const struct load_info *info) @@ -2924,7 +2929,7 @@ static int rewrite_section_headers(struct load_info *info, int flags) #ifndef CONFIG_MODULE_UNLOAD /* Don't load .exit sections */ - if (strstarts(info->secstrings+shdr->sh_name, ".exit")) + if (module_exit_section(info->secstrings+shdr->sh_name)) shdr->sh_flags &= ~(unsigned long)SHF_ALLOC; #endif } From patchwork Fri Jun 7 10:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 10981393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17E1814E5 for ; Fri, 7 Jun 2019 10:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04A5C287F2 for ; Fri, 7 Jun 2019 10:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB734287F9; Fri, 7 Jun 2019 10:50:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 94FF0287F2 for ; Fri, 7 Jun 2019 10:50:29 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=UpedVviBj59EkF9h14usHqVkmzglg4hT51Bw5p7eR3U=; b=haMmOoT+HQBsipOn2q9gIg2R84 8EclZaYq0pMBmz2beVcMoQHRGJczbfRhva/Hv+PVM/FmW7bUU49WLvzEL7Uk4iPgIB5L/I4i2hUYw pyrRL4lxPCNOWLfD7zJfl3OYTg79Fkp5ymCUzQe347eIBmsriI0X3UDmjiwk8BHpHtD3FR7VKlQ/+ dMyZc7S0o9tdiRhGaLUEomCP0UKUvNJ7WZrp6eqcVWCD9nCBtJvp6CGBCMcmMb8dbpyVlF7SNssyR kYHlLl9Jb/McwVGZFIdP2DbK0sM77AY9b/+lQF/y7BAxwmyooaluz0hWXXY1T9zlTQthWCOdFfTvM XFWXtXMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hZCRx-0002QC-4v; Fri, 07 Jun 2019 10:50:21 +0000 Received: from mx1.tq-group.com ([62.157.118.193]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hZCRU-0000re-6Y for linux-arm-kernel@lists.infradead.org; Fri, 07 Jun 2019 10:49:53 +0000 X-IronPort-AV: E=Sophos;i="5.60,562,1549926000"; d="scan'208";a="7741352" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 07 Jun 2019 12:49:39 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Fri, 07 Jun 2019 12:49:39 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Fri, 07 Jun 2019 12:49:39 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1559904579; x=1591440579; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=zT95b/achx15JXRT8jtCbEqeZxzU7o/BMcswA2iPOao=; b=q5Xy3O5MVHv287lIWXVkHKQb4YzZSGbEch60r4F9IzEHO7SXrL5E5iov 4Hj+Yd42ZbXPCEEeuzFXXASh8cCtIoD7o7B18a9GXN2DewB8fccNewqBJ FZWF6wFoCII/DwrqdG24yo/y2sqN9yIy9w3zRog67jryJMLqLaM6BDSF3 +O7m3UOV61zB8o6/AeeNVx3Je2cLl8ni46tQZYKHooybsbI3Fqr2OaLWn WlVOCM1pMKyskFrA9FWDpWxa2Rwd3NbHKbfnNB+KY6pvCjFgFpX3yHdWw I/yWEZHnLZIo/WwTJc0gZZKNi7GdRx85XP7UUPffqNobrq4TGp11LjD1k w==; X-IronPort-AV: E=Sophos;i="5.60,562,1549926000"; d="scan'208";a="7741351" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 07 Jun 2019 12:49:39 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.117.49.26]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 7E995280075; Fri, 7 Jun 2019 12:49:46 +0200 (CEST) From: Matthias Schiffer To: Russell King , Jessica Yu Subject: [PATCH modules v2 2/2] ARM: module: recognize unwind exit sections Date: Fri, 7 Jun 2019 12:49:12 +0200 Message-Id: <20190607104912.6252-3-matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190607104912.6252-1-matthias.schiffer@ew.tq-group.com> References: <20190607104912.6252-1-matthias.schiffer@ew.tq-group.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190607_034952_584159_F5CDD28F X-CRM114-Status: UNSURE ( 7.55 ) X-CRM114-Notice: Please train this message. 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: Matthias Schiffer , linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In addition to the prefix ".exit", ".ARM.extab.exit" and ".ARM.exidx.exit" must be recognized as exit sections as well. Otherwise, loading modules can fail without CONFIG_MODULE_UNLOAD depending on the memory layout, when relocations for the unwind sections refer to the .exit.text section: imx_sdma: section 16 reloc 0 sym '': relocation 42 out of range (0x7f015260 -> 0xc0f5a5e8) where 0x7F000000 is the module load area and 0xC0000000 is the vmalloc area. Relocation 42 refers to R_ARM_PREL31, which is limited to signed 31bit offsets. Signed-off-by: Matthias Schiffer --- v2: Use __weak function as suggested by Jessica arch/arm/kernel/module.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 3ff571c2c71c..692001aabb0f 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -58,6 +58,13 @@ void *module_alloc(unsigned long size) } #endif +bool module_exit_section(const char *name) +{ + return strstarts(name, ".exit") || + strstarts(name, ".ARM.extab.exit") || + strstarts(name, ".ARM.exidx.exit"); +} + int apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, unsigned int relindex, struct module *module)