From nobody Tue Apr 7 04:36:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1773669136; cv=none; d=zohomail.com; s=zohoarc; b=mIF/3s1JRhzMB0njCCDp+o7My6vYInIlz6Fvrb/siRlsG7FKHkEK2bzPvLszvUZcLEIh1JIhx3PSuVm9U1fcwZ/i6EPbgAIYjeWPxPvrNeXCRlD5//3Fhqcs1LqsDiwfA/t33AwtHDsi46xmYQajAGbwmyNDmyHgKxzd14DtMFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773669136; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gVayslBP5K3Rw/YvWCLXSSrNeRKQW0Mq43uyl9PyYNo=; b=EhHWylDUfObpqJTvPbiF4ywRKJKgZSlNUQVROHmK5/QJSzpfB4CWGebytSmDsNdQl+IdkdLjSa39avJNyZcWOIY4JKWGsfjWvc/BkMtslodXcnDZcZR8fDGZclOwl7v/YKDiNfNJ72KjqaBb9/GPuAUfGu0oAhQ7cvlW8Z6rfXs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773669136839846.9391404853388; Mon, 16 Mar 2026 06:52:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w28Lu-0001mR-Ug; Mon, 16 Mar 2026 09:51:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w28Lp-0001lW-8G; Mon, 16 Mar 2026 09:51:22 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w28Ln-00005G-K7; Mon, 16 Mar 2026 09:51:21 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 8EDDE193EEF; Mon, 16 Mar 2026 16:51:10 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id 222F4380939; Mon, 16 Mar 2026 16:51:14 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tls.msk.ru; s=202602; t=1773669070; bh=3CZEGJQOw2lzaKPVqbp1IGIRjHtE07Pi/JNnAkDdkhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JSYTLvzcde+wWeKzyz/TqPamZfRNuQBmR1F3t6z5OIORjW2eGDLGm27oedu2GsnSR pLJRvhmdh+QL9KDqL0WmUUDHb3GzoEgyLLSiwXmquTxw0EhyUtG6D1NVR81860Whwy 4kElMA8YqJ9D569GmGXB+VJFK7U7cNxiNnUMdszmPjc8ZKJ21yr2Lp42JblZosZzSQ wProdgO7wP3zn3lwyitc8aKYkM88nh5l48VIZ6FjDaUHAS0hL/q+VuZnAamNPeydvt sv3EdPW5vSzRkwBNEGzzI69N4FgUfEyfINfSKmjIbVnhrajf7IQm2nimCyWOX9JPyw Fa4ilI5MYBojg== From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Michael Tokarev Subject: [Stable-10.0.9 46/46] hyperv/syndbg: check length returned by cpu_physical_memory_map() Date: Mon, 16 Mar 2026 16:50:44 +0300 Message-ID: <20260316135104.119985-2-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tls.msk.ru) X-ZM-MESSAGEID: 1773669140145154100 From: Paolo Bonzini If cpu_physical_memory_map() returns a length shorter than the one that was passed into the function, writing the full out_len bytes causes an access beyond the memory allocated to the guest; or in the case of the MMIO bounce buffer, an out-of-bounds access in a heap-allocated object. Add a check similar to the one already in handle_send_msg(), and take the occasion to remove repeated computations of recv_byte_count + UDP_PKT_HEADER_SIZE and clarify that the code does not write past out_len bytes. Reported-by: Oleh Konko Reviewed-by: Daniel P. Berrang=C3=A9 Fixes: CVE-2026-3842 Signed-off-by: Paolo Bonzini (cherry picked from commit 4f28b87fdd24df2049626106b7c24d0180952115) (Mjt: context fixup for 10.0.x) Signed-off-by: Michael Tokarev diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c index d3e3917077..7137a6d0dc 100644 --- a/hw/hyperv/syndbg.c +++ b/hw/hyperv/syndbg.c @@ -189,7 +189,7 @@ static uint16_t handle_recv_msg(HvSynDbg *syndbg, uint6= 4_t outgpa, { uint16_t ret; uint8_t data_buf[TARGET_PAGE_SIZE - UDP_PKT_HEADER_SIZE]; - hwaddr out_len; + hwaddr out_len, out_requested_len; void *out_data; ssize_t recv_byte_count; =20 @@ -218,29 +218,28 @@ static uint16_t handle_recv_msg(HvSynDbg *syndbg, uin= t64_t outgpa, if (is_raw) { out_len +=3D UDP_PKT_HEADER_SIZE; } + out_requested_len =3D out_len; out_data =3D cpu_physical_memory_map(outgpa, &out_len, 1); - if (!out_data) { - return HV_STATUS_INSUFFICIENT_MEMORY; + ret =3D HV_STATUS_INSUFFICIENT_MEMORY; + if (!out_data || out_len < out_requested_len) { + goto cleanup_out_data; } =20 if (is_raw && - !create_udp_pkt(syndbg, out_data, - recv_byte_count + UDP_PKT_HEADER_SIZE, + !create_udp_pkt(syndbg, out_data, out_len, data_buf, recv_byte_count)) { - ret =3D HV_STATUS_INSUFFICIENT_MEMORY; goto cleanup_out_data; } else if (!is_raw) { - memcpy(out_data, data_buf, recv_byte_count); + memcpy(out_data, data_buf, out_len); } =20 - *retrieved_count =3D recv_byte_count; - if (is_raw) { - *retrieved_count +=3D UDP_PKT_HEADER_SIZE; - } + *retrieved_count =3D out_len; ret =3D HV_STATUS_SUCCESS; =20 cleanup_out_data: - cpu_physical_memory_unmap(out_data, out_len, 1, out_len); + if (out_data) { + cpu_physical_memory_unmap(out_data, out_len, 1, out_len); + } return ret; } =20 --=20 2.47.3