smb: client: fix potential UAF in cifs_stats_proc_write()
authorPaulo Alcantara <pc@manguebit.com>
Tue, 2 Apr 2024 19:33:55 +0000 (16:33 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:36:05 +0000 (16:36 +0200)
commit d3da25c5ac84430f89875ca7485a3828150a7e0a upstream.

Skip sessions that are being teared down (status == SES_EXITING) to
avoid UAF.

Cc: stable@vger.kernel.org
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/cifs_debug.c

index 82cac81..b4d2ee2 100644 (file)
@@ -656,6 +656,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
                        }
 #endif /* CONFIG_CIFS_STATS2 */
                        list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+                               if (cifs_ses_exiting(ses))
+                                       continue;
                                list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
                                        atomic_set(&tcon->num_smbs_sent, 0);
                                        spin_lock(&tcon->stat_lock);