Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 5A38F4FB9C6 for ; Wed, 30 Sep 2026 16:08:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790784542; cv=none; b=Lanzr5ErHAwQ2QLsGa3p4BHI4aUbWzYfdCb4NvEG87gZBUhxQthBd3WVUtbdWYuK7hRlfxb4Ch2FNSxfAlH2MEHv/ij2HGpLEXrWkmRcskySJ/CEskt2IwoqZLBOzOyHIhRFVs3WUY+7nKtcmzsTA9xxVY3+LoCtlwFZnc4BTB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790784542; c=relaxed/simple; bh=xhf1GehCpyXXGoKsorDEK3wW2mhhvK1GbINbgddAk/E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eNjIfRVPG3Xmzwc0uiFymufs37WyKZdNzprJSdPeEX5XY8lKOTf3yfK/D5gn8+TE2srAZkbXMy24JO5RIN0MWTl5Ze8YFIZFbYOgZgnBjKr2gtT8pzA2VcR2y/xLpp+uENRLy/pcYKuWHTM4zlN8vZYv6i3mbedfNyT4tuZ4C1o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IXWN/mPK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IXWN/mPK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56EA41F0089A; Wed, 30 Sep 2026 16:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790784535; bh=Gu4B4TvszWdxT/pSE3bJ3tBaYMJw5ZjH9ije66LHx5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IXWN/mPKvQPyT56vpAhnDU4l6r79QXVfmftNlX/OyJACHqr/dxgB9/jWh/9KI6wkf CkM3jp56qNpXD9krgIaDwNBH7N88g9ErukwWuCYw2lMeu67SM644BvFvGvQykBBUgl kZhF8nEJaU0CXNAWCoC7AcBNsqmwkN1VBj8i19AeviMMsO6hyWR/npG3RwHWqoH6pm w42qpXHQKAq662JB0RTrw88WWTSNVp0NiBc2KS3HVJ+/GEWT20JQwyaTaWYFSt3MW0 uAYqU9IL0Kex7Xd3gqqVpDIXItUMIGABDJlHITZmVd+Pp9P8m8gPXawrHsV87+WQrk r+9rsVKUxRfbA== From: Sasha Levin To: stable@vger.kernel.org Cc: Zihan Xi , Vega , Luxing Yin , Frank Sorenson , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.6.y 2/2] smb: client: clean up failed cached directory opens Date: Wed, 30 Sep 2026 12:08:51 -0400 Message-ID: <20260930160851.2985631-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930160851.2985631-1-sashal@kernel.org> References: <2026092937-truce-superhero-2529@gregkh> <20260930160851.2985631-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zihan Xi [ Upstream commit d2ff5fb93ea83034025850266b5eed391f96b825 ] open_cached_dir() sends CREATE and QUERY_INFO as a compound request. If the CREATE succeeds but a later command returns an error, the function must retain the CREATE FID so common cleanup can issue SMB2_close(). It also must not treat a response error as a valid CREATE. Validate the CREATE response before using its fields, record the FIDs, and mark the handle open before handling errors from later compound commands. Move the -EREMCHG reconnect handling before response validation so a missing response does not hide the reconnect request. Count the handle when it is marked open; confirmed close responses decrement the counter, while existing close retry behavior remains best effort on transport failures. Fixes: b0f6df737a1c ("cifs: cache FILE_ALL_INFO for the shared root handle") Cc: stable@vger.kernel.org Reported-by: Vega Assisted-by: LLM Co-developed-by: Luxing Yin Signed-off-by: Luxing Yin Signed-off-by: Zihan Xi Tested-by: Frank Sorenson Signed-off-by: Paulo Alcantara Signed-off-by: Sasha Levin --- fs/smb/client/cached_dir.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c index fbc746813a6f2..bb1358d649499 100644 --- a/fs/smb/client/cached_dir.c +++ b/fs/smb/client/cached_dir.c @@ -8,6 +8,7 @@ #include #include "cifsglob.h" #include "cifsproto.h" +#include "../common/smb2status.h" #include "cifs_debug.h" #include "smb2proto.h" #include "cached_dir.h" @@ -294,25 +295,37 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rc = compound_send_recv(xid, ses, server, flags, 2, rqst, resp_buftype, rsp_iov); - if (rc) { - if (rc == -EREMCHG) { - tcon->need_reconnect = true; - pr_warn_once("server share %s deleted\n", - tcon->tree_name); - } - goto oshr_free; + if (rc == -EREMCHG) { + tcon->need_reconnect = true; + pr_warn_once("server share %s deleted\n", + tcon->tree_name); } - cfid->is_open = true; - spin_lock(&cfids->cfid_list_lock); + if (!rsp_iov[0].iov_base || rsp_iov[0].iov_len < sizeof(*o_rsp)) { + if (!rc) + rc = -EIO; + goto oshr_free; + } o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base; + if (o_rsp->hdr.Status != STATUS_SUCCESS) { + if (!rc) + rc = -EIO; + goto oshr_free; + } + oparms.fid->persistent_fid = o_rsp->PersistentFileId; oparms.fid->volatile_fid = o_rsp->VolatileFileId; #ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid = le64_to_cpu(o_rsp->hdr.MessageId); #endif /* CIFS_DEBUG2 */ + cfid->is_open = true; + atomic_inc(&tcon->num_remote_opens); + if (rc) + goto oshr_free; + + spin_lock(&cfids->cfid_list_lock); if (o_rsp->OplockLevel != SMB2_OPLOCK_LEVEL_LEASE) { spin_unlock(&cfids->cfid_list_lock); @@ -378,7 +391,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, close_cached_dir(cfid); } else { *ret_cfid = cfid; - atomic_inc(&tcon->num_remote_opens); } kfree(utf16_path); -- 2.53.0