This is a note to let you know that I've just added the patch titled cifs: Check the lease context if we actually got a lease to the 6.2-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: cifs-check-the-lease-context-if-we-actually-got-a-lease.patch and it can be found in the queue-6.2 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 66d45ca1350a3bb8d5f4db8879ccad3ed492337a Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg <lsahlber@xxxxxxxxxx> Date: Fri, 17 Feb 2023 13:35:00 +1000 Subject: cifs: Check the lease context if we actually got a lease From: Ronnie Sahlberg <lsahlber@xxxxxxxxxx> commit 66d45ca1350a3bb8d5f4db8879ccad3ed492337a upstream. Some servers may return that we got a lease in rsp->OplockLevel but then in the lease context contradict this and say we got no lease at all. Thus we need to check the context if we have a lease. Additionally, If we do not get a lease we need to make sure we close the handle before we return an error to the caller. Signed-off-by: Ronnie Sahlberg <lsahlber@xxxxxxxxxx> Cc: stable@xxxxxxxxxxxxxxx Reviewed-by: Bharath SM <bharathsm@xxxxxxxxxxxxx> Reviewed-by: Paulo Alcantara (SUSE) <pc@xxxxxxxxxxxxx> Signed-off-by: Steve French <stfrench@xxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/cifs/cached_dir.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/fs/cifs/cached_dir.c +++ b/fs/cifs/cached_dir.c @@ -221,8 +221,7 @@ int open_cached_dir(unsigned int xid, st } goto oshr_free; } - - atomic_inc(&tcon->num_remote_opens); + cfid->is_open = true; o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base; oparms.fid->persistent_fid = o_rsp->PersistentFileId; @@ -239,7 +238,8 @@ int open_cached_dir(unsigned int xid, st &oparms.fid->epoch, oparms.fid->lease_key, &oplock, NULL, NULL); - + if (!(oplock & SMB2_LEASE_READ_CACHING_HE)) + goto oshr_free; qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) goto oshr_free; @@ -262,7 +262,6 @@ int open_cached_dir(unsigned int xid, st cfid->dentry = dentry; cfid->tcon = tcon; cfid->time = jiffies; - cfid->is_open = true; cfid->has_lease = true; oshr_free: @@ -282,12 +281,17 @@ oshr_free: } spin_unlock(&cfids->cfid_list_lock); if (rc) { + if (cfid->is_open) + SMB2_close(0, cfid->tcon, cfid->fid.persistent_fid, + cfid->fid.volatile_fid); free_cached_dir(cfid); cfid = NULL; } - if (rc == 0) + if (rc == 0) { *ret_cfid = cfid; + atomic_inc(&tcon->num_remote_opens); + } return rc; } Patches currently in stable-queue which might be from lsahlber@xxxxxxxxxx are queue-6.2/cifs-improve-checking-of-dfs-links-over-status_object_name_invalid.patch queue-6.2/cifs-return-a-single-use-cfid-if-we-did-not-get-a-lease.patch queue-6.2/cifs-fix-mount-on-old-smb-servers.patch queue-6.2/cifs-check-the-lease-context-if-we-actually-got-a-lease.patch