Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3088391ybt; Mon, 29 Jun 2020 15:03:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQgLtdLgjTlp7JWRtUXZ/ixNDxrAi6eTPvN1pNBurHY4OJip553W/DcoDoro66fDiEr+hm X-Received: by 2002:aa7:c450:: with SMTP id n16mr15903674edr.53.1593468218865; Mon, 29 Jun 2020 15:03:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593468218; cv=none; d=google.com; s=arc-20160816; b=jed5iuCa4f5DyRmXvidc8d4xZJvsAkudpLW3JXb2K1UECCFIfhE2Zj9dPmYYwe+Ajy srEpnZWqDbgiUx2uzT2aK7XUeg8uJno5bRNQswo1gBnn01Y/BEyOuqq1ZtxWORWM4I6Q E8acf3ykRsLC34qDjY1dt1WQmFk0cFknyJ0jMzJVCPC7qpaB2CQWFUo3cFodVPjHrGpJ IxUicjY6/xzK0J6wstgHAM0GEHZ1Ms+hVQhwXoXAfynodXZ5RkfVfZvdbLs5lSPI3X7B 09sLNhMB9YIQliBLNWNjA7MQM5eO3mqz4efHrn0dlaXlyb09wKrVfBGzSk/cUPWL8k84 7ogg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1TgX0/ZujmbZ19frKlQrXQJaklbRi2wvTajRDCMT+OE=; b=tAe1WZ0471xH3UsMJLXRAGdLW42jWFL/OxMkHS7YuohFW5fthK5+XAaBmHVugs8XhM hXPeLyB0Zg/4Vm0f43SW2AoIr9rAd5H8axwa1rIaRJkm0ut3MFK0XAaVBhiTBNvBkjq8 nEQFgg2odhQsk9jDA4klvHdlPU5ucFqqJO8ewvuotVkuR2W11HCLayYfjND5R+NDGrHR Os1EI6xBJ7+5PZRiaweq4JUQ3e/IUGK+z2WhGJHeVDtD24SrKUcLhQZIcFFhdIg+Cocw GbP5dgG6w1Tsmd8hq6AsoDL12ytxOvSfEIsbLQUJ88YUTlsPTAWb3nQ9xriE10Ew9IOX 897A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kr5naMBo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id os21si554034ejb.205.2020.06.29.15.03.15; Mon, 29 Jun 2020 15:03:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kr5naMBo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404562AbgF2WAH (ORCPT + 99 others); Mon, 29 Jun 2020 18:00:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:56792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726397AbgF2SfZ (ORCPT ); Mon, 29 Jun 2020 14:35:25 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 D92412467B; Mon, 29 Jun 2020 15:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593443979; bh=/51UgKaOiB8wer+ZMf40UDlmUj1DatvtgCzTxyBW770=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kr5naMBoUT3MbAvGMbXb3dTrJBgrY8J244547ulYIOBZPZ9bKHHLSANmzRQg1B/8T ADdHsxoj2dWrGKcUUy/omZGj596WwWocPFCypaDXYJGF1JXFSN+z6dFY0nnYMLftSU RLy7ySI17y2mtzdZ/KpECous/oIIwyIkhaddh5QQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiyu Yang , Xin Tan , Steve French , Greg Kroah-Hartman Subject: [PATCH 5.7 083/265] cifs: Fix cached_fid refcnt leak in open_shroot Date: Mon, 29 Jun 2020 11:15:16 -0400 Message-Id: <20200629151818.2493727-84-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629151818.2493727-1-sashal@kernel.org> References: <20200629151818.2493727-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.7-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.7.7-rc1 X-KernelTest-Deadline: 2020-07-01T15:14+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang commit 77577de64167aa0643d47ffbaacf3642632b321b upstream. open_shroot() invokes kref_get(), which increases the refcount of the "tcon->crfid" object. When open_shroot() returns not zero, it means the open operation failed and close_shroot() will not be called to decrement the refcount of the "tcon->crfid". The reference counting issue happens in one normal path of open_shroot(). When the cached root have been opened successfully in a concurrent process, the function increases the refcount and jump to "oshr_free" to return. However the current return value "rc" may not equal to 0, thus the increased refcount will not be balanced outside the function, causing a refcnt leak. Fix this issue by setting the value of "rc" to 0 before jumping to "oshr_free" label. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: Steve French CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index f829f4165d38c..c6a4caa7053e9 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -759,6 +759,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, /* close extra handle outside of crit sec */ SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); } + rc = 0; goto oshr_free; } -- 2.25.1