Linux-CIFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/1] cifs: fix race between compound_send_recv() and the demultiplex thread
@ 2019-11-14  1:42 Ronnie Sahlberg
  2019-11-14  1:42 ` [PATCH] " Ronnie Sahlberg
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2019-11-14  1:42 UTC (permalink / raw)
  To: linux-cifs

List, Pavel

Here is a small patch that fixes another race where we leak a handle on an interrupted open()
Please review.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] cifs: fix race between compound_send_recv() and the demultiplex thread
  2019-11-14  1:42 [PATCH 0/1] cifs: fix race between compound_send_recv() and the demultiplex thread Ronnie Sahlberg
@ 2019-11-14  1:42 ` " Ronnie Sahlberg
  0 siblings, 0 replies; 2+ messages in thread
From: Ronnie Sahlberg @ 2019-11-14  1:42 UTC (permalink / raw)
  To: linux-cifs; +Cc: Ronnie Sahlberg

There is a race where the open() may be interrupted between when we receive the reply
but before we have invoked the callback in which case we never end up calling
handle_cancelled_mid() and thus leak an open handle on the server.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/connect.c   | 1 -
 fs/cifs/transport.c | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index ccaa8bad336f..802604a7e692 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1223,7 +1223,6 @@ cifs_demultiplex_thread(void *p)
 			if (mids[i] != NULL) {
 				mids[i]->resp_buf_size = server->pdu_size;
 				if ((mids[i]->mid_flags & MID_WAIT_CANCELLED) &&
-				    mids[i]->mid_state == MID_RESPONSE_RECEIVED &&
 				    server->ops->handle_cancelled_mid)
 					server->ops->handle_cancelled_mid(
 							mids[i]->resp_buf,
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index ca3de62688d6..28018a7eccb2 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -1119,7 +1119,8 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
 				 midQ[i]->mid, le16_to_cpu(midQ[i]->command));
 			send_cancel(server, &rqst[i], midQ[i]);
 			spin_lock(&GlobalMid_Lock);
-			if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) {
+			if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED ||
+			    midQ[i]->mid_state == MID_RESPONSE_RECEIVED) {
 				midQ[i]->mid_flags |= MID_WAIT_CANCELLED;
 				midQ[i]->callback = cifs_cancelled_callback;
 				cancelled_mid[i] = true;
-- 
2.13.6


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-14  1:42 [PATCH 0/1] cifs: fix race between compound_send_recv() and the demultiplex thread Ronnie Sahlberg
2019-11-14  1:42 ` [PATCH] " Ronnie Sahlberg

Linux-CIFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-cifs/0 linux-cifs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-cifs linux-cifs/ https://lore.kernel.org/linux-cifs \
		linux-cifs@vger.kernel.org
	public-inbox-index linux-cifs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-cifs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git