From nobody Mon Feb 9 00:07:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637152552; cv=none; d=zohomail.com; s=zohoarc; b=VdpHPpgwzcZ31i5ZMPfVcnIyLVwXJnzfs9rk3NA8E598wZje/tTh+2T37WvSIqjXkKRNS7pRvJEExxc8Rn1Cqyj6kgE8XX8pyCh4CJy1ghYzyOTxM3oEF6OAWd2cwqCTc9ip3Yar2tgJCC+VY8eZaN79/keKgS65HElXc9GxhbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637152552; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=oTNtSt9bkGOnttpG0XfMFr62z7chItuoyRUPlpke2UQ=; b=KrHQURf1qnQd4RLZ9fNKgaXtNV9JSQXj0mDhx2SJ1KPFx+7MkHgJHbnw/S4fnJgvI3Y8x9ZKpTZ72sXF8WbTB8ioe4O9n9N9kufng43bExOPbnfcxQwYFwRG9uejE+dWXM52AGDh3mbcAxQ0CRw+Qk/ilEtaGHD80fTz0VjCjUU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1637152552228776.9361156907797; Wed, 17 Nov 2021 04:35:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-HthrIJ8RMNaxLZRmV7nltA-1; Wed, 17 Nov 2021 07:35:47 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3947B8799F0; Wed, 17 Nov 2021 12:35:46 +0000 (UTC) Received: from x1w.redhat.com (unknown [10.40.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 664CC3AEF; Wed, 17 Nov 2021 12:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637152550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oTNtSt9bkGOnttpG0XfMFr62z7chItuoyRUPlpke2UQ=; b=Jtrm/c5y6njjMsv0W4KZDNmWbp0cKFvLEDekgRNYMTAUSSpFJYHii2AYrxwEcaxsU6dr6E yYF3qAA0AWyb5cIlZ/AaCjACRvkD0PkoJakl4a25k7pro7F8BEylxUg5E8jegvbaH+YvNp n8R1q7hfZU593djafuh6PEbRAUXz+6Y= X-MC-Unique: HthrIJ8RMNaxLZRmV7nltA-1 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Gaurav Kamathe , Qiuhao Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH-for-6.2 v2 1/2] hw/nvme/ctrl: Fix buffer overrun in nvme_changed_nslist (CVE-2021-3947) Date: Wed, 17 Nov 2021 13:35:33 +0100 Message-Id: <20211117123534.2900334-2-philmd@redhat.com> In-Reply-To: <20211117123534.2900334-1-philmd@redhat.com> References: <20211117123534.2900334-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637152554604100001 Both 'buf_len' and 'off' arguments are under guest control. Since nvme_c2h() doesn't check out of boundary access, the caller must check for eventual buffer overrun on 'trans_len'. Cc: qemu-stable@nongnu.org Reported-by: Qiuhao Li Fixes: f432fdfa121 ("support changed namespace asynchronous event") Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/nvme/ctrl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 6a571d18cfa..93a24464647 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -4168,8 +4168,11 @@ static uint16_t nvme_changed_nslist(NvmeCtrl *n, uin= t8_t rae, uint32_t buf_len, int i =3D 0; uint32_t nsid; =20 - memset(nslist, 0x0, sizeof(nslist)); trans_len =3D MIN(sizeof(nslist) - off, buf_len); + if (trans_len >=3D sizeof(nslist)) { + return NVME_INVALID_FIELD | NVME_DNR; + } + memset(nslist, 0x0, sizeof(nslist)); =20 while ((nsid =3D find_first_bit(n->changed_nsids, NVME_CHANGED_NSID_SI= ZE)) !=3D NVME_CHANGED_NSID_SIZE) { --=20 2.31.1 From nobody Mon Feb 9 00:07:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637152557; cv=none; d=zohomail.com; s=zohoarc; b=aVyOhAVQG6f1o4HIsNJiDG7N2Vd2FV5DApuEvNf0o50tFNSqZZClo1q5t4aVY2INGcqWZugDE+qlGrXMp/5n+EwqZJHWt2/3zWq+v3uaDuodCCDHg4P1MZAbkcOX2X3TxB/r3913A6nLmqcrOkG5oU4hWSYLaUZxRvB/1cqNH6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637152557; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=hG+zgZUdKXWa/bANnargnjTKA5tMtHkSKP2FF2wC/84=; b=AKtaTbhbVPQhJGG5cqjUTIp6e/wqupaZC6kay7OIl2a+6CDMHoXTDYLKrtMyl7wZSlWQJUYCO+AudwWmHN/fvmJPcClhOYgmhMZPZDO8v0vSI3KtDR3Cbs+n2Jc23y37KCp/hr9Gm2NrfEv+nxFPzCgOSiDBzHNuNeqF27a6IMA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637152557877958.2384424846535; Wed, 17 Nov 2021 04:35:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-bfdrSBfiMraRWUGTCuP4_g-1; Wed, 17 Nov 2021 07:35:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CC5E802C8F; Wed, 17 Nov 2021 12:35:50 +0000 (UTC) Received: from x1w.redhat.com (unknown [10.40.192.245]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 072533AEF; Wed, 17 Nov 2021 12:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637152556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hG+zgZUdKXWa/bANnargnjTKA5tMtHkSKP2FF2wC/84=; b=Ra0Bld19r29cTDxayU0Q3i+sCGlY0So6bRlETZjLs6XNSZic67O29ftPmZs2hKi3GzkzTj Zs5POQLyaN3p6K3u+EzU7RxinZkAmGwHCF879CXlB58nxaiLCBaZohv8KR4u+p1gry2p9N PiJZSWQce0AfbEW59fMuiYFTA3LzAHI= X-MC-Unique: bfdrSBfiMraRWUGTCuP4_g-1 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Keith Busch , Klaus Jensen , qemu-block@nongnu.org, Gaurav Kamathe , Qiuhao Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH-for-6.2 v2 2/2] hw/nvme/ctrl: Prevent buffer overrun in nvme_error_info() Date: Wed, 17 Nov 2021 13:35:34 +0100 Message-Id: <20211117123534.2900334-3-philmd@redhat.com> In-Reply-To: <20211117123534.2900334-1-philmd@redhat.com> References: <20211117123534.2900334-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637152559308100001 Both 'buf_len' and 'off' arguments are under guest control. Since nvme_c2h() doesn't check out of boundary access, the caller must check for eventual buffer overrun on 'trans_len'. Cc: qemu-stable@nongnu.org Fixes: 94a7897c41d ("add support for the get log page command") Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/nvme/ctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 93a24464647..7414f3b4dd1 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -4146,7 +4146,8 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t = rae, uint32_t buf_len, uint32_t trans_len; NvmeErrorLog errlog; =20 - if (off >=3D sizeof(errlog)) { + trans_len =3D MIN(sizeof(errlog) - off, buf_len); + if (trans_len >=3D sizeof(errlog)) { return NVME_INVALID_FIELD | NVME_DNR; } =20 @@ -4155,7 +4156,6 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t = rae, uint32_t buf_len, } =20 memset(&errlog, 0x0, sizeof(errlog)); - trans_len =3D MIN(sizeof(errlog) - off, buf_len); =20 return nvme_c2h(n, (uint8_t *)&errlog, trans_len, req); } --=20 2.31.1