]> git.baikalelectronics.ru Git - kernel.git/commit
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)
committerSteve French <stfrench@microsoft.com>
Wed, 23 Mar 2022 20:20:15 +0000 (15:20 -0500)
commit5a5116d7517794ea1f698a49a31a213dc4055167
tree501b2964ccd2d7878d6a2b6b3e7c0b08fa1c2e63
parent3cb2dbddd6260312600e4a6d975111b977f7bcf1
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: 0d5ef027a6bc0 ("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>
fs/cifs/smb2pdu.c