Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp85608rwl; Tue, 4 Apr 2023 19:28:05 -0700 (PDT) X-Google-Smtp-Source: AKy350Yls0ZLA2bNiAmRMwGrryTU/VEVrPivNcUdWgFXDZroqk3An0gaS3LWozmUvPY5ECZuousX X-Received: by 2002:a17:906:81d3:b0:930:2e3c:c6aa with SMTP id e19-20020a17090681d300b009302e3cc6aamr1395591ejx.49.1680661685568; Tue, 04 Apr 2023 19:28:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680661685; cv=none; d=google.com; s=arc-20160816; b=voqFv+51u73Wh+Lhxj/ShNliN0Q8fs+atQFN/aAJe6RlKP9seKzKeVhCSPmpo85apO ooT+efsykXvUFWHCgGBcy/gHpfUfDBALNCVOeb8gG6iWOu7vLlbphQeCjxz/z1U1YWln lkB1t7pCPtI7CRUEoITCIfcxrrBqY4bbJs+Qg+JriP+8Bc+2G7dpQZ5Z0JerVGr+6lbG 91ERBo3BamWRB2WzOkbe3+xjDHDo6MIYX4ELSQLag1dy7FVGxgL8MP4tDR9j4Eer8zwe +IFPWcGykq1PXwqOwALz57Nx3F/rkBQn7B2gYPNyyoKepk3TEeHv2WbmF7nhXAm+RxdZ tBoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/zFMu+hCUyA4Z/2f84k8anH54tplY3/TfwT6JNMhL7g=; b=wiN9o8dloJbt6AXhn2coyCJpRXaSfpx/e7gUyoFx/kYyrzrGP3nUyhYT+yjJkS8rPu Brz5O+kMXScP0Faoy8Dg+sX4UzU33wPNBO19ob9mBFEim2NwTKFfunKNxpjtOR+mK1kR t3zaoRUAb7zABWzzxOCYUWQPG1gbl58D+8j0nRMYYRVEMsIygQlbdFX5Q2tsBujkhIFb LC1vqWpHSAfmoO9MDXUP7gCxd/IQpg6POIVKgFDAFSW9gU5oN/5/RYMeZIQGWOY4kvt0 9m5Wt0a+uTYi+H1N00cYteG/cIjlaOllR9ppDfvV+DZAdhHnIhnb04FD+1aIQmVpwXkf Aq+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=UjurHh14; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170906850600b00947704bc041si10639385ejx.14.2023.04.04.19.27.40; Tue, 04 Apr 2023 19:28:05 -0700 (PDT) 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=@infradead.org header.s=bombadil.20210309 header.b=UjurHh14; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236759AbjDEC1X (ORCPT + 99 others); Tue, 4 Apr 2023 22:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjDEC1Q (ORCPT ); Tue, 4 Apr 2023 22:27:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A668F2697; Tue, 4 Apr 2023 19:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=/zFMu+hCUyA4Z/2f84k8anH54tplY3/TfwT6JNMhL7g=; b=UjurHh14lS41LO3RhiYhdywUTf UEGL5ucwoWlBmR4Hh56vx44CPgIURTZMI+Sr8oPTudV3S1Fcxp4zufGjiC43e1ePkCMeBV+l4AuMR /+HFs3mc3aVXV+s66JFe+6Q3nYSF9IF1M+BCuEkQKFBiioYOWtcRJoNb48oOOKVL1vyQ/p9WNnNGT M1J7y9MPKOwQFj8/Ye23sAKx2zZsk+zHocAPyVlq99hFg8XUnbHmBDmqfPWdZIwMpN6ewNhd05eox KXhCOHRNjv2ytJo4Vf9IuwS/F8EH6fnRFtdknAq6LH8q7YYuzEuerM5aoWv6Vlxk+d6vKujoj8nKh vMShxgIA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pjsrb-003A05-1W; Wed, 05 Apr 2023 02:27:07 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, dave@stgolabs.net, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, colin.i.king@gmail.com, jim.cromie@gmail.com, catalin.marinas@arm.com, jbaron@akamai.com, rick.p.edgecombe@intel.com, mcgrof@kernel.org Subject: [PATCH v2 1/6] module: fix kmemleak annotations for non init ELF sections Date: Tue, 4 Apr 2023 19:26:57 -0700 Message-Id: <20230405022702.753323-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230405022702.753323-1-mcgrof@kernel.org> References: <20230405022702.753323-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain X-Spam-Status: No, score=-2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Commit ac3b43283923 ("module: replace module_layout with module_memory") reworked the way to handle memory allocations to make it clearer. But it lost in translation how we handled kmemleak_ignore() or kmemleak_not_leak() for different ELF sections. Fix this and clarify the comments a bit more. Fixes: ac3b43283923 ("module: replace module_layout with module_memory") Reported-by: Jim Cromie Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5cc21083af04..d8bb23fa6989 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2233,11 +2233,23 @@ static int move_module(struct module *mod, struct load_info *info) ptr = module_memory_alloc(mod->mem[type].size, type); /* - * The pointer to this block is stored in the module structure - * which is inside the block. Just mark it as not being a - * leak. + * The pointer to these blocks of memory are stored on the module + * structure and we keep that around so long as the module is + * around. We only free that memory when we unload the module. + * Just mark them as not being a leak then. The .init* ELF + * sections *do* get freed after boot so we treat them slightly + * differently and only grey them out -- they work as typical + * memory allocations which *do* eventually get freed. */ - kmemleak_ignore(ptr); + switch (type) { + case MOD_INIT_TEXT: /* fallthrough */ + case MOD_INIT_DATA: /* fallthrough */ + case MOD_INIT_RODATA: /* fallthrough */ + kmemleak_ignore(ptr); + break; + default: + kmemleak_not_leak(ptr); + } if (!ptr) { t = type; goto out_enomem; -- 2.39.2