Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3413680rwa; Tue, 23 Aug 2022 04:29:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ZU1ZQYb0prbj6RMUsG+Xb1MRhiLmGek6GWVjLUc5nYiKjeDXEWylfMOdCYKYQA6TZ7nuq X-Received: by 2002:a17:907:7214:b0:731:465d:a77c with SMTP id dr20-20020a170907721400b00731465da77cmr15870524ejc.308.1661254196294; Tue, 23 Aug 2022 04:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254196; cv=none; d=google.com; s=arc-20160816; b=bLeERNT7KhMzfEDeHT5udeCi4gOTesJ6BVK/qhTGpDd+W+fGklZqB+MOvbsMwblO7U 2y3csD6TvyG5ZL6Hiaif8X3wZdF6uYf6t6MerPW6qUlgBV7X4v9VTH9zSwTzTRoRNq/D vmHSIbuOGKReMNsCgyUuwMJf3DfclaYcF6Lq0yNzaGmZHLy0TGtTw1ChpoZzzv7l5zac +jyJuyRJqDxaLA4gDQyHa8TPNEB0ISrgfrI9oF0dzYe5le4HG8uLjOUEVjWodBAEvAMA e1OZQdXAOVAlpFjB1MGiXR1TmyNKGAySLo08ytSbqEbOSHC/i82bj0ckNcfQ4LzCFENP 02ow== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eJGKlD2oOlNruQ2BSMHSiClTSEOYTybNcQlsEgH/b00=; b=0ibSB3tZbrwF/v2IfQUSJKyD6gV4z8U5OodOMott79e5ytfjzYTTMK0w4Z/xKubOmo 27TXcG4MujXz5X6N/afiFfnIE/hRmIjMMZLbw/kHCJscYYmu/HHyeSc8mSUPMEx19G6o BfF1TUvD1WzgqMPbx/Onc0RZFeBm78bF6ACWw+z+FVO5K34mI717aI196fLkD3eEFYEf 9tZcPxQsEzWHQ4r9dG4CYSehQHNiAxy9BsubO22AXboPY9gMLcEa7jqglwDQZXECwYvQ 2WDXeCmnGpyGm9sqLDcXM4z/+vCnJlDR8oL5Nm+3gYmezEJJQBHHU6AhUc15HDnAc6QY oXhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xQ2LSDyO; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr2-20020a170906d54200b007341ad4b028si13492691ejc.642.2022.08.23.04.29.30; Tue, 23 Aug 2022 04:29:56 -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=@linuxfoundation.org header.s=korg header.b=xQ2LSDyO; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351565AbiHWJh4 (ORCPT + 99 others); Tue, 23 Aug 2022 05:37:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351960AbiHWJgK (ORCPT ); Tue, 23 Aug 2022 05:36:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4939859A; Tue, 23 Aug 2022 01:40:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C5E8B61485; Tue, 23 Aug 2022 08:39:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AF0DC433D7; Tue, 23 Aug 2022 08:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243977; bh=Q+qKzqalJIXpjEuX1BFx6fnUtUTf+8iG8Dxcg/f1apM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xQ2LSDyOFhaKz1aGvS3O2jEM8px8OIS98gK3OLjEHv2LLcLNf7iIcOWIUY9rQ57ap x33sjaqiCwwAUxHGqi+Ecgr5l9EqriujPPgt0WmLSsgQxKH87CJ/l6Vk7uYI2/Ogcc 05f/miQZxFJUkNrEyaDxqSwVQ6ANnegAeWHWLekU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shyam Prasad N , Zhang Xiaoxu , Steve French Subject: [PATCH 5.15 017/244] cifs: Fix memory leak on the deferred close Date: Tue, 23 Aug 2022 10:22:56 +0200 Message-Id: <20220823080059.651423774@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Zhang Xiaoxu commit ca08d0eac020d48a3141dbec0a3cf64fbdb17cde upstream. xfstests on smb21 report kmemleak as below: unreferenced object 0xffff8881767d6200 (size 64): comm "xfs_io", pid 1284, jiffies 4294777434 (age 20.789s) hex dump (first 32 bytes): 80 5a d0 11 81 88 ff ff 78 8a aa 63 81 88 ff ff .Z......x..c.... 00 71 99 76 81 88 ff ff 00 00 00 00 00 00 00 00 .q.v............ backtrace: [<00000000ad04e6ea>] cifs_close+0x92/0x2c0 [<0000000028b93c82>] __fput+0xff/0x3f0 [<00000000d8116851>] task_work_run+0x85/0xc0 [<0000000027e14f9e>] do_exit+0x5e5/0x1240 [<00000000fb492b95>] do_group_exit+0x58/0xe0 [<00000000129a32d9>] __x64_sys_exit_group+0x28/0x30 [<00000000e3f7d8e9>] do_syscall_64+0x35/0x80 [<00000000102e8a0b>] entry_SYSCALL_64_after_hwframe+0x46/0xb0 When cancel the deferred close work, we should also cleanup the struct cifs_deferred_close. Fixes: 9e992755be8f2 ("cifs: Call close synchronously during unlink/rename/lease break.") Fixes: e3fc065682ebb ("cifs: Deferred close performance improvements") Cc: stable@vger.kernel.org Reviewed-by: Shyam Prasad N Signed-off-by: Zhang Xiaoxu Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/misc.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/cifs/misc.c +++ b/fs/cifs/misc.c @@ -736,6 +736,8 @@ cifs_close_deferred_file(struct cifsInod list_for_each_entry(cfile, &cifs_inode->openFileList, flist) { if (delayed_work_pending(&cfile->deferred)) { if (cancel_delayed_work(&cfile->deferred)) { + cifs_del_deferred_close(cfile); + tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC); if (tmp_list == NULL) break; @@ -767,6 +769,8 @@ cifs_close_all_deferred_files(struct cif cfile = list_entry(tmp, struct cifsFileInfo, tlist); if (delayed_work_pending(&cfile->deferred)) { if (cancel_delayed_work(&cfile->deferred)) { + cifs_del_deferred_close(cfile); + tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC); if (tmp_list == NULL) break; @@ -802,6 +806,8 @@ cifs_close_deferred_file_under_dentry(st if (strstr(full_path, path)) { if (delayed_work_pending(&cfile->deferred)) { if (cancel_delayed_work(&cfile->deferred)) { + cifs_del_deferred_close(cfile); + tmp_list = kmalloc(sizeof(struct file_list), GFP_ATOMIC); if (tmp_list == NULL) break;