Skip to contentSkip to conversation

cifs: fix panic in smb2_reconnect

PATCH In review Ronnie Sahlberg 3 participants 3 messages Jun 5, 2019 – Jun 11, 2019

Subsystems (3)
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 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +9 -1
index 565b60b62f4d..ab8dc73d2282 100644
@@ -3113,9 +3113,14 @@ void smb2_reconnect_server(struct work_struct *work)
 				tcon_exist = true;
 			}
 		}
+		/*
+		 * IPC has the same lifetime as its session and uses its
+		 * refcount.
+		 */
 		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,7 +3139,10 @@ void smb2_reconnect_server(struct work_struct *work)
 		else
 			resched = true;
 		list_del_init(&tcon->rlist);
-		cifs_put_tcon(tcon);
+		if (tcon->ipc)
+			cifs_put_smb_ses(tcon->ses);
+		else
+			cifs_put_tcon(tcon);
 	}
 
 	cifs_dbg(FYI, "Reconnecting tcons finished\n");
Signature · 1 line
2.13.6
#1 lore raw

tentatively merged into cifs-2.6.git for-next (and to the github tree for next buildbot run)

Quoted 48 lines · Ronnie Sahlberg

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 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +9 -2
index 565b60b62f4d..ab8dc73d2282 100644
@@ -3113,9 +3113,14 @@ void smb2_reconnect_server(struct work_struct *work)
                                tcon_exist = true;
                        }
                }
+               /*
+                * IPC has the same lifetime as its session and uses its
+                * refcount.
+                */
                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,7 +3139,10 @@ void smb2_reconnect_server(struct work_struct *work)
                else
                        resched = true;
                list_del_init(&tcon->rlist);
-               cifs_put_tcon(tcon);
+               if (tcon->ipc)
+                       cifs_put_smb_ses(tcon->ses);
+               else
+                       cifs_put_tcon(tcon);
        }
 
        cifs_dbg(FYI, "Reconnecting tcons finished\n");
--

2.13.6

Signature · 3 lines
Thanks,

Steve
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ronnie Sahlberg

вт, 4 июн. 2019 г. в 17:16, Ronnie Sahlberg <[email protected]>:

Quoted 46 lines

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 | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +9 -2
index 565b60b62f4d..ab8dc73d2282 100644
@@ -3113,9 +3113,14 @@ void smb2_reconnect_server(struct work_struct *work)
                                tcon_exist = true;
                        }
                }
+               /*
+                * IPC has the same lifetime as its session and uses its
+                * refcount.
+                */
                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,7 +3139,10 @@ void smb2_reconnect_server(struct work_struct *work)
                else
                        resched = true;
                list_del_init(&tcon->rlist);
-               cifs_put_tcon(tcon);
+               if (tcon->ipc)
+                       cifs_put_smb_ses(tcon->ses);
+               else
+                       cifs_put_tcon(tcon);
        }
 
        cifs_dbg(FYI, "Reconnecting tcons finished\n");
--
Quoted 2 lines

2.13.6

--
Best regards,
Pavel Shilovsky