]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cifs: fix incorrect use of list iterator after the loop
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Sun, 20 Mar 2022 13:50:15 +0000 (21:50 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:21 +0000 (13:57 +0200)
commit a96c94481f5993eac2271f9fb4d009b7dc076c24 upstream.

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: 3663c9045f51a ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/cifs/smb2pdu.c

index 7e7909b1ae1180f836054d51a0da6bc918943231..f82d6fcb5c6469729a8e76c8d940ac6b76a3c14d 100644 (file)
@@ -3858,8 +3858,10 @@ void smb2_reconnect_server(struct work_struct *work)
        tcon = kzalloc(sizeof(struct cifs_tcon), GFP_KERNEL);
        if (!tcon) {
                resched = true;
-               list_del_init(&ses->rlist);
-               cifs_put_smb_ses(ses);
+               list_for_each_entry_safe(ses, ses2, &tmp_ses_list, rlist) {
+                       list_del_init(&ses->rlist);
+                       cifs_put_smb_ses(ses);
+               }
                goto done;
        }