From patchwork Mon Jan 24 09:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12721803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9845C433F5 for ; Mon, 24 Jan 2022 09:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2820F6B0085; Mon, 24 Jan 2022 04:22:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20AC46B0087; Mon, 24 Jan 2022 04:22:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 082496B0088; Mon, 24 Jan 2022 04:22:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id E87A46B0085 for ; Mon, 24 Jan 2022 04:22:20 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AC8338248D52 for ; Mon, 24 Jan 2022 09:22:20 +0000 (UTC) X-FDA: 79064639640.10.8733925 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-eopbgr90073.outbound.protection.outlook.com [40.107.9.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 1C8EE1C003B for ; Mon, 24 Jan 2022 09:22:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DkfdG7ScK2vgeI+nYwpg2VXiBDMgmEacARdkET6VhloWM2RhAja5zx/el0Z8/nlQRwOlR6bexTXzfWAGIdVfM8KdjRKUwJgyf2WoBowGx88yQing16Ct72EkmK25x5uOGKnGDk1YxlzH/C6RrnRFDFfQfAcqYNIhmUQ0mMcZ47DxH3MRr+qTfO32AqAjthDr5sM6Y92iVyLqpVDC5tlQagM3ISFwM5l2N8kDhXjWQb7FrJLxEaUWBZrnyp1gMuujkbfUlutDud2fJgBjZfjO6B7SmJrqG5PRotXLQqZKcdUZUzXOVYsuNhnXAbmAGCJm67mlUD1SemEtwvB1nDse8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=O+CeV327RTVvdEcxdN1wQBsa3h5QC1tyTLvFztvuQB8=; b=b0oD3cIW+VQBFXmjkye7BGgssW8TdFYSeylFylmpQ7RdKsaSl2jN/mbHafAq7nyQ3QnDJYMK0r7wJPAiX4iRbuMwMBuvTP4ykRGNJq6Ilaov1IEzJ6xmQkpFkVFKe0QHglNIDzCwpMX9yQ6ZCwAK1/HGKiUz190xKAp2lFp+B8o7V1zfCTxvZje41tyUre1bP8VjJOTSXLJOA5Y3kn1vb3AOmxgIi/7htTuhwuqluPEwOAKGR8ZQ6f9PFyOTIvLq4x5GtFS/J735UAgYc5wVehFhfiS+dXCKMuArj4SweKzYK6WFgXMHBzBylaavNyoj5O6qHot4FyFZt5RZfd6zSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0235.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.13; Mon, 24 Jan 2022 09:22:19 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.017; Mon, 24 Jan 2022 09:22:19 +0000 From: Christophe Leroy To: Luis Chamberlain , Jessica Yu CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "kgdb-bugreport@lists.sourceforge.net" , "linux-mm@kvack.org" , "linux-arch@vger.kernel.org" Subject: [PATCH 2/7] modules: Add within_module_text() macro Thread-Topic: [PATCH 2/7] modules: Add within_module_text() macro Thread-Index: AQHYEQPiNEhZhVr+ok+URNEzXjzsfg== Date: Mon, 24 Jan 2022 09:22:19 +0000 Message-ID: <0cd6fff65c1038286f62c4207c0d2e90b78c5cd4.1643015752.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9f5f4eda-6347-4440-531f-08d9df1b051b x-ms-traffictypediagnostic: PR0P264MB0235:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:227; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: PuYgn0K0sn7sTo45g+IdGEvG1NMGl4M5yPkv/hVPMv986AeGGR0QLaa/Jp8K4kuBvbrgEeoxMxa1PGpk7vrea8q3ID9vxjdTcPY1i0gIS/ZKHMHh89Vux7r6Y0+vqE6jVvD7YiYFwHeWSe1vIOy6NNLpsS3vgx5fGNjCuqE9P6f9z+VGe1mMZY59o2soL9xjaLD0r41Xk7/fZfrc8p8NYoG2K6yKImLHuZOcz9oQ1QLlr4xI94vMOEo1ShyMswcqk7VT4YR2u3ORKNbDnK2ljeK8GPWU2a+60qTKFAHJC65O4TrRRmzIE9RIvKKjjS2v4AmCaGWYayLp8OeKSQCrSik9piGP8rctkG2AkPjnCyUUQZPMACxBA3spng1g2vzS5a15M7STRXLI0Tsrlx8+kARB28V3URQ567iNCsnnL1fL+XOUNRpN6YEDWzfin3LFC+BUE3+e5bmEuYGyvMzlvxRI6/h4Emh6weKEwAQ08Ms1WiKbiHCuSLEjtnWLfEzkQBE2MZgfrU2pkRCdXS7GONXyYHgZFrIHD3JrkgXNqkkjP/Zd0xEuW0cMOvttnWGxvtLB5yvYxuu7Ap4tiBUb58F3Ocq3/9lTB7O75AftZbgWx3pXnuGOEPpzwGSu/K3Yk8Sl+1yicrZdCRpMi537j4R4Y3BuYjO+JJVu2jv7J6NmWSdFHIrSRTDxr/LCeGIhUoQzhZ5HMRKqwG7FaVaruA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(8936002)(6512007)(86362001)(66946007)(2906002)(4326008)(6506007)(66446008)(8676002)(64756008)(71200400001)(44832011)(36756003)(26005)(122000001)(66556008)(508600001)(186003)(66476007)(76116006)(38070700005)(91956017)(54906003)(5660300002)(110136005)(83380400001)(2616005)(6486002)(316002)(38100700002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?1PK7+Cy/9MCi2GmBFGfs17s?= =?iso-8859-1?q?PHfGi7KoA3Z6F2uyNGi+YWTMGSVNvzbq7G1jFQLPFYOpswGT+O6d+P6NtYpd?= =?iso-8859-1?q?/4k2WviWnMUxTuLDVj/v1RRu4/JeicX14RFXNqw0h58+5trMhwJb3X8wiF7T?= =?iso-8859-1?q?1UYR+FL+IC+8YfWQXLbLcrjDXHiKdAbED7m/KAY2n5FG2924p9KkeOvgHlr8?= =?iso-8859-1?q?TiUY6Zs7POKOOKz+E3A0b2fMvl4sVkB+yekEz/a1/kJCRdF7m8HV32ODrkcJ?= =?iso-8859-1?q?veRhONQEta5ly3QevBxsldj5kch9LirxHKWTb7HZdGov6PGqwyxIc4XwnaN8?= =?iso-8859-1?q?r635RNb9LMryTVAHUlGAOfsCYBfnOqHHwJkK27A94uYE25s6R9bsbE3ubDrO?= =?iso-8859-1?q?vWwk+I3FSqxtW/SHnuzQUUDuctZF/BaI72h4nury4hH5ANvZErxwTexlicP1?= =?iso-8859-1?q?nV0Sox6Vzc3twwYhMBjwZyc1y6ly4N4FQ3Z41C8s9NjKDalzZSrrGZfPuLfL?= =?iso-8859-1?q?IBfdVZRme8jDbfsyAQ38vg2hFv7QfTAqFMv8gax55G0oGaxrd0DhXPQ+uuNC?= =?iso-8859-1?q?1KEOkG7EiowGa1MxseISbNzrFeBxHbTilLOHXSCfI0YXd+V7bXy0Jpya8zcn?= =?iso-8859-1?q?kR2R/FBYPQlxTgQeXmIO0W1c6pf1ogVazICK5PLGiXJMyat+Nc8z/8kGbY9K?= =?iso-8859-1?q?isfuqMvzEA0NbnzPcmFCzFVJNMvuc3yhOI/mlu8paO/P0be8XW+FBzqGkjpF?= =?iso-8859-1?q?z8IldR2+mTVF51VRWzCGGU/iNkaCNdc2jYgbJkoXrARaUKLLD/9oCSNdsl/p?= =?iso-8859-1?q?z54GoLxrH5WixF7+jDY6qxofT8WxGIzZKQOXRP+fkkGWfCV+eWGxRbQtq4y4?= =?iso-8859-1?q?7xB/hSoWXHxWxh4mPOslTqMXiQYv7uBnzMe5rglluDEnxiXWdoWJyp1DTUHk?= =?iso-8859-1?q?N4RlpBP4WWxy+On1SPsy2fGt3UfenILn2ZvSwkw/XfCSK+SHKBv3/buIyBPj?= =?iso-8859-1?q?nZGTsPt0VmSbsqwHIEzz3/RYOg7uCz9Ejz3lc/2xFaXHTNfcDNyTkhSv441z?= =?iso-8859-1?q?bwdgiWK6xe7hUsOjAE9iFoF7pDhNcznh/6edg3NNtJKponiMtWUvgAEAhnPy?= =?iso-8859-1?q?IAdyC1Wgi67ZWLpBGEwKkN7IFb6hCdB7JRZcrd+C1YLROb/lYBc5EGJKiyF2?= =?iso-8859-1?q?K4Ji/PDhXJqNrcmDawJxRnzt6xUZ9npok+o1pQSU/lADBxaL7ymSyKNmpA9M?= =?iso-8859-1?q?pM98pVqj6EFLdis6Xm28J0DDrBJhiNl+/dy91tB8pHOKihEMOHQB0DzQOr5T?= =?iso-8859-1?q?r+uBRzBN7gRSI0Fq77YNs5lvY3U1dfw4sVTBrQudWNBUQnC8log1z8eyrkH3?= =?iso-8859-1?q?FubYyEn9hgrG64iZKp3iZyOmcDICkoYhvGeax9PyQbJmjsmKifx1Sp91/53f?= =?iso-8859-1?q?iVt1+uDoGrSUUCMYbDc4vZaW1/34Fr2jeHhU29JyVT4U7cV7BqG072aje3u+?= =?iso-8859-1?q?PautkgInKEIRRvVHDFfl625aIr/cgN8svMHSjyQDViHnJPIl7gTRKNJM6dJw?= =?iso-8859-1?q?4iMKh3rJ30q5U/b0lYf1ejTfg2ZNrwDWNVhFIRyzE2i0Rm7dvPDgi1iLCkTP?= =?iso-8859-1?q?5Xq42Z4uBdu8Xt9U7vu+SA/ryGDmZ1qDXSJPcstO0IEpZrLKh+CEfje62Bi0?= =?iso-8859-1?q?mhpjBCo1FXD+5Rnhr5jcE+AZyiBZjM4SZP4oUdBAR93eaBz/EtWEtUmQR3OE?= =?iso-8859-1?q?uwB4=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 9f5f4eda-6347-4440-531f-08d9df1b051b X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2022 09:22:19.1642 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: le6uaqCbUcrkeXcMDeo4ArJzqgd9kk4SnQ3m1i0I2D2IfJZMPhz1QsSnwNy29xpR48fiyjdbG27ry8LTQE2UowdS58BlVcyUV5HghejseRE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0235 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1C8EE1C003B X-Stat-Signature: 9cjyzoakbbj64513a8tbtxog955bwr8d Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.9.73 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1643016139-286792 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a macro to check whether an address is within module's text. Signed-off-by: Christophe Leroy --- include/linux/module.h | 13 +++++++++++++ kernel/module.c | 17 +++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index 33b4db8f5ca5..fc7adb110a81 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -570,6 +570,19 @@ static inline bool within_range(unsigned long addr, void *base, unsigned int siz return addr >= (unsigned long)base && addr < (unsigned long)base + size; } +static inline bool within_module_layout_text(unsigned long addr, + const struct module_layout *layout) +{ + return within_range(addr, layout->base, layout->text_size); +} + +static inline bool within_module_text(unsigned long addr, + const struct module *mod) +{ + return within_module_layout_text(addr, &mod->core_layout) || + within_module_layout_text(addr, &mod->init_layout); +} + static inline bool within_module_layout(unsigned long addr, const struct module_layout *layout) { diff --git a/kernel/module.c b/kernel/module.c index 84a9141a5e15..201d27643c84 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -4224,11 +4224,6 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags) return load_module(&info, uargs, flags); } -static inline int within(unsigned long addr, void *start, unsigned long size) -{ - return ((void *)addr >= start && (void *)addr < start + size); -} - #ifdef CONFIG_KALLSYMS /* * This ignores the intensely annoying "mapping symbols" found @@ -4765,13 +4760,11 @@ bool is_module_text_address(unsigned long addr) struct module *__module_text_address(unsigned long addr) { struct module *mod = __module_address(addr); - if (mod) { - /* Make sure it's within the text section. */ - if (!within(addr, mod->init_layout.base, mod->init_layout.text_size) - && !within(addr, mod->core_layout.base, mod->core_layout.text_size)) - mod = NULL; - } - return mod; + + if (mod && within_module_text(addr, mod)) + return mod; + + return NULL; } /* Don't grab lock, we're oopsing. */