Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3194411pxb; Mon, 9 Nov 2020 05:18:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVn6rM2uIl0+Sl1eXQEudD9vpDMHs4PfdRVEa4hwCl/GFJP9wXEsPzCVykSOR836U1iR8Z X-Received: by 2002:aa7:cac2:: with SMTP id l2mr15379635edt.141.1604927921227; Mon, 09 Nov 2020 05:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927921; cv=none; d=google.com; s=arc-20160816; b=M6VRGrLV1zb9FbCK2a1NTm83xE+pDYQ4hisHr7GVR25BUfTSfXM7pkoKX8/3apQiD0 ds3P+1gloMmXAlHHDQTgMU5DA1JIMBcm2QRVZ6/F+MnSna+NI1OgEDzM3Qfbown8CpKb Tb9Qu8/o2kSSUJ7Bx63Q1Mia4icSMRap8r0REUAsZUdRj/8hvdeZlaaLeOp3dG4K3joo tIYFUxEHpJE2Jl5ofJ2kuX+lZVcMYMT54LiZf2bChxh3VM/Bbzi7CDBNMYx3rWOiK3nu giwJTnqGE9eFl99AVNspLDO8ehQa5EOCyPiTdGixpWrjmZQ+m1b6Pfdnn6dRBDsItVU7 aEzg== 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=Rkf/J6WfqdySTbqpd4m6ps09I09IpFAg3SoiC/RzTAU=; b=LpzaGFw6LDGoSNk8Ha4+/4xN7vonDQ2t6IUsInMcVmbrgXPXNkTnnTOosHOzozyBps mKGhCwvvtG167iKipCJy+cCl6Ot9Cz+1dnJfFXQObhZxtLKVIUYA2B0rxs/HU6a4hc62 +AwV2mMpryxGhYvgzJTfK6qCSi9yc0xvKM9/Jrxk6S2iEjEYeQKPvItDeANr/6iXR+Yv 3NzQ2okovgAJCiALyEU6ewYbT9WRyRdfrClm4B6v3BeIqSqJ1eHeSxyH55fRXmcX0yed 18tGmAsJy1YsuB5MhCLVdMbrzwyEbWgMBUHFvmxzc/d6dO0XnoQWRF8Sk3T87LQSrevh 9eKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1IVHSktG; 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=fail (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 qh16si6773256ejb.677.2020.11.09.05.18.17; Mon, 09 Nov 2020 05:18:41 -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=1IVHSktG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733066AbgKINOD (ORCPT + 99 others); Mon, 9 Nov 2020 08:14:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:40084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733036AbgKINN4 (ORCPT ); Mon, 9 Nov 2020 08:13:56 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 322FF20789; Mon, 9 Nov 2020 13:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927635; bh=spIBQukg0Em/6s7m814lEBLeDRX0DkRAJLMt+1e4/nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1IVHSktGYUcthoLqHnI7P6SxMHCaw6VbbECXLpkHrFR4vsKaXk7wZeVXgfr331rcj BCFgjMJL6qMy9ScBr0F8XmbW0GitBKC8BRj48Q7txiSJ8QG696MSqAxwrpjP1KYgdO lwRu2iggE+VqokLO2pQPFNfiksvisvL6LzOzuVEQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, zhenwei pi , Sagi Grimberg , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.4 55/85] nvme-rdma: handle unexpected nvme completion data length Date: Mon, 9 Nov 2020 13:55:52 +0100 Message-Id: <20201109125025.216501133@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125022.614792961@linuxfoundation.org> References: <20201109125022.614792961@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: 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 a41ee9feab8e7..e957ad0a07f58 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