Skip to content

Commit a96c944

Browse files
Xiaomeng Tongsmfrench
authored andcommitted
cifs: fix incorrect use of list iterator after the loop
The bug is here: if (!tcon) { resched = true; list_del_init(&ses->rlist); cifs_put_smb_ses(ses); Because the list_for_each_entry() never exits early (without any break/goto/return inside the loop), the iterator 'ses' after the loop will always be an pointer to a invalid struct containing the HEAD (&pserver->smb_ses_list). As a result, the uses of 'ses' above will lead to a invalid memory access. The original intention should have been to walk each entry 'ses' in '&tmp_ses_list', delete '&ses->rlist' and put 'ses'. So fix it with a list_for_each_entry_safe(). Cc: stable@vger.kernel.org # 5.17 Fixes: 3663c90 ("cifs: check reconnects for channels of active tcons too") Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 2d004c6 commit a96c944

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

fs/cifs/smb2pdu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3853,8 +3853,10 @@ void smb2_reconnect_server(struct work_struct *work)
38533853
tcon = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL);
38543854
if (!tcon) {
38553855
resched = true;
3856-
list_del_init(&ses->rlist);
3857-
cifs_put_smb_ses(ses);
3856+
list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
3857+
list_del_init(&ses->rlist);
3858+
cifs_put_smb_ses(ses);
3859+
}
38583860
goto done;
38593861
}
38603862

0 commit comments

Comments
 (0)