Skip to content

Commit 2f94a31

Browse files
Ronnie SahlbergSteve French
Ronnie Sahlberg
authored and
Steve French
committed
cifs: fix kref underflow in close_shroot()
Fix a bug where we used to not initialize the cached fid structure at all in open_shroot() if the open was successful but we did not get a lease. This would leave the structure uninitialized and later when we close the handle we would in close_shroot() try to kref_put() an uninitialized refcount. Fix this by always initializing this structure if the open was successful but only do the extra get() if we got a lease. This extra get() is only used to hold the structure until we get a lease break from the server at which point we will kref_put() it during lease processing. Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]> CC: Stable <[email protected]>
1 parent 5e7a8ca commit 2f94a31

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

fs/cifs/smb2ops.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -717,20 +717,18 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
717717
oparms.fid->mid = le64_to_cpu(o_rsp->sync_hdr.MessageId);
718718
#endif /* CIFS_DEBUG2 */
719719

720-
if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE)
721-
oplock = smb2_parse_lease_state(server, o_rsp,
722-
&oparms.fid->epoch,
723-
oparms.fid->lease_key);
724-
else
725-
goto oshr_exit;
726-
727-
728720
memcpy(tcon->crfid.fid, pfid, sizeof(struct cifs_fid));
729721
tcon->crfid.tcon = tcon;
730722
tcon->crfid.is_valid = true;
731723
kref_init(&tcon->crfid.refcount);
732-
kref_get(&tcon->crfid.refcount);
733724

725+
if (o_rsp->OplockLevel == SMB2_OPLOCK_LEVEL_LEASE) {
726+
kref_get(&tcon->crfid.refcount);
727+
oplock = smb2_parse_lease_state(server, o_rsp,
728+
&oparms.fid->epoch,
729+
oparms.fid->lease_key);
730+
} else
731+
goto oshr_exit;
734732

735733
qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
736734
if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info))

0 commit comments

Comments
 (0)