Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1018363ybe; Wed, 4 Sep 2019 11:13:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGzuk+Y5BbHhHbGhzaNJJx2cOWvRQ40h1dWuFohQjlkLGxdeyT296hR3hE/h25Qm1ZK6q7 X-Received: by 2002:a62:ce0e:: with SMTP id y14mr48006517pfg.73.1567620786399; Wed, 04 Sep 2019 11:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620786; cv=none; d=google.com; s=arc-20160816; b=WIB/cfR68JArTM4HEuayLz/15umXKps8gX099kegztHY1Tv+NWfveErcVasbMWWJ26 pXFayUwtKvXrLRYI+7mv7COxTEdJ19z/7grYabjfRKHLbPZ5qqpLedjgQF/ErzuoDf2D HjcTw/ceG1u775KEKDw4Yk1jkM6CkuqBCsEyqlqfBQeZmEbcEK14XaspJEFQi7yyuKkE Ho3FuTTZXiMW9BNeas2+WKPBMWOWOwMZAWpMz3z4RX3kut+bGin61REmjHAO/M2mT94D ef7AF20U8ZRdld6kziGKN2iCsUWC6VH2MSIPJDV1zYP+FrYKgW88C6rh0qX+3IsLKlnW Wgnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xgiI4Xz/OyyUf8HpMsvjZ3SRYamg8amuNNGUM240EDo=; b=nicZVDrkfF1nFBaeC1YVPXGIu/OWNoNK/YZnCq56cm3KehUr1i4fane4TNW8F9TwAj IyR04A0qBKjwGTun59SS7/QFZj72WDskEcY898mdEG9aOIJ6prK1EyiOIGpX8HS3z7LY 6dWEgaFAOhBBegFeeWaYaMy04mtxUwrsRvRRoiWdepn3Zj1JSSyC5mULbKxJrnWiorRo v9jhmN5jPtizaJEQD7yeggTEklwTHqv/d2dsxudvl6RwgSY0gk1JhvgEvLRynkS6vPS7 ZR3Ar7gKtwW4MGXSa2qkE56fd5YnffkS+hYdWrDLeMG/vH1DOp1RdwIGDNcyUpjvq1Sq 9JmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QyEGRJIy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si17179430plm.44.2019.09.04.11.12.50; Wed, 04 Sep 2019 11:13:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QyEGRJIy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390159AbfIDSKr (ORCPT + 99 others); Wed, 4 Sep 2019 14:10:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:54490 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389617AbfIDSKp (ORCPT ); Wed, 4 Sep 2019 14:10:45 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 900A5206BA; Wed, 4 Sep 2019 18:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620644; bh=fPNZG9WKMOZtVaDyshIrE+uSyVM8MIhCmI3WBe5ukfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QyEGRJIyixC0xxUiQecBF/PRa7syajk2akSvd5x4Ck/GPH81r/cVQY6Q4yEnykd1P CEvYeFFtS4FzAyVlxDMC4UFZGBdauMhc9E1vpBrrqZWE5nTzGUA0tu8xFWeJ3Ua7Q6 yji6Whp8uDbIu2qYUU0tRK5BGESlgvbufjlPunRM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Morey-Chaisemartin , Max Gurtovoy , Hannes Reinecke , Sagi Grimberg , Sasha Levin Subject: [PATCH 5.2 014/143] nvme-rdma: fix possible use-after-free in connect error flow Date: Wed, 4 Sep 2019 19:52:37 +0200 Message-Id: <20190904175314.652104086@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit d94211b8bad3787e0655a67284105f57db728cb1 ] When start_queue fails, we need to make sure to drain the queue cq before freeing the rdma resources because we might still race with the completion path. Have start_queue() error path safely stop the queue. -- [30371.808111] nvme nvme1: Failed reconnect attempt 11 [30371.808113] nvme nvme1: Reconnecting in 10 seconds... [...] [30382.069315] nvme nvme1: creating 4 I/O queues. [30382.257058] nvme nvme1: Connect Invalid SQE Parameter, qid 4 [30382.257061] nvme nvme1: failed to connect queue: 4 ret=386 [30382.305001] BUG: unable to handle kernel NULL pointer dereference at 0000000000000018 [30382.305022] IP: qedr_poll_cq+0x8a3/0x1170 [qedr] [30382.305028] PGD 0 P4D 0 [30382.305037] Oops: 0000 [#1] SMP PTI [...] [30382.305153] Call Trace: [30382.305166] ? __switch_to_asm+0x34/0x70 [30382.305187] __ib_process_cq+0x56/0xd0 [ib_core] [30382.305201] ib_poll_handler+0x26/0x70 [ib_core] [30382.305213] irq_poll_softirq+0x88/0x110 [30382.305223] ? sort_range+0x20/0x20 [30382.305232] __do_softirq+0xde/0x2c6 [30382.305241] ? sort_range+0x20/0x20 [30382.305249] run_ksoftirqd+0x1c/0x60 [30382.305258] smpboot_thread_fn+0xef/0x160 [30382.305265] kthread+0x113/0x130 [30382.305273] ? kthread_create_worker_on_cpu+0x50/0x50 [30382.305281] ret_from_fork+0x35/0x40 -- Reported-by: Nicolas Morey-Chaisemartin Reviewed-by: Max Gurtovoy Reviewed-by: Hannes Reinecke Signed-off-by: Sagi Grimberg Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 97f668a39ae1c..7b074323bcdf2 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -562,13 +562,17 @@ out_destroy_cm_id: return ret; } +static void __nvme_rdma_stop_queue(struct nvme_rdma_queue *queue) +{ + rdma_disconnect(queue->cm_id); + ib_drain_qp(queue->qp); +} + static void nvme_rdma_stop_queue(struct nvme_rdma_queue *queue) { if (!test_and_clear_bit(NVME_RDMA_Q_LIVE, &queue->flags)) return; - - rdma_disconnect(queue->cm_id); - ib_drain_qp(queue->qp); + __nvme_rdma_stop_queue(queue); } static void nvme_rdma_free_queue(struct nvme_rdma_queue *queue) @@ -607,11 +611,13 @@ static int nvme_rdma_start_queue(struct nvme_rdma_ctrl *ctrl, int idx) else ret = nvmf_connect_admin_queue(&ctrl->ctrl); - if (!ret) + if (!ret) { set_bit(NVME_RDMA_Q_LIVE, &queue->flags); - else + } else { + __nvme_rdma_stop_queue(queue); dev_info(ctrl->ctrl.device, "failed to connect queue: %d ret=%d\n", idx, ret); + } return ret; } -- 2.20.1