Received: by 2002:ac2:48a3:0:0:0:0:0 with SMTP id u3csp5330lfg; Thu, 10 Mar 2022 20:50:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyFGY619hzFczZuoHgXDl7unHYjKS5to2LtAb08UfV5vXYILVkU6yDG2kVEBF3wiVkubCkl X-Received: by 2002:aa7:ce1a:0:b0:416:460:9df5 with SMTP id d26-20020aa7ce1a000000b0041604609df5mr7123762edv.277.1646974253617; Thu, 10 Mar 2022 20:50:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646974253; cv=none; d=google.com; s=arc-20160816; b=M/zJtKBTd9+FYEV40Y4JBgv/h+xMk4RNYTPPKeaCFyzfrpWIY37uowTdZvV21J3lul pjPy/9sBhIZjcG4qikEYxQCbtW+cU8EgGmISpWkOdcrbGr3o5A/hm/LdNTdIivb/W19M ao0OU8qWSuzi2h5UofFLaxPHfFIiQf/YsKknqFGUCaKitPtycWUA+b1gTBseUfFbTCJR KynRNwUXx1s48RUsAfDgQuLejjM55FyZv8u7Daa9XtHmn69Ua6JtDHJGA+9DfpqZAnDM MIGcFvdecTIF+b1WI+IC9twANQYK3fgp+dQf8gH2m5tI/VA34PH7tM2ByblahV7ZkPGs Na9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EwM5m/UKCLcQUodhjTTwfqA0OAG1WbMnIR0FKcI9qsQ=; b=lJJ67sp33GN5003zpXn/CWKDH4KSrFZxmyNJbycUDpIGaNT70muez9uH4OkABS2r3r RQOf1o2boKO0uClN/XpRm2c/rjtC9vGJXSUV8lxS876KhNclJdM7FVyDjClFLAN+3gqR 2v2WgXjx57ZUsYOFaw11ll9K4plpaFgPdCLTi/zktpwjXIlkg6i/FrbE62ZYNlY0FFK0 HnP5yNDoEGr2EbOuUT5ZG0dgqb2fWT1V4d2ZubxtB+XF012S4dyvFtRqPCNn7EW1Xfea TxjhDEyPds3Wn6tDReU8jFneXsclmxGabRyTpczNbYbU60mVUNO536BRNXc67k7XCAC6 gdpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZkZch8Dd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm12-20020a170907948c00b006db0ae1b4f4si5068997ejc.839.2022.03.10.20.50.30; Thu, 10 Mar 2022 20:50:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZkZch8Dd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241284AbiCJK0D (ORCPT + 99 others); Thu, 10 Mar 2022 05:26:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241273AbiCJKZu (ORCPT ); Thu, 10 Mar 2022 05:25:50 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7761513EFAF for ; Thu, 10 Mar 2022 02:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646907876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EwM5m/UKCLcQUodhjTTwfqA0OAG1WbMnIR0FKcI9qsQ=; b=ZkZch8Dd6jn5g+SaDUYd2hB8rrj/dVdQh7FpjJf8FA31cvSRoKVVwWFkEME4NI4f+flV05 MWUv5eM11aClVWFxM+5RTs5J+QJbN+jafC5kCG4rhbneW4vwLEUBz8DcYC0UOsNDzKqzp6 tada2hMUyGf7fyBGc041lVwX0UlYPgQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-XQZYcvQoNuGuFNiL93DyuA-1; Thu, 10 Mar 2022 05:24:34 -0500 X-MC-Unique: XQZYcvQoNuGuFNiL93DyuA-1 Received: by mail-wm1-f72.google.com with SMTP id 3-20020a05600c230300b00384e15ceae4so3877704wmo.7 for ; Thu, 10 Mar 2022 02:24:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EwM5m/UKCLcQUodhjTTwfqA0OAG1WbMnIR0FKcI9qsQ=; b=rUOj3tlt3ddK6MfhlC/sThqHh4uWsxVIIlV8RvE0i+sUniVzDFBcBo+ISu5QcsiJX4 PfWVALh5IEcDmabEjsHrRJZAYUaWe+MaYWSaw/mFN7cuiHMmjvZfpLDkErbk9DAIhdNU /EvuktbvIS0j04a9lQDZmpbW5jaswRVkSc7X3AwDVjoZ5PmMF/3WJjtD9SiIaNNTZZgz xI/P+jh1lK37cKLG9YwsNT4M/yo7cgHXgmf6KF3pUJSccS6+a4bEDfCBkmZJUF0enCF9 Xlw5JBX6nAScYPokKSKVx7k6F8QSotrkG0YS0mbSefiHx631bFWMk25lNNeYynjcN/2Q iHiQ== X-Gm-Message-State: AOAM531306zUF8ARaA82ahOU965aMDBbQVeTZeDut/OhoVNu8/aqR5Fm rlW+yxmuJ2qcMOS9G+H4EBk9ThlbArRqhkyc0Idpff6HOPoI87WWgyU1sIhZ1dVe8XptEDhKIW1 ah4ExPr77E5BDtlB4nz1I+dw= X-Received: by 2002:a05:600c:4142:b0:389:a592:10ce with SMTP id h2-20020a05600c414200b00389a59210cemr3042011wmm.148.1646907873691; Thu, 10 Mar 2022 02:24:33 -0800 (PST) X-Received: by 2002:a05:600c:4142:b0:389:a592:10ce with SMTP id h2-20020a05600c414200b00389a59210cemr3041986wmm.148.1646907873507; Thu, 10 Mar 2022 02:24:33 -0800 (PST) Received: from localhost (cpc111743-lutn13-2-0-cust979.9-3.cable.virginm.net. [82.17.115.212]) by smtp.gmail.com with ESMTPSA id h12-20020a5d548c000000b001f1f99e7792sm3696411wrv.111.2022.03.10.02.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 02:24:32 -0800 (PST) From: Aaron Tomlin To: mcgrof@kernel.org, christophe.leroy@csgroup.eu Cc: cl@linux.com, mbenes@suse.cz, akpm@linux-foundation.org, jeyu@kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, void@manifault.com, atomlin@atomlin.com, allen.lkml@gmail.com, joe@perches.com, msuchanek@suse.de, oleksandr@natalenko.name, jason.wessel@windriver.com, pmladek@suse.com, daniel.thompson@linaro.org, hch@infradead.org Subject: [PATCH v11 08/14] module: Move kmemleak support to a separate file Date: Thu, 10 Mar 2022 10:24:07 +0000 Message-Id: <20220310102413.3438665-9-atomlin@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220310102413.3438665-1-atomlin@redhat.com> References: <20220310102413.3438665-1-atomlin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No functional change. This patch migrates kmemleak code out of core module code into kernel/module/debug_kmemleak.c Reviewed-by: Christophe Leroy Signed-off-by: Aaron Tomlin --- kernel/module/Makefile | 1 + kernel/module/debug_kmemleak.c | 30 ++++++++++++++++++++++++++++++ kernel/module/internal.h | 7 +++++++ kernel/module/main.c | 27 --------------------------- 4 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 kernel/module/debug_kmemleak.c diff --git a/kernel/module/Makefile b/kernel/module/Makefile index d313c8472cb3..12388627725c 100644 --- a/kernel/module/Makefile +++ b/kernel/module/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_MODULE_SIG) += signing.o obj-$(CONFIG_LIVEPATCH) += livepatch.o obj-$(CONFIG_MODULES_TREE_LOOKUP) += tree_lookup.o obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o +obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o diff --git a/kernel/module/debug_kmemleak.c b/kernel/module/debug_kmemleak.c new file mode 100644 index 000000000000..12a569d361e8 --- /dev/null +++ b/kernel/module/debug_kmemleak.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Module kmemleak support + * + * Copyright (C) 2009 Catalin Marinas + */ + +#include +#include +#include "internal.h" + +void kmemleak_load_module(const struct module *mod, + const struct load_info *info) +{ + unsigned int i; + + /* only scan the sections containing data */ + kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); + + for (i = 1; i < info->hdr->e_shnum; i++) { + /* Scan all writable sections that's not executable */ + if (!(info->sechdrs[i].sh_flags & SHF_ALLOC) || + !(info->sechdrs[i].sh_flags & SHF_WRITE) || + (info->sechdrs[i].sh_flags & SHF_EXECINSTR)) + continue; + + kmemleak_scan_area((void *)info->sechdrs[i].sh_addr, + info->sechdrs[i].sh_size, GFP_KERNEL); + } +} diff --git a/kernel/module/internal.h b/kernel/module/internal.h index d6f646a5da41..b0c360839f63 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -167,3 +167,10 @@ static inline int module_sig_check(struct load_info *info, int flags) return 0; } #endif /* !CONFIG_MODULE_SIG */ + +#ifdef CONFIG_DEBUG_KMEMLEAK +void kmemleak_load_module(const struct module *mod, const struct load_info *info); +#else /* !CONFIG_DEBUG_KMEMLEAK */ +static inline void kmemleak_load_module(const struct module *mod, + const struct load_info *info) { } +#endif /* CONFIG_DEBUG_KMEMLEAK */ diff --git a/kernel/module/main.c b/kernel/module/main.c index c63e10c61694..7dd283959c5c 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2519,33 +2519,6 @@ 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) -{ - unsigned int i; - - /* only scan the sections containing data */ - kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); - - for (i = 1; i < info->hdr->e_shnum; i++) { - /* Scan all writable sections that's not executable */ - if (!(info->sechdrs[i].sh_flags & SHF_ALLOC) || - !(info->sechdrs[i].sh_flags & SHF_WRITE) || - (info->sechdrs[i].sh_flags & SHF_EXECINSTR)) - continue; - - kmemleak_scan_area((void *)info->sechdrs[i].sh_addr, - info->sechdrs[i].sh_size, GFP_KERNEL); - } -} -#else -static inline void kmemleak_load_module(const struct module *mod, - const struct load_info *info) -{ -} -#endif - static int validate_section_offset(struct load_info *info, Elf_Shdr *shdr) { #if defined(CONFIG_64BIT) -- 2.34.1