Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2059906pxb; Wed, 9 Feb 2022 10:02:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIwAKfutklVZjGPw8NDscGnGgkudp5btbzvJNV9hIl0F3zqwpsTocCXVE+mzPUtQzAQhJn X-Received: by 2002:a17:907:6283:: with SMTP id nd3mr3039590ejc.2.1644429769319; Wed, 09 Feb 2022 10:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644429769; cv=none; d=google.com; s=arc-20160816; b=YL/OAjdRpmWQari5zr34OirZDDweYgU8QYYvCb5Vq66GI9++lXLe5WK6gHHib2yEjI xbcLA5heXg+hQLu9I1TV7q0LYD6ZYRc0tEYsgLNqpfhEuyPOYe8S1gV9Ozy64VVFpheu onZn1lKjO9FSrf83ccRD5IUcOw0yIy4F9BtU3TEU7hzRFnHYFlKYrUP2hGWgwyk+3kpX FIBlFa5QripWTTcRGeRu6HYah/v9Ai9JRk7/R+POU6rnF2f9UGd5zpi+H36dM60QJxzD uYuRxFKLVvZ7UvpIMY38d1X9yqlWhbqs/fOqn2KaVKFThzC2s6INCNS6JNRXQdUjxzBb QXzQ== 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:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QA83dhan4GHrbc3Y3AatV9qxaqVqba7enDqgKUIKf/o=; b=fGjJxYvREVmqieIgxCfh+pSxPKlX6uh8JEcshkd6aWbSj66zX4BNAWqzYrVciF55PZ o92CUIG9Cmk3ipJwqIx/P17lRH7qHoF+3hn68LgpFf1Lg0xhRQt9B4ELxUmGh7MsaaLv sBn+pWP6UqzLgrKW9NqEoApl+n18gVnwgaN/N2NtyMLZAnU0Cu6zYAowADXPbLy34GQw MZbRm5U402OvoTU+BrMMuIC8SHNwaWky5nqrt2uO1+XS0PZO+9nkkaS8IgmEi8Qv5HBe LfyecLlsfRYaHLzvKnyYPFL5szyNciFPUtadiQZPpn4IXVjDqLonv7AxL2ODxWE6WPrq avcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ew23Nezn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qf5si11430208ejc.141.2022.02.09.10.02.21; Wed, 09 Feb 2022 10:02:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ew23Nezn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237894AbiBIRIW (ORCPT + 99 others); Wed, 9 Feb 2022 12:08:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236682AbiBIRIQ (ORCPT ); Wed, 9 Feb 2022 12:08:16 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE118C05CB87 for ; Wed, 9 Feb 2022 09:08:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644426499; h=from:from:reply-to: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=QA83dhan4GHrbc3Y3AatV9qxaqVqba7enDqgKUIKf/o=; b=Ew23NeznqX5//1pfUOFLZycqK4ziZsAdVvGzPcDS4ZWwnuZzV7OvGPrfa9gHb5+JEAwVAX U3+b8YSMWOwY+vaYL/UutAk4DrGgoyFXp6RBBoEt+HTMGs/DT61jvu5E2GyGI7L9A1pmi0 UrudF7r/9J8Yw78bLSmppOBmpp8YNU0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-TvCwzrWOP26-sQJvU_vCUQ-1; Wed, 09 Feb 2022 12:08:18 -0500 X-MC-Unique: TvCwzrWOP26-sQJvU_vCUQ-1 Received: by mail-wm1-f70.google.com with SMTP id bg32-20020a05600c3ca000b00349f2aca1beso732784wmb.9 for ; Wed, 09 Feb 2022 09:08:17 -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:reply-to:mime-version:content-transfer-encoding; bh=QA83dhan4GHrbc3Y3AatV9qxaqVqba7enDqgKUIKf/o=; b=uU5uU7SGMr1yrpBcZDtVFET3eOg+eaetcFWDTRw28QFasQBuE2OWhtsv8pPA0FM6ou HsMUunT/CLa7T+8XpbN8Kzv39FuwMUUoBN/edrVwtY3rTSyiZVKWryFJIXiWvV8dDJ/d Ckx1SC/5CAwmUa01OwlbdYga8mbuLQxN9HlWtOuBnkolMjymdhNJ3DdKmlQUbgiBznrp srxi3KVRcfXI0y0ldLtGxmKYXibRyRWHkD3UY3AxEPX5mtppVnLMAypsWK72Y/hnF+rl vJ4sulQchvMaYXh9gBi2+Adk1ZFxUy/WoJ5rRuiTmqwjwLqFlav+BJyfN5THwPZjOVOx MC7w== X-Gm-Message-State: AOAM533w4DpV/ePE+L7p1u/AR1JXxjgYonQCOA/RreEBRbN/RSiO7sbG enIq1TOOajmEddL9P1evkoeoa7+5D58EgNzJiNDhdxeMuwErI5u7zeqN1lWfhmw2oEMZgE6ROQq GGIS7WWWuiZWY4B8XIu15bmE= X-Received: by 2002:a05:6000:128d:: with SMTP id f13mr2740925wrx.675.1644426496685; Wed, 09 Feb 2022 09:08:16 -0800 (PST) X-Received: by 2002:a05:6000:128d:: with SMTP id f13mr2740907wrx.675.1644426496477; Wed, 09 Feb 2022 09:08:16 -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 j35sm1155960wms.32.2022.02.09.09.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 09:08:15 -0800 (PST) From: Aaron Tomlin To: mcgrof@kernel.org Cc: cl@linux.com, pmladek@suse.com, mbenes@suse.cz, akpm@linux-foundation.org, jeyu@kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, live-patching@vger.kernel.org, atomlin@atomlin.com, ghalat@redhat.com, allen.lkml@gmail.com, void@manifault.com, joe@perches.com, christophe.leroy@csgroup.eu, msuchanek@suse.de, oleksandr@natalenko.name Subject: [PATCH v5 08/13] module: Move kmemleak support to a separate file Date: Wed, 9 Feb 2022 17:08:09 +0000 Message-Id: <20220209170814.3268487-2-atomlin@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209170814.3268487-1-atomlin@redhat.com> References: <20220209170814.3268487-1-atomlin@redhat.com> Reply-To: 20220209170358.3266629-1-atomlin@redhat.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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 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 8f2857d9ba1e..62c9fc91d411 100644 --- a/kernel/module/Makefile +++ b/kernel/module/Makefile @@ -11,4 +11,5 @@ ifdef CONFIG_MODULES 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 endif diff --git a/kernel/module/debug_kmemleak.c b/kernel/module/debug_kmemleak.c new file mode 100644 index 000000000000..e896c2268011 --- /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 6d5891cc8421..33d7befd0602 100644 --- a/kernel/module/internal.h +++ b/kernel/module/internal.h @@ -171,3 +171,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 __maybe_unused 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 403f2aacb3f6..c9931479e2eb 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2515,33 +2515,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