]> git.itanic.dy.fi Git - linux-stable/commitdiff
smb: client: fix potential UAF in cifs_debug_files_proc_show()
authorPaulo Alcantara <pc@manguebit.com>
Tue, 2 Apr 2024 19:33:53 +0000 (16:33 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:38:21 +0000 (16:38 +0200)
commit ca545b7f0823f19db0f1148d59bc5e1a56634502 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
fs/smb/client/cifsglob.h

index 23d2622b969f09237eff1d122565bc81039aebf2..4f4be57b6f5bdd18529f20f93882c0e19f2ecd71 100644 (file)
@@ -250,6 +250,8 @@ static int cifs_debug_files_proc_show(struct seq_file *m, void *v)
        spin_lock(&cifs_tcp_ses_lock);
        list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
                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) {
                                spin_lock(&tcon->open_file_lock);
                                list_for_each_entry(cfile, &tcon->openFileList, tlist) {
index 6d1c518378a152f25fa1b51ea8b52e2d24ebcb3a..844afda090d05482692eaf028b14c2eb53f8766e 100644 (file)
@@ -2295,4 +2295,14 @@ struct smb2_compound_vars {
        struct smb2_file_link_info link_info;
 };
 
+static inline bool cifs_ses_exiting(struct cifs_ses *ses)
+{
+       bool ret;
+
+       spin_lock(&ses->ses_lock);
+       ret = ses->ses_status == SES_EXITING;
+       spin_unlock(&ses->ses_lock);
+       return ret;
+}
+
 #endif /* _CIFS_GLOB_H */