From patchwork Wed Apr 7 05:46:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 1463183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=irrelevant.dk header.i=@irrelevant.dk header.a=rsa-sha256 header.s=fm2 header.b=I1QoRYLS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=CV2mpk7N; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FFYpb5GZ0z9sVb for ; Wed, 7 Apr 2021 16:07:51 +1000 (AEST) Received: from localhost ([::1]:35754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lU1Lx-0004Ik-K4 for incoming@patchwork.ozlabs.org; Wed, 07 Apr 2021 02:07:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU11j-0002EH-6X; Wed, 07 Apr 2021 01:46:55 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46047) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU11g-00057S-5y; Wed, 07 Apr 2021 01:46:54 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 022205C0117; Wed, 7 Apr 2021 01:46:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 07 Apr 2021 01:46:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=m4zssAaPDs4gc Hy6p0aY+ZOL0+f4nd8B7oTmX+tpuM0=; b=I1QoRYLScsN6uArxZP6k4XXQwWOMU zQTWdpwGOg1NjYz13yvRi8PWALxJ/C72H0JYS4rJZyaPIN9U53fMbZ4k5gZbH8ng D1I3nKNXJ6HnQQWLqIW3sWil+4rmKMGgLw7uzfggKn0e7vPE02VijIw2qOHUWy7+ UHu/9/EUDRs33fnBd+jX2CY2E5HbjOe6lgeJ8cuqjUf16tTDevemGZpbUiBy0gMI cBOrBaK7fn9hA3oFTk8NAGHHbuZSt4jZDw42KZdtEwb+aYcnDSKJKneDsgpFeGKo +ORn09ymIbc7Sv2T2gY7JR6b/cnxMLHbTap4tIfU5oyVgzXIq/pPGc9jQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=m4zssAaPDs4gcHy6p0aY+ZOL0+f4nd8B7oTmX+tpuM0=; b=CV2mpk7N CPctKjBjQ/dcahiMXbyjbsOPPDIrRU4G1u2p0Ur477Gh3ZbiCJDCEa9MtezkVJfA XewNs65tW0goZXh2uJIzsdo+Ax9AQ6hkTSC3BD2X+inQ5Pyw5h99baQCPpfO2YYt K/YzMVJodZ+xSyPqgmlQmkDTwSF1D1BLlVqpH6jsR1C9rZ0NFnvYPumzdZz7DjCY ImxVZKVqy3EqjT/YfRXhmNOP82fW40CXCSrrGGzUYOMGWJqziqLtrve4Z/AIDtOh cuQMauXy2k0POGNwb5rsMLXII2s4kU6inLvg/lK88QFopIrL4Z26uIpkkBgOv0UA A1L1X/El2a+o2A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudejiedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghu shculfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrth htvghrnhepueelteegieeuhffgkeefgfevjeeigfetkeeitdfgtdeifefhtdfhfeeuffev gfeknecukfhppeektddrudeijedrleekrdduledtnecuvehluhhsthgvrhfuihiivgepvd enucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id A059E1080063; Wed, 7 Apr 2021 01:46:49 -0400 (EDT) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PULL for-6.0 v2 08/10] hw/block/nvme: fix ns attachment out-of-bounds read Date: Wed, 7 Apr 2021 07:46:33 +0200 Message-Id: <20210407054635.189440-9-its@irrelevant.dk> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210407054635.189440-1-its@irrelevant.dk> References: <20210407054635.189440-1-its@irrelevant.dk> MIME-Version: 1.0 Received-SPF: pass client-ip=66.111.4.29; envelope-from=its@irrelevant.dk; helo=out5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Klaus Jensen , Minwoo Im , Stefan Hajnoczi , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen nvme_ns_attachment() does not verify the contents of the host-supplied 16 bit "Number of Identifiers" field in the command payload. Make sure the value is capped at 2047 and fix the out-of-bounds read. Fixes: 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command") Cc: Minwoo Im Signed-off-by: Klaus Jensen Reviewed-by: Minwoo Im --- hw/block/nvme.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index d2dd82496790..87891d4d0f3b 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -4920,6 +4920,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) return NVME_NS_CTRL_LIST_INVALID | NVME_DNR; } + *nr_ids = MIN(*nr_ids, NVME_CONTROLLER_LIST_SIZE - 1); for (i = 0; i < *nr_ids; i++) { ctrl = nvme_subsys_ctrl(n->subsys, ids[i]); if (!ctrl) {