smb: client: fix potential UAF in cifs_debug_files_proc_show()
Subsystems (2)
PATCH 1/12 smb: client: fix potential UAF in cifs_debug_files_proc_show()
Skip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/cifs_debug.c | 2 ++ fs/smb/client/cifsglob.h | 10 ++++++++++ 2 files changed, 12 insertions(+)
fs/smb/client/cifs_debug.c +2 -0
@@ -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) {
fs/smb/client/cifsglob.h +10 -0
@@ -2322,4 +2322,14 @@ struct smb2_compound_vars { struct kvec ea_iov; }; +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 */
Signature · 1 line
2.44.0
PATCH 2/12 smb: client: fix potential UAF in cifs_dump_full_key()
Skip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/ioctl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/ioctl.c +5 -1
@@ -247,7 +247,9 @@ static int cifs_dump_full_key(struct cifs_tcon *tcon, struct smb3_full_key_debugspin_lock (&cifs_tcp_ses_lock);list_for_each_entry (server_it, &cifs_tcp_ses_list, tcp_ses_list) {list_for_each_entry (ses_it, &server_it->smb_ses_list, smb_ses_list) { -if (ses_it->Suid == out.session_id) { +spin_lock (&ses_it->ses_lock); +if (ses_it->ses_status !=SES_EXITING && + ses_it->Suid == out.session_id) { ses = ses_it;/* * since we are using the session outside the crit
@@ -255,9 +257,11 @@ static int cifs_dump_full_key(struct cifs_tcon *tcon, struct smb3_full_key_debug* so increment its refcount */ cifs_smb_ses_inc_refcount (ses); +spin_unlock (&ses_it->ses_lock); found = true; goto search_end; } +spin_unlock (&ses_it->ses_lock); } } search_end:
Signature · 1 line
2.44.0
PATCH 3/12 smb: client: fix potential UAF in cifs_stats_proc_write()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/cifs_debug.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/cifs_debug.c +2 -0
@@ -678,6 +678,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);
Signature · 1 line
2.44.0
PATCH 4/12 smb: client: fix potential UAF in cifs_stats_proc_show()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/cifs_debug.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/cifs_debug.c +2 -0
@@ -759,6 +759,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v) }#endif /* 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) { i++;seq_printf (m,"\n%d) %s" , i, tcon->tree_name);
Signature · 1 line
2.44.0
PATCH 5/12 smb: client: fix potential UAF in smb2_check_message()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/smb/client/smb2misc.c +2 -1
@@ -160,7 +160,8 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *server)/* decrypt frame now that it is completely read in */ spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (iter, &pserver->smb_ses_list, smb_ses_list) { -if (iter->Suid ==le64_to_cpu (thdr->SessionId)) { +if (!cifs_ses_exiting (iter) && + iter->Suid ==le64_to_cpu (thdr->SessionId)) { ses = iter;break ; }
Signature · 1 line
2.44.0
PATCH 6/12 smb: client: fix potential UAF in smb2_is_valid_lease_break()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2misc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/smb2misc.c +2 -0
@@ -623,6 +623,8 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)/* look up tcon based on tid & uid */ spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->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); cifs_stats_inc(
Signature · 1 line
2.44.0
PATCH 7/12 smb: client: fix potential UAF in smb2_is_valid_oplock_break()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2misc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/smb2misc.c +2 -0
@@ -700,6 +700,8 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)/* look up tcon based on tid & uid */ spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->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);
Signature · 1 line
2.44.0
PATCH 8/12 smb: client: fix potential UAF in is_valid_oplock_break()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/misc.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/misc.c +2 -0
@@ -481,6 +481,8 @@ is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv)/* look up tcon based on tid & uid */ spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { +if (cifs_ses_exiting (ses)) +continue ;list_for_each_entry (tcon, &ses->tcon_list, tcon_list) {if (tcon->tid != buf->Tid)continue ;
Signature · 1 line
2.44.0
PATCH 9/12 smb: client: fix potential UAF in smb2_get_sign_key()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2transport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/smb/client/smb2transport.c +3 -2
@@ -89,8 +89,10 @@ int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key) pserver =SERVER_IS_CHAN (server) ? server->primary_server : server;list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { -if (ses->Suid == ses_id) +spin_lock (&ses->ses_lock); +if (ses->ses_status !=SES_EXITING && ses->Suid == ses_id) goto found; +spin_unlock (&ses->ses_lock); }trace_smb3_ses_not_found (ses_id); cifs_server_dbg(FYI, "%s: Could not find session 0x%llx\n",
@@ -99,7 +101,6 @@ int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key) goto out; found: -spin_lock (&ses->ses_lock);spin_lock (&ses->chan_lock); is_binding = (cifs_chan_needs_reconnect(ses, server) &&
Signature · 1 line
2.44.0
Re: [PATCH 09/12] smb: client: fix potential UAF in smb2_get_sign_key()
Quoted 7 lines · Paulo Alcantara
Skip sessions that are being teared down (status ==
SES_EXITING) to avoid UAF.Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>--- fs/smb/client/smb2transport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Please ignore this one as we still need the signing key for session logoff in __cifs_put_smb_ses().
PATCH 10/12 smb: client: fix potential UAF in smb2_is_network_name_deleted()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2ops.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/smb2ops.c +2 -0
@@ -2480,6 +2480,8 @@ smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server)spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { +if (cifs_ses_exiting (ses)) +continue ;list_for_each_entry (tcon, &ses->tcon_list, tcon_list) {if (tcon->tid ==le32_to_cpu (shdr->Id.SyncId.TreeId)) {spin_lock (&tcon->tc_lock);
Signature · 1 line
2.44.0
PATCH 11/12 smb: client: fix potential UAF in smb2_get_enc_key()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/smb2ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +3 -2
@@ -4188,8 +4188,8 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { -if (ses->Suid == ses_id) { -spin_lock (&ses->ses_lock); +spin_lock (&ses->ses_lock); +if (ses->ses_status !=SES_EXITING && ses->Suid == ses_id) { ses_enc_key = enc ? ses->smb3encryptionkey : ses->smb3decryptionkey;memcpy (key, ses_enc_key,SMB3_ENC_DEC_KEY_SIZE );
@@ -4197,6 +4197,7 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)spin_unlock (&cifs_tcp_ses_lock);return 0 ; } +spin_unlock (&ses->ses_lock); }spin_unlock (&cifs_tcp_ses_lock);
Signature · 1 line
2.44.0
Re: [PATCH 11/12] smb: client: fix potential UAF in smb2_get_enc_key()
Isn't this needed to send the SMB3 Logoff request?
Quoted 36 lines · Paulo Alcantara
Skip sessions that are being teared down (status ==
SES_EXITING) to avoid UAF.Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>--- fs/smb/client/smb2ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/smb/client/smb2ops.c +3
-3@@ -4188,8 +4188,8 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { -if (ses->Suid == ses_id) { -spin_lock (&ses->ses_lock); +spin_lock (&ses->ses_lock); +if (ses->ses_status !=SES_EXITING && ses->Suid == ses_id) { ses_enc_key = enc ? ses->smb3encryptionkey : ses->smb3decryptionkey;memcpy (key, ses_enc_key,SMB3_ENC_DEC_KEY_SIZE );@@ -4197,6 +4197,7 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)spin_unlock (&cifs_tcp_ses_lock);return 0 ; } +spin_unlock (&ses->ses_lock); }spin_unlock (&cifs_tcp_ses_lock); --2.44.0
Signature · 3 lines
Thanks, Steve
Re: [PATCH 11/12] smb: client: fix potential UAF in smb2_get_enc_key()
Quoted 1 line · Steve French
Isn't this needed to send the SMB3 Logoff request?
Yes, good catch! Please drop this one.
Re: [PATCH 11/12] smb: client: fix potential UAF in smb2_get_enc_key()
In reply to Paulo AlcantaraQuoted 7 lines · Paulo Alcantara
Skip sessions that are being teared down (status ==
SES_EXITING) to avoid UAF.Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>--- fs/smb/client/smb2ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
As we can send encrypted session logoff when SMB2_SESSION_FLAG_ENCRYPT_DATA is set, then please ignore this one and patch 05/12.
PATCH 12/12 smb: client: fix potential UAF in cifs_signal_cifsd_for_reconnect()
In reply to Paulo AlcantaraSkip sessions that are being teared down (status == SES_EXITING) to avoid UAF.
--- fs/smb/client/connect.c | 2 ++ 1 file changed, 2 insertions(+)
fs/smb/client/connect.c +2 -0
@@ -175,6 +175,8 @@ cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server,spin_lock (&cifs_tcp_ses_lock);list_for_each_entry (ses, &pserver->smb_ses_list, smb_ses_list) { +if (cifs_ses_exiting (ses)) +continue ;spin_lock (&ses->chan_lock);for (i =0 ; i < ses->chan_count; i++) {if (!ses->chans[i].server)
Signature · 1 line
2.44.0
Hello,
I have some questions regarding CVE-2024-26928.
I would like to confirm whether the phrase "fix potential UAF in cifs_debug_files_proc_show()" implies that the UAF issue does not actually exist, correct?
Based on my analysis, cifs_tcp_ses_lock plays a crucial role in preventing the UAF.
After adding ses to the smb_ses_list list, the only place where the ses is freed is in the __cifs_put_smb_ses function:
```
__cifs_put_smb_ses()
...
spin_lock(&cifs_tcp_ses_lock);
list_del_init(&ses->smb_ses_list);
spin_unlock(&cifs_tcp_ses_lock);
...
sesInfoFree(ses);
```The ses is freed only after it is removed from the list, and this removal is protected by cifs_tcp_ses_lock.
In cifs_debug_files_proc_show(), the cifs_tcp_ses_lock is still held, ensuring that during access to the ses that is about to be destroyed, the ses will not be freed in __cifs_put_smb_ses(), thus preventing a UAF issue.
```
cifs_debug_files_proc_show()
...
spin_lock(&cifs_tcp_ses_lock);
...
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list)
...
spin_lock(&cifs_tcp_ses_lock);
```Based on this understanding, I wonder if the issue addressed by this CVE might not be a genuine problem. I am also curious about the series of patches considered as fixes for this CVE.
Best regards,
Wang Zhaolong
Quoted 41 lines
Skip sessions that are being teared down (status ==
SES_EXITING) to avoid UAF.Signed-off-by Paulo Alcantara (Red Hat) <[email protected]>--- fs/smb/client/cifs_debug.c | 2 ++ fs/smb/client/cifsglob.h | 10 ++++++++++ 2 files changed, 12 insertions(+)fs/smb/client/cifs_debug.c +2
-0@@ -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) {fs/smb/client/cifsglob.h +10
-0@@ -2322,4 +2322,14 @@ struct smb2_compound_vars { struct kvec ea_iov; }; +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 */
Quoted 7 lines · Wang Zhaolong
Hello,
I have some questions regarding CVE-2024-26928.
I would like to confirm whether the phrase "fix potential UAF in
cifs_debug_files_proc_show()" implies that the UAF issue does not actually exist, correct?
Correct. This is just a way to prevent one from accessing any fields from @ses while it is being released by a different task.
Quoted 3 lines
Based on this understanding, I wonder if the issue addressed by this CVE might not be a genuine problem. I am also curious about the series of patches considered as fixes for this CVE.
Nope. The fixes were created and sent without having any related CVEs.