Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp57092rwe; Thu, 13 Apr 2023 22:09:58 -0700 (PDT) X-Google-Smtp-Source: AKy350YregtLtvY/kmi04iJJWk3KEZ7q5TFtUECu3Y2qZZUQrB83T9Evcf8V18W4YWfo8OYPx+FK X-Received: by 2002:a17:90a:4586:b0:23f:9925:6f8b with SMTP id v6-20020a17090a458600b0023f99256f8bmr4192781pjg.17.1681448998304; Thu, 13 Apr 2023 22:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681448998; cv=none; d=google.com; s=arc-20160816; b=pcOzNyYGTnnsTb/to0GFAKUT7wMLjR0Osg2rfSZj+wehRfzMuivpgzbDujN3nvT4NC nhSJadAvrsJjYQaJdqyY3SAMLO8Gu01XbMZz0X3abHV8pGbYOueICaZqtdQiCDqe3GKF 9V4kAA+BUlnYRSjx5iub9X12Z73wT5UiD48zqdfnllfYSyycqqzxZy4IS55DfKgLkNqZ Ui9tMkWAranq+jb1x6rXl9CuSMThyoo3R2JpaG6aXlRw5/LYpyJNPl/suSB0vkODrWJm erHMC5FxbVqWzG/u9jaoAuaUk0yHtm+FrJZ3d/5Hi0qvigHWE7f0w+gSbpySbF8oWu6F Ao3g== 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=d1P4Lb2k3WvTKxpPWQ0Fgfk0BiJfkVHvlpVmM1zJ91o=; b=xGkF3OlkC2j7c7/uxKB8nFsoG2Q/GEDlyuxTEa5XBiPB23oK2jvIxM4HUvCaKP74r2 +KmE0rTF9YwZJXzA3RxJaROcd6A8/vWERDU2TcBFx/pPkwMyhRZngHAYQcIlrG5Ww51+ iPkMNZFiG9TfJc2nPR33wxK3h9xjpdosN2y7ovx4KLN/tJSFzugVvbxW6NVDGWBK71Wc iTUgWYSsNpMQFlBq9D1OaMUFWo0AYdwThn4JvWxTT+k1/V+0sdMtGL+WsflyJbQRMVmu LeEcXgBafNhCJCixwbf2KWYEK2feqHy6eAg68sMNDwllg5GEWAzSkwwpz9gu+zYtbtCN JmIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=DqwnBtWG; 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 w16-20020a170902e89000b001a51bb4ad79si4126161plg.42.2023.04.13.22.09.46; Thu, 13 Apr 2023 22:09:58 -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=DqwnBtWG; 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 S229791AbjDNFIx (ORCPT + 99 others); Fri, 14 Apr 2023 01:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjDNFIt (ORCPT ); Fri, 14 Apr 2023 01:08:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319D244A8; Thu, 13 Apr 2023 22:08:46 -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=d1P4Lb2k3WvTKxpPWQ0Fgfk0BiJfkVHvlpVmM1zJ91o=; b=DqwnBtWGV0bKq17zOTApZ3Ty3T udPqRDkRW1Jw8aPmWRpjpvoUlYqek3ute8vM6VwL9HTtizN7T8xk5JEKTWEwszDrd6Ea0xRhixqIe lSOkfft0VtkvePiEiL6sb0gtU+Mq4EzfC2g3HaoX9ze0a5otbhjpdGeWXTMPTCtk39do+8hqGXvZ8 F4yu9B9GVNuQ0BqNTuxMdqZR6c2G/outr+fojM2z8JW+Nomy8VaHsZSkYBaujlaFpisBQPscw9sXm GKroLOlcDoKPwao7uq/9cPdYuPDIVREaqhWIOf/tE869yP7hbUcM10hHP9xfzJZNY8yupugCJc/UL HZ8rZI0g==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pnBfp-008KKH-1R; Fri, 14 Apr 2023 05:08:37 +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 v3 1/4] module: fix kmemleak annotations for non init ELF sections Date: Thu, 13 Apr 2023 22:08:33 -0700 Message-Id: <20230414050836.1984746-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230414050836.1984746-1-mcgrof@kernel.org> References: <20230414050836.1984746-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 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. Contrary to the old way of using kmemleak_ignore() for init.* ELF sections we stick now only to kmemleak_not_leak() as per suggestion by Catalin Marinas so to avoid any false positives and simplify the code. Fixes: ac3b43283923 ("module: replace module_layout with module_memory") Reported-by: Jim Cromie Acked-by: Song Liu Suggested-by: Catalin Marinas Signed-off-by: Luis Chamberlain --- kernel/module/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kernel/module/main.c b/kernel/module/main.c index 5cc21083af04..32554d8a5791 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -2231,13 +2231,18 @@ static int move_module(struct module *mod, struct load_info *info) } mod->mem[type].size = PAGE_ALIGN(mod->mem[type].size); 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 *could* treat them + * slightly differently with kmemleak_ignore() and only grey + * them out as they work as typical memory allocations which + * *do* eventually get freed, but let's just keep things simple + * and avoid *any* false positives. */ - kmemleak_ignore(ptr); + kmemleak_not_leak(ptr); if (!ptr) { t = type; goto out_enomem; -- 2.39.2