Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp165200pxb; Mon, 2 Nov 2020 17:28:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJybWKNuomLEErHuTaMdLXXZy6RM3c7Rgi/1n5sSrQajd+P+yUKJW3KhDiwUm4LluXJToBLT X-Received: by 2002:a17:906:3644:: with SMTP id r4mr11872537ejb.517.1604366906816; Mon, 02 Nov 2020 17:28:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604366906; cv=none; d=google.com; s=arc-20160816; b=V8bkqJm7Ftowndsg2j3K2fxdrm2PY795CSWLB/oqZOD42Xu9nNmsz39NwuxUYIEiQS tBUwjLlWBFasxI60D3lwucfqMAXE48yTojmy17fPYBPaeU/1Ab3T+7Fmz9FOn0by3mWM ta97jXtecAJcC4ehQSjUCJqunFuyqxhnOcqTvuCZTklcVbtlh9o/A/zN6vjxoqwyVTUp tSE/pX4gnJCV1q0C4YK4fynVDt8bCZeXMD4oIpzY3f3rBNLVVKrR22l4/Y/8Sq4dEyMu 6KgaQBF7lKMdUz+uMTX96VAceAlPTXJvlUJG9Q75tzWKCqfC6cysvZhkJUqwFd1+RRh8 SDow== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0k4EkNhvDfmExRrwfIQt+2WXvhwnabF3bNThzqOq8Js=; b=EjL6Xyls4FgOtxGd31+7VaEkzVyhpN+cLgEbkDwfZPDdEdxDHkgrRDe8L3MU8POrIs mqh0yc+cZRAObqaDPCWWDJ0sWI+CSoG3w7LfufdtJIxmxZxCIkL3Kem4I/ZKHLX4ImTq wn+B2wIDf6a5JRgDgYSR3zudhfLyWWMNLubVz+9PiimYxkiVbUfXEUTwdpEDPCFBW49W QSKcWzcExdNQQXduLtNm2hrCmpmslgwFMtdvWtgRo4YT/fk5dOiJ8F2SsCiTGsFsFKuR 5PpnNftkBScJWkd9Nadjx7dsoONMPgTnFec4Rs28xCaLIDEh7NXtjvogbpE3wsL93cya cJxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u3u1iTaZ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx25si9222277ejb.270.2020.11.02.17.28.04; Mon, 02 Nov 2020 17:28:26 -0800 (PST) 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=@kernel.org header.s=default header.b=u3u1iTaZ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728119AbgKCBX7 (ORCPT + 99 others); Mon, 2 Nov 2020 20:23:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:35332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728082AbgKCBUb (ORCPT ); Mon, 2 Nov 2020 20:20:31 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C37D222453; Tue, 3 Nov 2020 01:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604366430; bh=aA8e9Bb/bGjP79dUDBE23SvgQ+7Zz95nL9u23Kqa3X8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u3u1iTaZWYhCa4Pe6krjwzGcMwZqCFT5zeXISX5NUrpyGGXSHIaCX/wYIo4Usz1G1 b1ucW8uuaSIJ20PQxPEputQ7Rf/kGeQ9XNOcJC2ONfrVZkGSlIINKVGkL1so6KE92R O/hGN9Rymq0YrRECd6NuCBNJptCU8BTD3ovDpCkg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: zhenwei pi , Sagi Grimberg , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 17/24] nvme-rdma: handle unexpected nvme completion data length Date: Mon, 2 Nov 2020 20:20:00 -0500 Message-Id: <20201103012007.183429-17-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201103012007.183429-1-sashal@kernel.org> References: <20201103012007.183429-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: zhenwei pi [ Upstream commit 25c1ca6ecaba3b751d3f7ff92d5cddff3b05f8d0 ] Receiving a zero length message leads to the following warnings because the CQE is processed twice: refcount_t: underflow; use-after-free. WARNING: CPU: 0 PID: 0 at lib/refcount.c:28 RIP: 0010:refcount_warn_saturate+0xd9/0xe0 Call Trace: nvme_rdma_recv_done+0xf3/0x280 [nvme_rdma] __ib_process_cq+0x76/0x150 [ib_core] ... Sanity check the received data length, to avoids this. Thanks to Chao Leng & Sagi for suggestions. Signed-off-by: zhenwei pi Reviewed-by: Sagi Grimberg Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/rdma.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index abe4fe496d05c..cb5aecb018901 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1520,6 +1520,14 @@ static void nvme_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) return; } + /* sanity checking for received data length */ + if (unlikely(wc->byte_len < len)) { + dev_err(queue->ctrl->ctrl.device, + "Unexpected nvme completion length(%d)\n", wc->byte_len); + nvme_rdma_error_recovery(queue->ctrl); + return; + } + ib_dma_sync_single_for_cpu(ibdev, qe->dma, len, DMA_FROM_DEVICE); /* * AEN requests are special as they don't time out and can -- 2.27.0