* [5.15 Backport] cifs: Check the lease context if we actually got a lease
@ 2024-09-06 10:20 meetakshisetiyaoss
2024-09-06 10:28 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: meetakshisetiyaoss @ 2024-09-06 10:20 UTC (permalink / raw)
To: stable
Cc: smfrench, nspmangalore, bharathsm.hsk, lsahlber, Bharath SM,
Paulo Alcantara (SUSE), Steve French, Meetakshi Setiya
This patch fixes a directory lease bug on the smb client and
prevents it from incorrectly caching the directories if the
server returns an invalid lease state. The patch is in
6.3 kernel, requesting backport to stable 5.15.
I have cherry-picked the patch for 5.15 kernel below
From 2bb51b129ceb884145c3527f8c04817cc00d0e6e Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <lsahlber@redhat.com>
Date: Fri, 17 Feb 2023 13:35:00 +1000
Subject: [PATCH] cifs: Check the lease context if we actually got a lease
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@redhat.com>
Cc: stable@vger.kernel.org
Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Meetakshi Setiya <msetiya@microsoft.com>
---
fs/cifs/smb2ops.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index b725bd3144fb..6c30fff8a029 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -886,8 +886,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
goto oshr_exit;
}
- atomic_inc(&tcon->num_remote_opens);
-
o_rsp = (struct smb2_create_rsp *)rsp_iov[0].iov_base;
oparms.fid->persistent_fid = o_rsp->PersistentFileId;
oparms.fid->volatile_fid = o_rsp->VolatileFileId;
@@ -897,8 +895,6 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
tcon->crfid.tcon = tcon;
tcon->crfid.is_valid = true;
- tcon->crfid.dentry = dentry;
- dget(dentry);
kref_init(&tcon->crfid.refcount);
/* BB TBD check to see if oplock level check can be removed below */
@@ -907,14 +903,16 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
* See commit 2f94a3125b87. Increment the refcount when we
* get a lease for root, release it if lease break occurs
*/
- kref_get(&tcon->crfid.refcount);
- tcon->crfid.has_lease = true;
rc = smb2_parse_contexts(server, rsp_iov,
&oparms.fid->epoch,
oparms.fid->lease_key, &oplock,
NULL, NULL);
if (rc)
goto oshr_exit;
+
+ if (!(oplock & SMB2_LEASE_READ_CACHING_HE))
+ goto oshr_exit;
+
} else
goto oshr_exit;
@@ -928,7 +926,10 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
(char *)&tcon->crfid.file_all_info))
tcon->crfid.file_all_info_is_valid = true;
tcon->crfid.time = jiffies;
-
+ tcon->crfid.dentry = dentry;
+ dget(dentry);
+ kref_get(&tcon->crfid.refcount);
+ tcon->crfid.has_lease = true;
oshr_exit:
mutex_unlock(&tcon->crfid.fid_mutex);
@@ -937,8 +938,15 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
SMB2_query_info_free(&rqst[1]);
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
- if (rc == 0)
+ if (rc) {
+ if (tcon->crfid.is_valid)
+ SMB2_close(0, tcon, oparms.fid->persistent_fid,
+ oparms.fid->volatile_fid);
+ }
+ if (rc == 0) {
*cfid = &tcon->crfid;
+ atomic_inc(&tcon->num_remote_opens);
+ }
return rc;
}
--
2.46.0.46.g406f326d27
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [5.15 Backport] cifs: Check the lease context if we actually got a lease
2024-09-06 10:20 [5.15 Backport] cifs: Check the lease context if we actually got a lease meetakshisetiyaoss
@ 2024-09-06 10:28 ` Greg KH
[not found] ` <CAFTVevVJq6m74GgPzAqTT1AQeiNt2tr3DfQL2tJmfM2wj=SgNg@mail.gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2024-09-06 10:28 UTC (permalink / raw)
To: meetakshisetiyaoss
Cc: stable, smfrench, nspmangalore, bharathsm.hsk, lsahlber,
Bharath SM, Paulo Alcantara (SUSE), Steve French,
Meetakshi Setiya
On Fri, Sep 06, 2024 at 06:20:18AM -0400, meetakshisetiyaoss@gmail.com wrote:
> This patch fixes a directory lease bug on the smb client and
> prevents it from incorrectly caching the directories if the
> server returns an invalid lease state. The patch is in
> 6.3 kernel, requesting backport to stable 5.15.
> I have cherry-picked the patch for 5.15 kernel below
>
> >From 2bb51b129ceb884145c3527f8c04817cc00d0e6e Mon Sep 17 00:00:00 2001
What is the real git commit id of this change?
And what about 6.1.y? You can't skip that or you would have a
regression when you upgrade as you shouldn't be using 5.15.y for much
longer, right? :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-06 10:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06 10:20 [5.15 Backport] cifs: Check the lease context if we actually got a lease meetakshisetiyaoss
2024-09-06 10:28 ` Greg KH
[not found] ` <CAFTVevVJq6m74GgPzAqTT1AQeiNt2tr3DfQL2tJmfM2wj=SgNg@mail.gmail.com>
2024-09-06 10:48 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox