Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3282810pxm; Mon, 28 Feb 2022 16:24:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCopRpC+OHNkAE91JWVDJJLUOpKGWduCVRRiJ1ROt5CtoY50otBkLyWKjZTO7WExI56NvG X-Received: by 2002:a63:4f48:0:b0:378:a293:11f3 with SMTP id p8-20020a634f48000000b00378a29311f3mr6465188pgl.99.1646094299250; Mon, 28 Feb 2022 16:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646094299; cv=none; d=google.com; s=arc-20160816; b=erBIxLeOr8g5YZmHQkSwyzvN99XlkiCzaleIFEKIHvCF5N6w4lzbxa4GTn8SN/OHBg O1zEm9IpqenZZJTK0ixEAsPT4mmJg7v79iV+rC091lCPI32K736+l+aPHGA32q17uHzg rmsQ1I7C8DxBLqlbDLSmWX20VtFgm0D3nV2ZB0qHM6qKG9ZE6vjKbV9nhz1dZfkyEIRQ fm5SkG1NLy3/saKSdb3CadEJ+WWe90pMjbSf1lOnVfyYPtAEqbX7gtr0JfwQVf/KsCfO lUKc3zmHU5yGdDB/MN3DSvCqchNAbAddEICEne4jFBMOCpv5EkdNKghxsvT4XiJvnGwh 9p7A== 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=P3bgNzeY4NTUrhICb1GBtH9i7ydzusNTVDgKVMH+36Zv1YD/k4fpR9pLPMuHpwrjts 2mVaAXvFrtceSgr7dzEebgTqkjMVM1QOz7SXE4Tbm5U4I6XEZ6g5ovN7WH60DSrUycWC X5UwKprhBZrCr13dAWuSphKUOo5xvx0MeXZnpopIM1qWpouZdo0vE67xvn3zkcbiyfEg qJAjNj3K6dolXbpTsZFMAxqU1ACI+5kRrG4zK0nda4kP8G/pokxhaINBUIMstu1b2s/l +ZfSucg7t+IHaaCqEyuDw/xvR8/8z15lwI4sO989u/bFQX2iU3YLETJWDaMWd2Hi9wg0 fUOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zk7Fh6DY; 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 a13-20020a65604d000000b00372cab4e40csi11006516pgp.700.2022.02.28.16.24.32; Mon, 28 Feb 2022 16:24:59 -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=Zk7Fh6DY; 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 S231732AbiB1Xo6 (ORCPT + 99 others); Mon, 28 Feb 2022 18:44:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231700AbiB1Xof (ORCPT ); Mon, 28 Feb 2022 18:44:35 -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 BBA7DF65DC for ; Mon, 28 Feb 2022 15:43:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646091824; 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=Zk7Fh6DY9h6kQ0iGCvQBK6bEPnZaOmNSWOq9kpYVenB8+QqyiywrtrVnqeZk09nLKQDT59 OSqHvipoHDYXUMq1pgsuJUxL7BxfzmrolrEnMq8wumMOnXS8+PunzfEgJKnA9YgZoACW4r hq3ASQ3uFrDHfpX6PFvYekYZZ5lfIO0= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-Gc9lOMr_OAGj7IuAEaZC5g-1; Mon, 28 Feb 2022 18:43:43 -0500 X-MC-Unique: Gc9lOMr_OAGj7IuAEaZC5g-1 Received: by mail-wm1-f69.google.com with SMTP id 10-20020a1c020a000000b0037fae68fcc2so314651wmc.8 for ; Mon, 28 Feb 2022 15:43:43 -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=a7CXGJqK2HqBxFswRqFwxn7o0Lz8PNOU7TaiAMmOAsa1o3D5uhGxCYXygKaYBB8/MK 9z/ALM1RwY3MNTg9UBj+AaeNKysMv2b1U805twCrtg2N2RAA8lOuqppiPOgdukhknP6j 2VJaz2HVNVyjkioQRkWkWuHPrL3Ny+CvGW1xDR4BNkzGoPkshkViT0+w/aJTelo1Vavf BNnH4qhtWa27Y6KI5eaV46LoSFXgnzBT1YN2EbPy4Y7uMoC0lnJuExmMC0d6kWtyAnHt 5wtyO0cHCG+oW98YXz+Scqq0PmWnS4nJ5pV09kNYxkbrH2caV09bFd1vwaz4NQt3kWmo chGw== X-Gm-Message-State: AOAM532ifnBwdf3V0bV0UXu6QfoVtBahOTfTOPHbU4APe74ZPFOcVYLB ibP7kvr3Liju6s9ANnjXU4TtsQTFpRiC4sO+RSdyAAa9Yi+JoVWNB2QEnJ/yWP9Q8xqv6+fjyDd CD1SLBabKGdxwnou4jQCKuK8= X-Received: by 2002:a1c:f018:0:b0:37b:c13c:3128 with SMTP id a24-20020a1cf018000000b0037bc13c3128mr15097537wmb.157.1646091822460; Mon, 28 Feb 2022 15:43:42 -0800 (PST) X-Received: by 2002:a1c:f018:0:b0:37b:c13c:3128 with SMTP id a24-20020a1cf018000000b0037bc13c3128mr15097522wmb.157.1646091822292; Mon, 28 Feb 2022 15:43:42 -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 z3-20020a1cf403000000b0037d1f4a2201sm782025wma.21.2022.02.28.15.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:43:41 -0800 (PST) From: Aaron Tomlin To: mcgrof@kernel.org, christophe.leroy@csgroup.eu, pmladek@suse.com 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, daniel.thompson@linaro.org Subject: [PATCH v9 08/14] module: Move kmemleak support to a separate file Date: Mon, 28 Feb 2022 23:43:16 +0000 Message-Id: <20220228234322.2073104-9-atomlin@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220228234322.2073104-1-atomlin@redhat.com> References: <20220228234322.2073104-1-atomlin@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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