Skip to content

Commit 59a556a

Browse files
bharathsm-msSteve French
authored andcommitted
SMB3: drop reference to cfile before sending oplock break
In cifs_oplock_break function we drop reference to a cfile at the end of function, due to which close command goes on wire after lease break acknowledgment even if file is already closed by application but we had deferred the handle close. If other client with limited file shareaccess waiting on lease break ack proceeds operation on that file as soon as first client sends ack, then we may encounter status sharing violation error because of open handle. Solution is to put reference to cfile(send close on wire if last ref) and then send oplock acknowledgment to server. Fixes: 9e31678 ("SMB3: fix lease break timeout when multiple deferred close handles for the same file.") Cc: stable@kernel.org Signed-off-by: Bharath SM <bharathsm@microsoft.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 47592fa commit 59a556a

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

fs/cifs/cifsglob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ struct smb_version_operations {
424424
/* check for STATUS_NETWORK_SESSION_EXPIRED */
425425
bool (*is_session_expired)(char *);
426426
/* send oplock break response */
427-
int (*oplock_response)(struct cifs_tcon *, struct cifs_fid *,
428-
struct cifsInodeInfo *);
427+
int (*oplock_response)(struct cifs_tcon *tcon, __u64 persistent_fid, __u64 volatile_fid,
428+
__u16 net_fid, struct cifsInodeInfo *cifs_inode);
429429
/* query remote filesystem */
430430
int (*queryfs)(const unsigned int, struct cifs_tcon *,
431431
struct cifs_sb_info *, struct kstatfs *);

fs/cifs/file.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4881,7 +4881,9 @@ void cifs_oplock_break(struct work_struct *work)
48814881
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
48824882
struct TCP_Server_Info *server = tcon->ses->server;
48834883
int rc = 0;
4884-
bool purge_cache = false;
4884+
bool purge_cache = false, oplock_break_cancelled;
4885+
__u64 persistent_fid, volatile_fid;
4886+
__u16 net_fid;
48854887

48864888
wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS,
48874889
TASK_UNINTERRUPTIBLE);
@@ -4926,19 +4928,24 @@ void cifs_oplock_break(struct work_struct *work)
49264928
if (!CIFS_CACHE_HANDLE(cinode) && !list_empty(&cinode->deferred_closes))
49274929
cifs_close_deferred_file(cinode);
49284930

4931+
persistent_fid = cfile->fid.persistent_fid;
4932+
volatile_fid = cfile->fid.volatile_fid;
4933+
net_fid = cfile->fid.netfid;
4934+
oplock_break_cancelled = cfile->oplock_break_cancelled;
4935+
4936+
_cifsFileInfo_put(cfile, false /* do not wait for ourself */, false);
49294937
/*
49304938
* releasing stale oplock after recent reconnect of smb session using
49314939
* a now incorrect file handle is not a data integrity issue but do
49324940
* not bother sending an oplock release if session to server still is
49334941
* disconnected since oplock already released by the server
49344942
*/
4935-
if (!cfile->oplock_break_cancelled) {
4936-
rc = tcon->ses->server->ops->oplock_response(tcon, &cfile->fid,
4937-
cinode);
4943+
if (!oplock_break_cancelled) {
4944+
rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
4945+
volatile_fid, net_fid, cinode);
49384946
cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
49394947
}
49404948

4941-
_cifsFileInfo_put(cfile, false /* do not wait for ourself */, false);
49424949
cifs_done_oplock_break(cinode);
49434950
}
49444951

fs/cifs/smb1ops.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,11 @@ cifs_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
897897
}
898898

899899
static int
900-
cifs_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
901-
struct cifsInodeInfo *cinode)
900+
cifs_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
901+
__u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
902902
{
903-
return CIFSSMBLock(0, tcon, fid->netfid, current->tgid, 0, 0, 0, 0,
904-
LOCKING_ANDX_OPLOCK_RELEASE, false,
905-
CIFS_CACHE_READ(cinode) ? 1 : 0);
903+
return CIFSSMBLock(0, tcon, net_fid, current->tgid, 0, 0, 0, 0,
904+
LOCKING_ANDX_OPLOCK_RELEASE, false, CIFS_CACHE_READ(cinode) ? 1 : 0);
906905
}
907906

908907
static int

fs/cifs/smb2ops.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,15 +2383,14 @@ smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)
23832383
}
23842384

23852385
static int
2386-
smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
2387-
struct cifsInodeInfo *cinode)
2386+
smb2_oplock_response(struct cifs_tcon *tcon, __u64 persistent_fid,
2387+
__u64 volatile_fid, __u16 net_fid, struct cifsInodeInfo *cinode)
23882388
{
23892389
if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
23902390
return SMB2_lease_break(0, tcon, cinode->lease_key,
23912391
smb2_get_lease_state(cinode));
23922392

2393-
return SMB2_oplock_break(0, tcon, fid->persistent_fid,
2394-
fid->volatile_fid,
2393+
return SMB2_oplock_break(0, tcon, persistent_fid, volatile_fid,
23952394
CIFS_CACHE_READ(cinode) ? 1 : 0);
23962395
}
23972396

0 commit comments

Comments
 (0)