|
| 1 | +From f52056b4fdf5f43b1513168443617bd479e5233f Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Mon, 20 Jul 2026 05:56:28 +0000 |
| 4 | +Subject: [PATCH] hyperv/syndbg: check length returned by |
| 5 | + cpu_physical_memory_map() |
| 6 | + |
| 7 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 8 | +Upstream-reference: AI Backport of https://gitlab.com/qemu-project/qemu/-/commit/85af4e937016ed2f20122eb116597d1abb30c5c0.patch |
| 9 | +--- |
| 10 | + hw/hyperv/syndbg.c | 23 +++++++++++------------ |
| 11 | + 1 file changed, 11 insertions(+), 12 deletions(-) |
| 12 | + |
| 13 | +diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c |
| 14 | +index 065e12fb1..9fdec1146 100644 |
| 15 | +--- a/hw/hyperv/syndbg.c |
| 16 | ++++ b/hw/hyperv/syndbg.c |
| 17 | +@@ -189,7 +189,7 @@ static uint16_t handle_recv_msg(HvSynDbg *syndbg, uint64_t outgpa, |
| 18 | + { |
| 19 | + uint16_t ret; |
| 20 | + uint8_t data_buf[TARGET_PAGE_SIZE - UDP_PKT_HEADER_SIZE]; |
| 21 | +- hwaddr out_len; |
| 22 | ++ hwaddr out_len, out_requested_len; |
| 23 | + void *out_data; |
| 24 | + ssize_t recv_byte_count; |
| 25 | + |
| 26 | +@@ -218,29 +218,28 @@ static uint16_t handle_recv_msg(HvSynDbg *syndbg, uint64_t outgpa, |
| 27 | + if (is_raw) { |
| 28 | + out_len += UDP_PKT_HEADER_SIZE; |
| 29 | + } |
| 30 | ++ out_requested_len = out_len; |
| 31 | + out_data = cpu_physical_memory_map(outgpa, &out_len, 1); |
| 32 | +- if (!out_data) { |
| 33 | +- return HV_STATUS_INSUFFICIENT_MEMORY; |
| 34 | ++ ret = HV_STATUS_INSUFFICIENT_MEMORY; |
| 35 | ++ if (!out_data || out_len < out_requested_len) { |
| 36 | ++ goto cleanup_out_data; |
| 37 | + } |
| 38 | + |
| 39 | + if (is_raw && |
| 40 | +- !create_udp_pkt(syndbg, out_data, |
| 41 | +- recv_byte_count + UDP_PKT_HEADER_SIZE, |
| 42 | ++ !create_udp_pkt(syndbg, out_data, out_len, |
| 43 | + data_buf, recv_byte_count)) { |
| 44 | +- ret = HV_STATUS_INSUFFICIENT_MEMORY; |
| 45 | + goto cleanup_out_data; |
| 46 | + } else if (!is_raw) { |
| 47 | +- memcpy(out_data, data_buf, recv_byte_count); |
| 48 | ++ memcpy(out_data, data_buf, out_len); |
| 49 | + } |
| 50 | + |
| 51 | +- *retrieved_count = recv_byte_count; |
| 52 | +- if (is_raw) { |
| 53 | +- *retrieved_count += UDP_PKT_HEADER_SIZE; |
| 54 | +- } |
| 55 | ++ *retrieved_count = out_len; |
| 56 | + ret = HV_STATUS_SUCCESS; |
| 57 | + |
| 58 | + cleanup_out_data: |
| 59 | +- cpu_physical_memory_unmap(out_data, out_len, 1, out_len); |
| 60 | ++ if (out_data) { |
| 61 | ++ cpu_physical_memory_unmap(out_data, out_len, 1, out_len); |
| 62 | ++ } |
| 63 | + return ret; |
| 64 | + } |
| 65 | + |
| 66 | +-- |
| 67 | +2.43.0 |
| 68 | + |
0 commit comments