From patchwork Thu Nov 14 06:16:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 11243113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4AEA14E5 for ; Thu, 14 Nov 2019 06:17:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B637206DB for ; Thu, 14 Nov 2019 06:17:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NBn1RMv9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725838AbfKNGQ7 (ORCPT ); Thu, 14 Nov 2019 01:16:59 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23567 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725601AbfKNGQ7 (ORCPT ); Thu, 14 Nov 2019 01:16:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573712218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dRm5vJVeG6xuzO6X2C1D7bCmSL5NkYafWYfuCH/HrKI=; b=NBn1RMv9LRzQEzxlHQ2RRRJI83e8cc11v2FootNk4wyuOfXcjgTxV6p3TagGn4e63sFsBt 5qYTbMOSyKUhlNoVTqeVY7jTN9fT+92u5xPZY3yInBLbRx3arpFiptlqHTZC05l+geyTGi FUrzOEKWuAYacqrEtMGoIe4cmlOXKII= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-En-7x3m-OqaGkCuRO0QUew-1; Thu, 14 Nov 2019 01:16:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF5CE1802CE1 for ; Thu, 14 Nov 2019 06:16:55 +0000 (UTC) Received: from test1135.test.redhat.com (vpn2-54-39.bne.redhat.com [10.64.54.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65ADF5458E; Thu, 14 Nov 2019 06:16:55 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Ronnie Sahlberg Subject: [PATCH] cifs: fix race between compound_send_recv() and the demultiplex thread Date: Thu, 14 Nov 2019 16:16:46 +1000 Message-Id: <20191114061646.22122-2-lsahlber@redhat.com> In-Reply-To: <20191114061646.22122-1-lsahlber@redhat.com> References: <20191114061646.22122-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: En-7x3m-OqaGkCuRO0QUew-1 X-Mimecast-Spam-Score: 0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org 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 Reviewed-by: Pavel Shilovsky --- fs/cifs/connect.c | 1 - fs/cifs/transport.c | 2 +- 2 files changed, 1 insertion(+), 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..0f219f7653f3 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -1119,7 +1119,7 @@ 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 (is_interrupt_error(rc)) { midQ[i]->mid_flags |= MID_WAIT_CANCELLED; midQ[i]->callback = cifs_cancelled_callback; cancelled_mid[i] = true;