From patchwork Wed Apr 5 02:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13201113 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 512FAC6FD1D for ; Wed, 5 Apr 2023 02:27:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2FA06B0080; Tue, 4 Apr 2023 22:27:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE2326B007E; Tue, 4 Apr 2023 22:27:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5FD36B0082; Tue, 4 Apr 2023 22:27:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 94D5F6B007E for ; Tue, 4 Apr 2023 22:27:20 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7103DAC536 for ; Wed, 5 Apr 2023 02:27:20 +0000 (UTC) X-FDA: 80645750640.02.4EE058E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf14.hostedemail.com (Postfix) with ESMTP id CE8FC10000C for ; Wed, 5 Apr 2023 02:27:18 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UjurHh14; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf14.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680661638; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/zFMu+hCUyA4Z/2f84k8anH54tplY3/TfwT6JNMhL7g=; b=If2MSp4T/X50Obyh4YIwPzUKjcW8VjA3/sTI7owPX/tpRcbhKX59cjC5X8hfMkx4s9q0++ X6F7cLRG99yRjZ3BtGadKYTnyE2pjdDJOtrts9kuhaFFmF7Dpk8rke56sg4QlzfsBJw29Z eIMcyk/D02Rn7LkmCwF/kPf1+jbl7nI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UjurHh14; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf14.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680661638; a=rsa-sha256; cv=none; b=HWOv+v+yAoRTSBCqzAB6HancEwY7FTzC3DjIzwNrN23GNJ1s5Ouhrid/yd22Mg7wyV7xab bxyIDxEfHDiRx4wHT6KPhgdB87esaUii/V5OGXy8YZ1gX1/mXpSe4K7tEzcTvWwWCdFm2A BOs+xxykfi0YhjV3rDrgIzR5pfsB1II= 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CE8FC10000C X-Stat-Signature: 8px197fuwbczuxf9ga8rgnrgx4jzzidm X-HE-Tag: 1680661638-5268 X-HE-Meta: U2FsdGVkX19DfQcvvUoGrrgeKkjFjI8wD7DO/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vynksv63WzA12juwubJ7vDZqlftEkJ/o1purArwcPbCfhUgSx3SGcqWeE5Xzt+CMoAe80+Xh6+wFblf1wKzw7uXAaKJ4lxKVTiDhcCDAGPSPcBqL1/qZylzovT43aO4peUZRXzgaXPcmVX5gNLLN8XvxDMg76jTf9vePJkcVjsjc20FY80zZhM5bfaQWLaasnwn1dTvBVILuKkbkpknLcIs09z9vifROS8fPBRJaGlgifSxSHlziQOuLpO7xr3fztOZqERZN1L9a3JkEfOGMALCcej8w2HlHSpfjZwJAd/QYamnvQZB8u/BGYWxrtchyB1lreXB6Djttl/5JfFATpCC39y87NoiQSlNNW8ytzAsyyiZAY7I0IO5V+nfkc7LE 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: 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 Acked-by: Song Liu --- 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;