From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 932BBC6379D for ; Wed, 25 Nov 2020 07:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E91D206D9 for ; Wed, 25 Nov 2020 07:53:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="V8hV5Vl+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbgKYHxT (ORCPT ); Wed, 25 Nov 2020 02:53:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:53944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726407AbgKYHxT (ORCPT ); Wed, 25 Nov 2020 02:53:19 -0500 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBF4220857; Wed, 25 Nov 2020 07:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606290798; bh=zWaKhFGSMXCY/b+jLfMpt5Moxe0TRFeN///Em3HdlxU=; h=From:To:Cc:Subject:Date:From; b=V8hV5Vl+Gli0KSdSNUhK6CZIIdYDilT16Qu8EzxfiLLpwdnm59umKi3DZ0OdMHGd7 8TJ5bzp2mYeqtXXN8KJBgIvCo/pB7r2cJ5CflRGpLTd60FSXMk+4cwUBqBdZCE4mGL O20VL2EYfg/qhNmlsQ9V5U7WfoXF74wFJFlkIgWM= From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: oleksandr@natalenko.name, jk@ozlabs.org, mjg59@google.com, David.Laight@aculab.com, Ard Biesheuvel , Vamshi K Sthambamkadi Subject: [PATCH] efivarfs: revert "fix memory leak in efivarfs_create()" Date: Wed, 25 Nov 2020 08:53:03 +0100 Message-Id: <20201125075303.3963-1-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The memory leak addressed by commit fe5186cf12e3 is a false positive: all allocations are recorded in a linked list, and freed when the filesystem is unmounted. This leads to double frees, and as reported by David, leads to crashes if SLUB is configured to self destruct when double frees occur. So drop the redundant kfree() again, and instead, mark the offending pointer variable so the allocation is ignored by kmemleak. Cc: Vamshi K Sthambamkadi Fixes: fe5186cf12e3 ("efivarfs: fix memory leak in efivarfs_create()") Reported-by: David Laight Signed-off-by: Ard Biesheuvel --- fs/efivarfs/inode.c | 1 + fs/efivarfs/super.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c index 96c0c86f3fff..38324427a2b3 100644 --- a/fs/efivarfs/inode.c +++ b/fs/efivarfs/inode.c @@ -103,6 +103,7 @@ static int efivarfs_create(struct inode *dir, struct dentry *dentry, var->var.VariableName[i] = '\0'; inode->i_private = var; + kmemleak_ignore(var); err = efivar_entry_add(var, &efivarfs_list); if (err) diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index f943fd0b0699..15880a68faad 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -21,7 +21,6 @@ LIST_HEAD(efivarfs_list); static void efivarfs_evict_inode(struct inode *inode) { clear_inode(inode); - kfree(inode->i_private); } static const struct super_operations efivarfs_ops = { -- 2.17.1