From nobody Mon Feb 9 23:39:30 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