CIFS: Do not reconnect TCP session in add_credits()
When executing add_credits() we currently call cifs_reconnect() if the number of credits is zero and there are no requests in flight. In this case we may call cifs_reconnect() recursively twice and cause memory corruption given the following sequence of functions: mid1.callback() -> add_credits() -> cifs_reconnect() -> -> mid2.callback() -> add_credits() -> cifs_reconnect(). Fix this by avoiding to call cifs_reconnect() in add_credits() and checking for zero credits in the demultiplex thread. Cc: <stable@vger.kernel.org> Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com> Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
This commit is contained in:
@@ -720,6 +720,21 @@ server_unresponsive(struct TCP_Server_Info *server)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
zero_credits(struct TCP_Server_Info *server)
|
||||
{
|
||||
int val;
|
||||
|
||||
spin_lock(&server->req_lock);
|
||||
val = server->credits + server->echo_credits + server->oplock_credits;
|
||||
if (server->in_flight == 0 && val == 0) {
|
||||
spin_unlock(&server->req_lock);
|
||||
return true;
|
||||
}
|
||||
spin_unlock(&server->req_lock);
|
||||
return false;
|
||||
}
|
||||
|
||||
static int
|
||||
cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
|
||||
{
|
||||
@@ -732,6 +747,12 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
|
||||
for (total_read = 0; msg_data_left(smb_msg); total_read += length) {
|
||||
try_to_freeze();
|
||||
|
||||
/* reconnect if no credits and no requests in flight */
|
||||
if (zero_credits(server)) {
|
||||
cifs_reconnect(server);
|
||||
return -ECONNABORTED;
|
||||
}
|
||||
|
||||
if (server_unresponsive(server))
|
||||
return -ECONNABORTED;
|
||||
if (cifs_rdma_enabled(server) && server->smbd_conn)
|
||||
|
Reference in New Issue
Block a user