Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp657683pxj; Tue, 18 May 2021 11:10:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8Uo5fftNzOk0NYD6+awcdDCTgPFaxybWrzaYXOf5dzvkCHPqDPLTHdoSIjbeZ6bvzWgQY X-Received: by 2002:a6b:7901:: with SMTP id i1mr5349843iop.41.1621361439404; Tue, 18 May 2021 11:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621361439; cv=none; d=google.com; s=arc-20160816; b=j2c7h6q5ESGjz8sT6zR/8r1W3welJex1l1nF4W04uYCYybRghrerqXSO+ffZ+Aq8kQ 3XPwBfsTyIETxKg1NBT8Zt96nPreSUj/iDp9Ri8WJqNJQ8tCKUiRcCpkqOqyiMfaeJKw 0gPlg6/wXdm3jLXzmNIojsE3fbRJdcVPMSm9dsL24kQ58ibFP8lBasCacAzY1RyHrqDS 6cnjjtm9hP0TYYsn13eovH33+Jw6CchUWH1h6Ozq916gq7Id90WEqNF6vmMjV9TFStCH Uha/XAnvipd9Fn1luwx6J6ptDw3s4Oq0OLSdyPPJnbdTEZDBByJhEjXf5MrTNFJPxPtO wjAQ== 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=NGhUsF0wnUVbtZPetCvEJz3Y4/cN+vMl48OxllgO3ZgQpscPcrZrZTT/MEgQ9hCPs3 vSYyrkbwuFVV5KKjE/iKqkCtvD56bpfoE2RiiEOZDV7yzcuhpLoXJwlexjV6aK2Bf6sj zyfVWbmoWpgIYzV1UewHcK5CJUIbIzzEcrkh+EyLu+V6mWa5pGDBK2ecJCLoAWnpizsi 3mNyjqEoiuvf7Za9+sRG6BopSK0AJFm4hlTZNgLempBwrnOsRHUg/KcYRvEHf7uc83Bo llg2xnwcXb1VSlwSCxXSWfTTA4DEIbFS3SLSVXms/ZO9OVj+6Z1j9g8qGYlTUYRvsZZ4 mf5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fXNMirdC; 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 g5si21533257ilq.106.2021.05.18.11.10.27; Tue, 18 May 2021 11:10:39 -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=fXNMirdC; 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 S1343596AbhEQQL1 (ORCPT + 99 others); Mon, 17 May 2021 12:11:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:35552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244960AbhEQPsN (ORCPT ); Mon, 17 May 2021 11:48:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B7DC61956; Mon, 17 May 2021 14:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262699; bh=C69sFFjLTwRGrFM8sFyWi7PxzrJIrS93PYxgSNh2q44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXNMirdC84hxg1uWZflst9Yp47k5c6fLw8VGTZM7ck4rfPG9SYu4G8SY60L1fbBVj FDBmHE3QRV7Hq2Ntv8T/MRAEx68FaW8ljvB8K2Eqmx/ZLiicPszKeK0U3LZlODbr0y t6OthgiqMsUTOBXSay6gOiBRgAZgeZ1T7dSZEp8M= 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.10 233/289] nvmet-rdma: Fix NULL deref when SEND is completed with error Date: Mon, 17 May 2021 16:02:38 +0200 Message-Id: <20210517140313.022095467@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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