From patchwork Wed Sep 4 12:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Lingfeng X-Patchwork-Id: 13790707 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04BA91CFEC8; Wed, 4 Sep 2024 12:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452716; cv=none; b=tMFy3keiweqblIGOoWf5ZsCeEJ0jNoMl71gOL69Nq9blMD7yYOmHhc5vLYQ5dLdYPMDqpMp8wIB2m6y3MdZqb3dDl/lWklD7XUcQ0PByyKeb2ghJuUyQQXuIwNU4YtwWIilDsYu2T+eLZMhyKpOnS1mIQZ4yllLoJLGg21IPaiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725452716; c=relaxed/simple; bh=fAGw/lFDUtCFK4w9/lMU7NNeTTvoDdKMReIVsqDayxA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=A9ZFe5P4pr+x8Q5xg/zrMKz/XmkGpUmW1iYcarna2f/Vv20cFipiRp32iDL5VfLKJbb9z1dt322lJpWsazHbTyH2MuoSuUtR0xx5elJu+AjMZdZ434qo97zrcqnsHyKRywwCFyEzWpdwCxHmh62FC55ozGhCCpYZ4njh8l6H73E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WzMBV70NTz2Dbj6; Wed, 4 Sep 2024 20:24:50 +0800 (CST) Received: from kwepemg500017.china.huawei.com (unknown [7.202.181.81]) by mail.maildlp.com (Postfix) with ESMTPS id 64D511401E9; Wed, 4 Sep 2024 20:25:11 +0800 (CST) Received: from huawei.com (10.175.127.227) by kwepemg500017.china.huawei.com (7.202.181.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 4 Sep 2024 20:25:10 +0800 From: Li Lingfeng To: , CC: , , , , , , , , Subject: [PATCH] nfs: fix memory leak in error path of nfs4_do_reclaim Date: Wed, 4 Sep 2024 20:34:57 +0800 Message-ID: <20240904123457.3027627-1-lilingfeng3@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemg500017.china.huawei.com (7.202.181.81) Commit c77e22834ae9 ("NFSv4: Fix a potential sleep while atomic in nfs4_do_reclaim()") separate out the freeing of the state owners from nfs4_purge_state_owners() and finish it outside the rcu lock. However, the error path is omitted. As a result, the state owners in "freeme" will not be released. Fix it by adding freeing in the error path. Fixes: c77e22834ae9 ("NFSv4: Fix a potential sleep while atomic in nfs4_do_reclaim()") Signed-off-by: Li Lingfeng --- fs/nfs/nfs4state.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 877f682b45f2..30aba1dedaba 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1957,6 +1957,7 @@ static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recov set_bit(ops->owner_flag_bit, &sp->so_flags); nfs4_put_state_owner(sp); status = nfs4_recovery_handle_error(clp, status); + nfs4_free_state_owners(&freeme); return (status != 0) ? status : -EAGAIN; }