Skip to contentSkip to conversation

cifs: fix panic in smb2_reconnect

PATCH In review Ronnie Sahlberg 2 participants 2 messages Jun 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix panic in smb2_reconnect

RH Bugzilla: 1702264

We need to protect so that the call to smb2_reconnect() in smb2_reconnect_server() does not end up freeing the session because it can lead to a use after free and crash.

---
 fs/cifs/smb2pdu.c | 3 +++
 1 file changed, 3 insertions(+)
fs/cifs/smb2pdu.c +3 -0
index 565b60b62f4d..c4f3e2403b58 100644
@@ -3116,6 +3116,7 @@ void smb2_reconnect_server(struct work_struct *work)
 		if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) {
 			list_add_tail(&ses->tcon_ipc->rlist, &tmp_list);
 			tcon_exist = true;
+			ses->ses_count++;
 		}
 	}
 	/*
@@ -3134,6 +3135,8 @@ void smb2_reconnect_server(struct work_struct *work)
 		else
 			resched = true;
 		list_del_init(&tcon->rlist);
+		if (tcon->ipc)
+			cifs_put_smb_ses(tcon->ses);
 		cifs_put_tcon(tcon);
 	}
 
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw

fs/cifs/smb2pdu.c void smb2_reconnect_server(struct work_struct *work)

Quoted 5 lines · Ronnie Sahlberg
fs/cifs/smb2pdu.c +0 -0
index 565b60b62f4d..c4f3e2403b58 100644
@@ -3116,6 +3116,7 @@ void smb2_reconnect_server(struct work_struct *work)

I would add a comment here. Something like:

    /* IPC has the same lifetime as its session and uses its
       refcount */
Quoted 8 lines
fs/cifs/smb2pdu.c +1 -0
 		if (ses->tcon_ipc && ses->tcon_ipc->need_reconnect) {
 			list_add_tail(&ses->tcon_ipc->rlist, &tmp_list);
 			tcon_exist = true;
+			ses->ses_count++;
 		}
 	}
 	/*

fs/cifs/smb2pdu.c void smb2_reconnect_server(struct work_struct *work) · line 3140

Quoted 6 lines
fs/cifs/smb2pdu.c +2 -0
@@ -3134,6 +3135,8 @@ void smb2_reconnect_server(struct work_struct *work)
 		else
 			resched = true;
 		list_del_init(&tcon->rlist);
+		if (tcon->ipc)
+			cifs_put_smb_ses(tcon->ses);
 		cifs_put_tcon(tcon);

Since cifs_put_tcon() is a noop on IPC this looks correct but I think an putting it in an "else" would make the logic clearer.

Signature · 4 lines
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97  8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)