From patchwork Wed Apr 22 09:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 227070 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=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 53588C55185 for ; Wed, 22 Apr 2020 10:54:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28C5220774 for ; Wed, 22 Apr 2020 10:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587552852; bh=TF/01RNQtNtjrq6KbrU+2FAcLCzjC1oerULda68YHj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=PhMYbPmxchZuoNE5+uDgY/TfTfVI6H2qU8GAUCnxB3ZzT5V1dYx2cKaDwNhB+cweo 2xG8GajQhQtPz/Oc+Cxs8wpT5pu1OD/BTdckNg+lHdyV7wAwEvw49IJSGR/hRwnLd2 fHmzRVALU+pEz8oXA7bh2/Zt1PuQVq2a1GrQFj5w= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728663AbgDVKIP (ORCPT ); Wed, 22 Apr 2020 06:08:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:33400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbgDVKIO (ORCPT ); Wed, 22 Apr 2020 06:08:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 928F52077D; Wed, 22 Apr 2020 10:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587550094; bh=TF/01RNQtNtjrq6KbrU+2FAcLCzjC1oerULda68YHj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hm8mr3vwcH0PrpiGEL4YyV1EKdp+HXbmRyMKj07WHPuNjKa+po7MI2nRLuKsjB+Hz doGZ3wtY8W6VLNeYh7DpRWub7r0a2mEnerwFJp8lf0g0xwE0G9/oXwXHVt2mL6j6Ty +ixGwUpcJUPspBWqoRUBVcHc5+sF+l1hHiyqL7QE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Misono Tomohiro , Trond Myklebust , Sasha Levin Subject: [PATCH 4.9 106/125] NFS: direct.c: Fix memory leak of dreq when nfs_get_lock_context fails Date: Wed, 22 Apr 2020 11:57:03 +0200 Message-Id: <20200422095049.996928532@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095032.909124119@linuxfoundation.org> References: <20200422095032.909124119@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Misono Tomohiro [ Upstream commit 8605cf0e852af3b2c771c18417499dc4ceed03d5 ] When dreq is allocated by nfs_direct_req_alloc(), dreq->kref is initialized to 2. Therefore we need to call nfs_direct_req_release() twice to release the allocated dreq. Usually it is called in nfs_file_direct_{read, write}() and nfs_direct_complete(). However, current code only calls nfs_direct_req_relese() once if nfs_get_lock_context() fails in nfs_file_direct_{read, write}(). So, that case would result in memory leak. Fix this by adding the missing call. Signed-off-by: Misono Tomohiro Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/direct.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 53f0012ace42f..de135d2591ffb 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -595,6 +595,7 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, struct iov_iter *iter) l_ctx = nfs_get_lock_context(dreq->ctx); if (IS_ERR(l_ctx)) { result = PTR_ERR(l_ctx); + nfs_direct_req_release(dreq); goto out_release; } dreq->l_ctx = l_ctx; @@ -1019,6 +1020,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter) l_ctx = nfs_get_lock_context(dreq->ctx); if (IS_ERR(l_ctx)) { result = PTR_ERR(l_ctx); + nfs_direct_req_release(dreq); goto out_release; } dreq->l_ctx = l_ctx;