From patchwork Wed Nov 17 13:23:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Klaus Jensen X-Patchwork-Id: 12624591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72296C433EF for ; Wed, 17 Nov 2021 13:33:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 07D9061B1E for ; Wed, 17 Nov 2021 13:33:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 07D9061B1E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=irrelevant.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:45934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnL3y-0001wZ-Tx for qemu-devel@archiver.kernel.org; Wed, 17 Nov 2021 08:33:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnKuc-00063Z-Ds; Wed, 17 Nov 2021 08:23:44 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:46681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnKuZ-0002xl-LO; Wed, 17 Nov 2021 08:23:41 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id C44085C0180; Wed, 17 Nov 2021 08:23:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 17 Nov 2021 08:23:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=fm1; bh=nkiuqszGgJsMzEQCWWDaSIsiha CyQaKhHN2sGp/IaMw=; b=HCCRxe69V1oH7UVMSC9+AteAAUzseQ0ckcykP0R04b SufH3gPRcZdXWaGt6MO94T6s+w3Bfs2t9FCcqdV/AZTCjKZB8pI6RBFevz2sQAQ2 JvG7Kjudl4DsABP8yO4QM2+OMys9VIFER+nEn1GFUAhvn1S/kMeDJj/Z12W51YoC TW3JgR6yXP5g8RFTn2DoH+8ta4728xH3SdEJRaZGmAQzvokXy0qu/2HLXO464kNF fqXi9f1N3KOPht0oAp5qiwDuvewPgM0+1PmKSQkUBhSNyLguwvzt2FF+rsahCZbu U+Dj7hIVF4In288sLXPXCib43yNVK4s2FGhHzwbPLgEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=nkiuqs zGgJsMzEQCWWDaSIsihaCyQaKhHN2sGp/IaMw=; b=Zr1y1cv00rTxHaaVYm3+So NyAgklT6yluVnIrV/9Q0xo87wPVLv8CKMElCaXGlOBTIYIFvYr38Pp1tZHpzyJfH ox5GVHHwj+kn36Htb2hijEF6plRfh2Tjele8eXnNcgkc43nG7Fh5dvezY7+WCMKP 9v1ufszVEjnlmogEv1lm7pzYlE/s5hMJnAQRyVZWubj04qlg/tzWj454MwRsMa3w jcwB169ehCsk+DOwklHbgINKq9yGvCQPPqri6Nq/oOKPWhXBY8i3F8w8QgSmsFr3 CMQKkmXzsaqHod8copAMf8dp3dDhoLQoNFoH2s8MtOafLK+QUWya09eIsaaWL0Ow == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrfeeggdegiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpefmlhgruhhsucfl vghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtthgvrh hnpefhgfdvtdetgffffefgveetgfeifefhvdejhfdvtdegffdvudfgledtudelueelhfen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehithhsse hirhhrvghlvghvrghnthdrughk X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 17 Nov 2021 08:23:36 -0500 (EST) From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH for-6.2] hw/nvme: fix buffer overrun in nvme_changed_nslist (CVE-2021-3947) Date: Wed, 17 Nov 2021 14:23:35 +0100 Message-Id: <20211117132335.41850-1-its@irrelevant.dk> X-Mailer: git-send-email 2.34.0 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, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-block@nongnu.org, Klaus Jensen , qemu-stable@nongnu.org, Qiuhao Li , Keith Busch , Klaus Jensen , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Klaus Jensen Fix missing offset verification. Cc: qemu-stable@nongnu.org Cc: Philippe Mathieu-Daudé Reported-by: Qiuhao Li Fixes: f432fdfa121 ("support changed namespace asynchronous event") Signed-off-by: Klaus Jensen Reviewed-by: Philippe Mathieu-Daudé Tested-by: Gaurav Kamathe --- Note: Since its so easy to mess this fix up, the log pages code could probably use a refactor - there is a lot of duplicated code as well and it's easy to miss a check like this. However, defer that for 7.0. hw/nvme/ctrl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 6a571d18cfae..5f573c417b3d 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -4168,6 +4168,11 @@ static uint16_t nvme_changed_nslist(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, int i = 0; uint32_t nsid; + if (off >= sizeof(nslist)) { + trace_pci_nvme_err_invalid_log_page_offset(off, sizeof(nslist)); + return NVME_INVALID_FIELD | NVME_DNR; + } + memset(nslist, 0x0, sizeof(nslist)); trans_len = MIN(sizeof(nslist) - off, buf_len);