Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp92574pxj; Mon, 17 May 2021 21:54:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynyidhMIFeKzhT0yeIVuj1kcfRe4IRl1KZ3E6Pnnq1CtKxH0ZsgnKPpysJzOfwFMaxfMcp X-Received: by 2002:a50:f695:: with SMTP id d21mr4688883edn.67.1621313681301; Mon, 17 May 2021 21:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621313681; cv=none; d=google.com; s=arc-20160816; b=d05OP8UCFWx3GmUveKHhnslmQlMxr9RmNFaMJLY9uxDFEWPyrTUVTDe4obM2ybKRbJ kjbQ0ozsfWA8qs7nDQEaK+/oF1nE44Gyq6gzzmzsMDMaCIaH5WAedfmBs5LZBwOeirxk H/lSdLO+bZNoRfbYcTcfUHbIghN2M5v5Waa3L2TXrh+7mDw1/AmJIIpPGv8jbOCPv99H gOe/q8omJ/Jo4VJD95QnCXVGxUo3Dlcxx6qDt0It9nMqyRTaEv6DvU9fgY+hh0bK/ktF h4il1ksfL24cgVyLl/kDrUn4wptTuqlNipS31OS+FT4Z5dSvrv0qASpiInAGTGsNrM79 gOhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=i6OO3i2eZVkl4Gcxbvl1mBb8OnT+OmWddXiXhiZtdbg=; b=JHMxiIX5Tup8TNX7abKjTWH78NE22cMuPXr6/K/wHBQhBcENl44aYWbKKbpZfy+Oyh NLfGhH3NHxeMJI67LvZ4zTcDAw9lprMNgIjbrY8Go9WW+PnwV2Gp2KZN7MJLmtvmFUUK ea1OT7fMQ7fsurZAIwOJgu7fF1BuXnr0EYfo0nMe+uLHlFHTSq4xlGJpGmPaC11krR72 NG2/ZsVxy16+wzYk2LnIkoxWvcdTH4v2IQQKKuCVBffJqAQeLz4ljVR1S3Km3J4UaID2 hnupxN1tf+qNjn3Rwau5SWRs9DHoyIXxNE9+TCcW+Y/xSWbuxTUv94LX8DpEOk/66ma6 Q6Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KOTn5WeY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si8526776ejb.688.2021.05.17.21.54.18; Mon, 17 May 2021 21:54:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KOTn5WeY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241272AbhEQOoD (ORCPT + 99 others); Mon, 17 May 2021 10:44:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:33968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241003AbhEQOhT (ORCPT ); Mon, 17 May 2021 10:37:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0DB8261241; Mon, 17 May 2021 14:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261058; bh=C69sFFjLTwRGrFM8sFyWi7PxzrJIrS93PYxgSNh2q44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KOTn5WeY7UUbS7F5uyhgCKJtsIWHzTPzdirXQddD9ESXD7w8E9iUf3b8c3Emqv22k ht+CZfaH+cq2JHfnNrTiyqqgMHpv8w8hW1iF3CSfnxEinDVGNTlwI67MrebeL/qzjd A2JM56+RAMS+VMsmFbLX5bHVRmSU6JQb08GyK0kw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shai Malin , Michal Kalderon , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.12 299/363] nvmet-rdma: Fix NULL deref when SEND is completed with error Date: Mon, 17 May 2021 16:02:45 +0200 Message-Id: <20210517140312.709393807@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Kalderon [ Upstream commit 8cc365f9559b86802afc0208389f5c8d46b4ad61 ] When running some traffic and taking down the link on peer, a retry counter exceeded error is received. This leads to nvmet_rdma_error_comp which tried accessing the cq_context to obtain the queue. The cq_context is no longer valid after the fix to use shared CQ mechanism and should be obtained similar to how it is obtained in other functions from the wc->qp. [ 905.786331] nvmet_rdma: SEND for CQE 0x00000000e3337f90 failed with status transport retry counter exceeded (12). [ 905.832048] BUG: unable to handle kernel NULL pointer dereference at 0000000000000048 [ 905.839919] PGD 0 P4D 0 [ 905.842464] Oops: 0000 1 SMP NOPTI [ 905.846144] CPU: 13 PID: 1557 Comm: kworker/13:1H Kdump: loaded Tainted: G OE --------- - - 4.18.0-304.el8.x86_64 #1 [ 905.872135] RIP: 0010:nvmet_rdma_error_comp+0x5/0x1b [nvmet_rdma] [ 905.878259] Code: 19 4f c0 e8 89 b3 a5 f6 e9 5b e0 ff ff 0f b7 75 14 4c 89 ea 48 c7 c7 08 1a 4f c0 e8 71 b3 a5 f6 e9 4b e0 ff ff 0f 1f 44 00 00 <48> 8b 47 48 48 85 c0 74 08 48 89 c7 e9 98 bf 49 00 e9 c3 e3 ff ff [ 905.897135] RSP: 0018:ffffab601c45fe28 EFLAGS: 00010246 [ 905.902387] RAX: 0000000000000065 RBX: ffff9e729ea2f800 RCX: 0000000000000000 [ 905.909558] RDX: 0000000000000000 RSI: ffff9e72df9567c8 RDI: 0000000000000000 [ 905.916731] RBP: ffff9e729ea2b400 R08: 000000000000074d R09: 0000000000000074 [ 905.923903] R10: 0000000000000000 R11: ffffab601c45fcc0 R12: 0000000000000010 [ 905.931074] R13: 0000000000000000 R14: 0000000000000010 R15: ffff9e729ea2f400 [ 905.938247] FS: 0000000000000000(0000) GS:ffff9e72df940000(0000) knlGS:0000000000000000 [ 905.938249] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 905.950067] nvmet_rdma: SEND for CQE 0x00000000c7356cca failed with status transport retry counter exceeded (12). [ 905.961855] CR2: 0000000000000048 CR3: 000000678d010004 CR4: 00000000007706e0 [ 905.961855] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 905.961856] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 905.961857] PKRU: 55555554 [ 906.010315] Call Trace: [ 906.012778] __ib_process_cq+0x89/0x170 [ib_core] [ 906.017509] ib_cq_poll_work+0x26/0x80 [ib_core] [ 906.022152] process_one_work+0x1a7/0x360 [ 906.026182] ? create_worker+0x1a0/0x1a0 [ 906.030123] worker_thread+0x30/0x390 [ 906.033802] ? create_worker+0x1a0/0x1a0 [ 906.037744] kthread+0x116/0x130 [ 906.040988] ? kthread_flush_work_fn+0x10/0x10 [ 906.045456] ret_from_fork+0x1f/0x40 Fixes: ca0f1a8055be2 ("nvmet-rdma: use new shared CQ mechanism") Signed-off-by: Shai Malin Signed-off-by: Michal Kalderon Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 6c1f3ab7649c..7d607f435e36 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -700,7 +700,7 @@ static void nvmet_rdma_send_done(struct ib_cq *cq, struct ib_wc *wc) { struct nvmet_rdma_rsp *rsp = container_of(wc->wr_cqe, struct nvmet_rdma_rsp, send_cqe); - struct nvmet_rdma_queue *queue = cq->cq_context; + struct nvmet_rdma_queue *queue = wc->qp->qp_context; nvmet_rdma_release_rsp(rsp); @@ -786,7 +786,7 @@ static void nvmet_rdma_write_data_done(struct ib_cq *cq, struct ib_wc *wc) { struct nvmet_rdma_rsp *rsp = container_of(wc->wr_cqe, struct nvmet_rdma_rsp, write_cqe); - struct nvmet_rdma_queue *queue = cq->cq_context; + struct nvmet_rdma_queue *queue = wc->qp->qp_context; struct rdma_cm_id *cm_id = rsp->queue->cm_id; u16 status; -- 2.30.2