Skip to content

Commit 7023676

Browse files
jtlaytonsmfrench
authored andcommitted
cifs: check for NULL last_entry before calling cifs_save_resume_key
Prior to commit eaf35b1, cifs_save_resume_key had some NULL pointer checks at the top. It turns out that at least one of those NULL pointer checks is needed after all. When the LastNameOffset in a FIND reply appears to be beyond the end of the buffer, CIFSFindFirst and CIFSFindNext will set srch_inf.last_entry to NULL. Since eaf35b1, the code will now oops in this situation. Fix this by having the callers check for a NULL last entry pointer before calling cifs_save_resume_key. No change is needed for the call site in cifs_readdir as it's not reachable with a NULL current_entry pointer. This should fix: https://bugzilla.redhat.com/show_bug.cgi?id=750247 Cc: [email protected] Cc: Christoph Hellwig <[email protected]> Reported-by: Adam G. Metzler <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 95edcff commit 7023676

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

fs/cifs/readdir.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,15 +554,21 @@ static int find_cifs_entry(const int xid, struct cifs_tcon *pTcon,
554554
rc);
555555
return rc;
556556
}
557-
cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile);
557+
/* FindFirst/Next set last_entry to NULL on malformed reply */
558+
if (cifsFile->srch_inf.last_entry)
559+
cifs_save_resume_key(cifsFile->srch_inf.last_entry,
560+
cifsFile);
558561
}
559562

560563
while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
561564
(rc == 0) && !cifsFile->srch_inf.endOfSearch) {
562565
cFYI(1, "calling findnext2");
563566
rc = CIFSFindNext(xid, pTcon, cifsFile->netfid,
564567
&cifsFile->srch_inf);
565-
cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile);
568+
/* FindFirst/Next set last_entry to NULL on malformed reply */
569+
if (cifsFile->srch_inf.last_entry)
570+
cifs_save_resume_key(cifsFile->srch_inf.last_entry,
571+
cifsFile);
566572
if (rc)
567573
return -ENOENT;
568574
}

0 commit comments

Comments
 (0)