Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3197301pxb; Mon, 9 Nov 2020 05:22:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8m8NfdmeSzCTBVsuc03hAMd6b7jw6zsyR6rxDb7jzoSuEZKLHKxUYonWy3neV/AStRtaV X-Received: by 2002:a17:906:b150:: with SMTP id bt16mr15406686ejb.257.1604928159124; Mon, 09 Nov 2020 05:22:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928159; cv=none; d=google.com; s=arc-20160816; b=g2cHEAWHXa1Oxlrp0DzKgQCsrfuppZw912tYhg43RBK0F+n2dAt9cQV18Mfsw8n7UZ sAvDeuYfE8oo3hgJmvvmIxfMFEvTyuACTM1/LxjfT54oJB/HQqZc/ulrvJ3MkyqXJah5 w99yeQGEf8WH286yeCFJejhrUMkh42l6/FmjaxZLXBD9xNe0iL+CwJy1ArAu0lzKDuxz 8hjdYXUhgx4mK0ebrb95OxY9CEcOA7P6pmI4Qowxjpem6PrNU8pqDlCH+K5ughTlWmRs V++uXVeuQlcW2ZIr6I6DsNlrph+cE11MN2xajJxbhdwGHY6byp4HFiDoePSKpGLhZ+zo J2SA== 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=Tt9K/SS0WA7aS9Xx0s4Zf88+GQlOQlzG+QI6xwNQOwg=; b=bKyA3sIbVwJA5oip5vOvCLH8a4/WEYVID15rB+ycj9iJ/hVAJzhbCW92DHmWWiFa3F t97dE8+BV9RBUB0QOL8xfPH8r9RgEtMbXqVpkPIHB4ElABKJrIaLmzW6TQrup5TdUQXq lNFNtdezDiqnKyw7Y7RtMyrzGzG/l9UVZHbFxJdnb66QokecFdNKFaH03vGvoj1Nu5+N reYxVIe4OiBmiq3paPC6pUfllyHgSmbvsxFIA/iwUqplXkplbMHCxBG/pFAu5irLYO4s HwmxOKX/YW15RLgiIcUBB28CsnG+hJf60u1VPoS1pOx4A3685+imB7xyzNgG5O04ghBR mgUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JDpMQad6; 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 bd20si6652507edb.98.2020.11.09.05.22.16; Mon, 09 Nov 2020 05:22:39 -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=JDpMQad6; 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 S2388002AbgKINVC (ORCPT + 99 others); Mon, 9 Nov 2020 08:21:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:48716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388004AbgKINVA (ORCPT ); Mon, 9 Nov 2020 08:21:00 -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 1769A20867; Mon, 9 Nov 2020 13:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928059; bh=t/oVmvx3FKMad9dfXELoANOthvBeVY5y4WeFwh3C9Ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDpMQad6xrhpuK8juqQktQ4SJEw4WRMT5tFPtSbnjw91128pZvZRl9Rd/fNvWerQq qjKembOs1eDg8g8IUVmMk0gXNgcqTe0ITJLwepgPDhzY36fi9zBdJeejVW5BTEfFy7 fL160vWVe8VZqUcXOhm7poDW04+dg6nDfZuy/wdE= 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.9 096/133] nvme-rdma: handle unexpected nvme completion data length Date: Mon, 9 Nov 2020 13:55:58 +0100 Message-Id: <20201109125035.316518001@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@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 116902b1b2c34..3a598e91e816d 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1767,6 +1767,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