Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp55113lfv; Tue, 12 Apr 2022 17:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy90Yh/HfwaKdYoUtR0ddA/QLGYd1tculLbitD0QzFZ94GfvPnrK1a5ncFXNtqgB0Nb5wwI X-Received: by 2002:a17:903:2ca:b0:156:f1cc:7cb6 with SMTP id s10-20020a17090302ca00b00156f1cc7cb6mr33693593plk.174.1649808283864; Tue, 12 Apr 2022 17:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649808283; cv=none; d=google.com; s=arc-20160816; b=pNHnq4m/2A5CpcydqGt3Wyrc9v7bIuoQW4pHqaEl8aBNUfUxiRR9hdpMjcAmMoEG7t pr6DDGUbtetzANG6OVukiwcjhPg01dV3DhYQX7R1FS3vKPDIJKymsgk2/JRF1N7ialje RwPtYi+zlbwb9bouqrsqcVLB7SSsMlCtwqz4YeAGPFSMTau0JM/1wi5IYA8qhDKhgKNt FKYPNZoR6wHZOq42Y9zM5l9ZMc4i1rxkpsPuKC4rRAQLtsmRLb4D4XVCKH8KI+XxM53B IB0xGb7JkP5gvA7UHh2p7WasWXGQLAB9R66re4x0UL034XgvYJa0ojDyFFzR0VFZk7km +oTA== 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=c3iDfSSUojQMKXTH147iHJWgvHsC2YdubjKd914hAa8=; b=KVgeikLIXB4DtCljEiFvVYyABsUc4pwEUE//7skCz4Q+eHjFtmiDmWdkIIYyver8bi /r1zlQMbVt5j7cSaV7ukvGg5t10jUCWOT/rh4Cve7x0DAO/xiw69jKLbV1TEP8XOfKDF t4qmuDbOGVXyjn8kMCu9L5bwKSg81gChhTCBY1RRUoQXjbUhxq1RNBjKI5i72SETeRH+ M7BXvL+3QvcBWnjFhc4I23UlDRtT46ii4tXzrNZnt4MePAjza1++1AioAiUNcvo4mHZR EwAzz2hn2jN5MIxEiJpT6v8u5rgzHpE9jWmiaa1QZhHetqxSR1OnKZAykpeaAneGjALh bSGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cCbjDPsd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v69-20020a638948000000b00398b858c5d4si236661pgd.525.2022.04.12.17.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 17:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cCbjDPsd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B4EBB14A902; Tue, 12 Apr 2022 15:01:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243736AbiDLGuM (ORCPT + 99 others); Tue, 12 Apr 2022 02:50:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351481AbiDLGo4 (ORCPT ); Tue, 12 Apr 2022 02:44:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE6433AA7B; Mon, 11 Apr 2022 23:38:25 -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 ams.source.kernel.org (Postfix) with ESMTPS id 87AE2B818C8; Tue, 12 Apr 2022 06:38:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E40F2C385A1; Tue, 12 Apr 2022 06:38:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649745503; bh=u+U5VkDgvKYLLZki/AQqHBw1Vp9+XfAo+5qJ6Dk/VdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCbjDPsd8C/JcuVeKAve62/LVof0LXZa4Uw8M+tUVp9loQUdSw3jhtXzlsPcdPtnZ BKTaomvFTk1RyENH3rTiAkzlIpAGB9kdZ0oZKWX1FMc0BWlWHxH+mvAnG96NXBVFFr vfH+VLLx3ZSqhml0FP909mRlIsP4oB5Z6SzUPBTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Xiong , Xiyu Yang , Xin Tan , Trond Myklebust , Sasha Levin Subject: [PATCH 5.10 077/171] NFSv4.2: fix reference count leaks in _nfs42_proc_copy_notify() Date: Tue, 12 Apr 2022 08:29:28 +0200 Message-Id: <20220412062930.114869680@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062927.870347203@linuxfoundation.org> References: <20220412062927.870347203@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Xin Xiong [ Upstream commit b7f114edd54326f730a754547e7cfb197b5bc132 ] [You don't often get email from xiongx18@fudan.edu.cn. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.] The reference counting issue happens in two error paths in the function _nfs42_proc_copy_notify(). In both error paths, the function simply returns the error code and forgets to balance the refcount of object `ctx`, bumped by get_nfs_open_context() earlier, which may cause refcount leaks. Fix it by balancing refcount of the `ctx` object before the function returns in both error paths. Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs42proc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index 2587b1b8e2ef..dad32b171e67 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -567,8 +567,10 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst, ctx = get_nfs_open_context(nfs_file_open_context(src)); l_ctx = nfs_get_lock_context(ctx); - if (IS_ERR(l_ctx)) - return PTR_ERR(l_ctx); + if (IS_ERR(l_ctx)) { + status = PTR_ERR(l_ctx); + goto out; + } status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx, FMODE_READ); @@ -576,7 +578,7 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst, if (status) { if (status == -EAGAIN) status = -NFS4ERR_BAD_STATEID; - return status; + goto out; } status = nfs4_call_sync(src_server->client, src_server, &msg, @@ -584,6 +586,7 @@ static int _nfs42_proc_copy_notify(struct file *src, struct file *dst, if (status == -ENOTSUPP) src_server->caps &= ~NFS_CAP_COPY_NOTIFY; +out: put_nfs_open_context(nfs_file_open_context(src)); return status; } -- 2.35.1