From nobody Sat Sep 26 20:00:17 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1788793178; cv=none; d=zohomail.com; s=zohoarc; b=LWkv6tjA4gLL/QQB2vTZBhVutZZmiE7+jMWyQjMitjXxYyQnXxovo1+26DV14ch1vaLcrlWPVINUGCc/vbffjLdTmVAIHxcEulQwfuwTVQqvfgt3xa1k/Po3VgFfnRkOnnOwwgV9iyNJ/VlL7hhvUqS/sZ4h/duACOeGimjmW9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788793178; 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=bvPXE8g/apTypGq/sMMTB6yOGdKYamBM905yKoKLsp8=; b=Qh0HU4MoKWmDqXAPQE7kKLlbiTgWyDNznoa7y8V5jaFu0ud7Z7vptInP46mtif1LbrsLeBJfALNXxCav0KUiRJtTewKZFdUPemZ+k/Iiv8YCT5QNf6Lg2kk3xfcBJLt5i8zgI2UkPVuMDn/4jfYXY/ncqKDE74PlDYN+PMICEZ0= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788793178014334.9809000983324; Mon, 7 Sep 2026 07:59:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3aoO-0004BU-3O; Mon, 07 Sep 2026 10:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x3aoL-0004AG-8O for qemu-devel@nongnu.org; Mon, 07 Sep 2026 10:59:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x3aoJ-0001v4-DZ for qemu-devel@nongnu.org; Mon, 07 Sep 2026 10:59:04 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-x3YqbzLnO2ijSThIrc7WpA-1; Mon, 07 Sep 2026 10:59:01 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-482f763db88so2069458f8f.2 for ; Mon, 07 Sep 2026 07:59:01 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([151.29.41.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-485883927a3sm22547547f8f.11.2026.09.07.07.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2026 07:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788793142; 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=bvPXE8g/apTypGq/sMMTB6yOGdKYamBM905yKoKLsp8=; b=Z9i4cMUJ06d6STvNXaEr/nycHoWm+ezZkoF74rAfhIpYlRih3nWVHeV/6xze8AX69PKCmz +mcR/W7Du9U9+DjVihkN8WHnBdr3oQymPmYD9RDvX99FIYmZIeCOPM2wHOtuq45ZTC3lnc SPPEBb86h9304uWZokQHqLChG23O8Lo= X-MC-Unique: x3YqbzLnO2ijSThIrc7WpA-1 X-Mimecast-MFC-AGG-ID: x3YqbzLnO2ijSThIrc7WpA_1788793140 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1788793140; x=1789397940; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bvPXE8g/apTypGq/sMMTB6yOGdKYamBM905yKoKLsp8=; b=QnMSCGxiLlrs+kkedFSqsW7rXQD4J0uiEYEbPMXpkyr/RjIhbY9xG/cXY2KIcBw/22 ymrFvX5+uP7j3bY7ov4UU8tYA5k+p4HKhpDb0aEdAxSkIbQUutOfViTAOZ2iIBecyxp2 H3FKvcS94FKcFWkUbwMsbr+iy0hPkeJz0JT5qDVcXRBJzhsituADHKf5DwdorYRWocWj PH0arp1kICC18YYYoKVtY0RJKbbjXumk6RD49f+5a9QEYCX2mJACpW6Tah1yG7BCJNBb 0WymeLR6A0RYFJxWmUs7qO4lPaWVSDWE1qXPC+DFoCgCF4KEnPz7TQJloH3xL8Kqlp5e FuLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788793140; x=1789397940; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bvPXE8g/apTypGq/sMMTB6yOGdKYamBM905yKoKLsp8=; b=fwZen7opsWfwWVBs8WBzOUGHg6JkpAGx2lPS2T+H5O0/a73Z2npyjv0W4L0QTTVLaz 1+Hv7tNwUxKnOKJFyaweJei9fZ02yTw3aaviduIEyHepxsKqcQR7GW91kPjkfmaKXDtN BeDADOkh4nJW/x4/tIpLA81jtBRZGx5iSVZNxokMuSI7armDfk/AZFBwtGPKUEFZzID9 bif79xl5vxu/UqaibR571T6mO73MDeEh0Me99XIVHtHKcYzo44rhp+xAoISSzGaviyqR DhIm0OgC2ZVKyWW7aUxk759GqTvWsHQ+A3om4Mbm9qo1o67hLQlgA8NARjfNpPUjI1eT wdCw== X-Gm-Message-State: AFuF++k8yT0OPIDo9pqOWfW/nzmzK9rrxnfAFUPQ3aOFM/PSgybUW1vi /ZH9jl5PL7cCpdBEWyl2DQw3EXXf5n/zk/Fe6XRzXC1a7YjvAx87xzwR8FPBMVbnjUD63oe2lrQ 1gMsLH3R/S1d2iHiWB2s4QGHBdEx4lYSGaJ8fbIsNYkTZn8O/5LMmsZnl X-Gm-Gg: AYBFou2tzi2lB1h7jevYfj1HE9EAgBoFxud5vuZxini+NMKErDGfLl6JTygSDyQ+zOJ whkGZn8Ml5Fn4gREfDsbT86a+ZwqdUFPCiZJCkOp8eL7TPd647k/wkg5LYXD3xRjmT4Pq6Gbv1H /Y3IKX8e+kdk5T8RRToDemTdivDflIOxB0cGxYEnZsnkUj4wnZ8LcayPenqqfmWApBSGcDeW/WB cFGI24JSNu+h2wk7+zd1D5CDUqdgFqUGgxdVUXUIEpXhwTFc0P4KN4d8JEu4zdQLjnBd/6kwZX7 qPdNv5pdBvSKWSAYP9CSvWbyhrTV9WvUbjD42pNq3+1JN0dDV2z7bgD5YQv6gWAszi7GPpcKj3X 2iGbWc5xQnf1InNlKznr2NXw/Fx1OzyxutnI9G5uOKQgxstJbWdyUVqlGe97YFlLdcMHL X-Received: by 2002:a05:600c:a40f:b0:49c:fa21:e74b with SMTP id 5b1f17b1804b1-49cfa21e9a7mr157863315e9.33.1788793140390; Mon, 07 Sep 2026 07:59:00 -0700 (PDT) X-Received: by 2002:a05:600c:a40f:b0:49c:fa21:e74b with SMTP id 5b1f17b1804b1-49cfa21e9a7mr157862925e9.33.1788793139932; Mon, 07 Sep 2026 07:58:59 -0700 (PDT) From: Luigi Leonardi Date: Mon, 07 Sep 2026 16:58:55 +0200 Subject: [PATCH v3 1/2] igvm: validate byte_offset before using it in parameter directives MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260907-fix_offset-v3-1-bcffcefc0985@redhat.com> References: <20260907-fix_offset-v3-0-bcffcefc0985@redhat.com> In-Reply-To: <20260907-fix_offset-v3-0-bcffcefc0985@redhat.com> To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Stefano Garzarella , Ani Sinha , Paolo Bonzini , Zhao Liu , qemu-stable@nongnu.org, Luigi Leonardi X-Mailer: b4 0.14.3 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=leonardi@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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: 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 @redhat.com) X-ZM-MESSAGEID: 1788793179980158500 None of the directive handlers that place data at a byte_offset within a parameter area validated that byte_offset actually falls within the parameter area's size. A malformed IGVM file with byte_offset > size would underflow the "size - byte_offset" computation used to determine remaining space, wrapping to a huge value and defeating the size check, then write out of bounds through param_entry->data + byte_offset. Add qigvm_get_param_data(), which looks up the parameter area, checks byte_offset against its size, and returns the offset-adjusted data pointer directly (NULL on failure), with the remaining space returned via an output parameter, instead of the raw QIgvmParameterData entry. This keeps the byte_offset arithmetic in one place instead of repeating param_entry->data + byte_offset and param_entry->size - byte_offset at every call site. Use it in the vp-count and environment-info handlers, adding an explicit check that the fixed-size write fits in the remaining space. Signed-off-by: Luigi Leonardi --- backends/igvm.c | 70 +++++++++++++++++++++++++++++++++++---= ---- include/system/igvm-internal.h | 6 ++++ 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/backends/igvm.c b/backends/igvm.c index 7b7bdc72b7..a8340d7d55 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -101,6 +101,39 @@ qigvm_find_param_entry(QIgvm *igvm, uint32_t parameter= _area_index, return NULL; } =20 +/* + * Look up a parameter area and check that param->byte_offset falls within + * it, in one step. On success, returns the offset-adjusted write location + * within the parameter area and sets *param_size to the remaining space + * there, so callers never need to touch param->byte_offset themselves. + * Returns NULL on failure. + */ +uint8_t * +qigvm_get_param_data(QIgvm *igvm, uint32_t parameter_area_index, + const IGVM_VHS_PARAMETER *param, + uint32_t *param_size, + Error **errp) +{ + QIgvmParameterData *param_entry; + + assert(param_size); + + param_entry =3D qigvm_find_param_entry(igvm, parameter_area_index, err= p); + if (!param_entry) { + return NULL; + } + + if (param->byte_offset > param_entry->size) { + error_setg(errp, + "IGVM: byte_offset 0x%x exceeds parameter area size 0x%= x", + param->byte_offset, param_entry->size); + return NULL; + } + + *param_size =3D param_entry->size - param->byte_offset; + return param_entry->data + param->byte_offset; +} + static int qigvm_directive_page_data(QIgvm *ctx, const uint8_t *header_dat= a, Error **errp); static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_da= ta, @@ -682,17 +715,25 @@ static int qigvm_directive_vp_count(QIgvm *ctx, const= uint8_t *header_data, Error **errp) { const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; - QIgvmParameterData *param_entry; + uint8_t *param_data; + uint32_t param_size; uint32_t *vp_count; CPUState *cpu; =20 - param_entry =3D qigvm_find_param_entry(ctx, - param->parameter_area_index, errp= ); - if (param_entry =3D=3D NULL) { + param_data =3D qigvm_get_param_data(ctx, param->parameter_area_index, + param, ¶m_size, errp); + if (!param_data) { return -1; } =20 - vp_count =3D (uint32_t *)(param_entry->data + param->byte_offset); + if (sizeof(*vp_count) > param_size) { + error_setg(errp, + "IGVM: vp-count parameter exceeds parameter area " + "defined in IGVM file"); + return -1; + } + + vp_count =3D (uint32_t *)param_data; *vp_count =3D 0; CPU_FOREACH(cpu) { @@ -707,17 +748,24 @@ static int qigvm_directive_environment_info(QIgvm *ct= x, Error **errp) { const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; - QIgvmParameterData *param_entry; + uint8_t *param_data; + uint32_t param_size; IgvmEnvironmentInfo *environmental_state; =20 - param_entry =3D qigvm_find_param_entry(ctx, - param->parameter_area_index, errp= ); - if (param_entry =3D=3D NULL) { + param_data =3D qigvm_get_param_data(ctx, param->parameter_area_index, + param, ¶m_size, errp); + if (!param_data) { + return -1; + } + + if (sizeof(*environmental_state) > param_size) { + error_setg(errp, + "IGVM: environment-info parameter exceeds parameter are= a " + "defined in IGVM file"); return -1; } =20 - environmental_state =3D - (IgvmEnvironmentInfo *)(param_entry->data + param->byte_offset); + environmental_state =3D (IgvmEnvironmentInfo *)param_data; environmental_state->memory_is_shared =3D 1; =20 return 0; diff --git a/include/system/igvm-internal.h b/include/system/igvm-internal.h index 9e9fa1d9af..f5ee2d5b1b 100644 --- a/include/system/igvm-internal.h +++ b/include/system/igvm-internal.h @@ -81,4 +81,10 @@ QIgvmParameterData* qigvm_find_param_entry(QIgvm *igvm, uint32_t parameter_area_index, Error **errp); =20 +uint8_t * +qigvm_get_param_data(QIgvm *igvm, uint32_t parameter_area_index, + const IGVM_VHS_PARAMETER *param, + uint32_t *param_size, + Error **errp); + #endif --=20 2.55.0 From nobody Sat Sep 26 20:00:17 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1788793188; cv=none; d=zohomail.com; s=zohoarc; b=lmhrwClED95TIFWSH8cBcQcEtZMNaYWEb4VYC7XCXiR2RrLLgThH0e4lX18BOrf8QQd1IXIpOXP2BQJGAZ4K8717R7uIZR1x8MIqcQacqNU0EkUNbOViFAa/0K4HRLv+7H/71H/AJMAPmEZWwK0OFacHofrY0dgSHlbqjmkhGLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788793188; 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=ftcsARFbiXjTmIJ9OJxvuV/GsHCDBtGRAys02DaiBsQ=; b=HC1RHFc4O0PyDs62XoAU11yLbPxrVVpzhCjxznypX178FRYlRFMyNGWA2TgAzTbtrYkBEXfAUcOzVrZVyEn9E3iFu/CEDtEEtp4GKbMJ1CYX2daHr8+rjPqvZ63gqcg1+fCQk4Z+lTy2ug6cOwAckg3qYcJoIuiHoVt/GX8ZByE= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1788793188539908.7045163227996; Mon, 7 Sep 2026 07:59:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x3aoN-0004BP-HV; Mon, 07 Sep 2026 10:59:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x3aoM-0004AR-BG for qemu-devel@nongnu.org; Mon, 07 Sep 2026 10:59:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x3aoK-0001vJ-J6 for qemu-devel@nongnu.org; Mon, 07 Sep 2026 10:59:06 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-HkfgMQH7NViT3f6T8IKuUg-1; Mon, 07 Sep 2026 10:59:02 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4994aebe932so46800195e9.3 for ; Mon, 07 Sep 2026 07:59:02 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([151.29.41.106]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-485883927a3sm22547547f8f.11.2026.09.07.07.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2026 07:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788793143; 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=ftcsARFbiXjTmIJ9OJxvuV/GsHCDBtGRAys02DaiBsQ=; b=Cn87+H/XazLUdspGCVnuzQ+QsISUkPlSbQyjoNYeei6K3vN4FPSfLcvcQWz+kKorQvNlly fXCBSQeN+q2j7DnsifrJRufOXppmwS2ULE/1QGXBxx1KtREoBylXG1cZDNkvAusvbGfRES phF79+Wz7ttLmTiDJ5hDuran3IbyTtE= X-MC-Unique: HkfgMQH7NViT3f6T8IKuUg-1 X-Mimecast-MFC-AGG-ID: HkfgMQH7NViT3f6T8IKuUg_1788793141 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1788793141; x=1789397941; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ftcsARFbiXjTmIJ9OJxvuV/GsHCDBtGRAys02DaiBsQ=; b=QHQx8we+U95tTsfyd6ee4VP8QBFf6CCiwR0+Jhx59FXXAA5U/HutwPliqQok5YjTut AQ3UEThY+X5FRhMMmg2RqSF4X0fpMhswhAWVpXoYFZk2ZFK4lo7YSRUSUUb5zyXG0x7K UhavJBML75sp0lgPBwnz25kLMcQgYTPdfdInGhuZ/BBPYD5LxyLkSTKAcR0CUwD+FHO8 slqOUj8bn9fQNBYfiXZVACmV5Syi6GRJuGVSECujA9IfZOOMcien3b6Tq18d1Bzsoql5 hsLewg83C5FZuMzX/5rwInJ6RPb9lQgB/Pmbpw7NX7Pr++Aiy3sax8RVB7OQqzF6E86H xwkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788793141; x=1789397941; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ftcsARFbiXjTmIJ9OJxvuV/GsHCDBtGRAys02DaiBsQ=; b=MUfJWL5Fq4wUv1vhDWSYBPOYeEzlxRtTRhKslws6Uzgr4DP3M90IYqHf09v6tfEv+5 /obh7dzlohkLWjBYAKwk/zY3HLR7iSHnHzjH882VtED/YZSomdUndwlmUOS82YFxLkIw ubhooijLq9RuiLmZrv6aNoM6CquDsDManq/+QsjsR0Q/TbJ9u61vaCema21+kd82zzUu QG4l8TA/JRPSXGJJbaP0vTHoBK64m+j0rgG3ypJu1v7nXyO0snZDW+y13F2WwutFZLlT lItjX/8R4yB0+Qnl/JpB8It0/Pb66NaQIQJCs79eJta8gLobVZyauiNpMc8NQAEYc5J4 l/Mw== X-Gm-Message-State: AFuF++mLZAMQfExVQARMtYiX6HKA8syFX0plknvtv1rNa4pnB+sFtJKy PSLmRgqTMmyWaiuXs1h2gQmTh5HwYsMGIAALHgWfWJTXKRW69RcfeACSL2AZq5QqaE/quWVEMUx 5iFp/ygEgF2gBJfLw6MkcI22vUyr2W5g8QqdfgCaQ37snbwZSz/GYe4Lt X-Gm-Gg: AYBFou3ol5DDKa17BM3RbA3DaeKa8h7f3qavgaY7ory/mY8A37Kbl48eyCxsjag4vi4 52+ufHDbSDqXkVzoOzxIEAgBheQAFA1jjbZ8Fd4lABwxOk/XryVfSQMFS2HmWCj5iCYRM5eVN8B IollYrCLE/ysasljWW9YTHecWgPM5n95iWAqgviLDec25r3l9QiCb1rjVzPa6B6Pw4Ttdopwz0v oeyYjJFmsoQlhdI4ZUEwFvl5jSnCiLioyeUu/TAB1EFrAbynNSaJNWTQlTub45iHG8HRvgB/AUG T/4F6Urog/YzvHpOWRWrAJGatOZjVc0kyt9vnPJZtjp9/H8IdE3FX6w1y4t0i7n3MtkD6ySAq87 pxUcmiYKe/l0z5+q3mxv5sxe5+l3VdHwEF9qHf5PcZKytvryRIf6mZIRnzHMyA7WIrcnI X-Received: by 2002:a05:6000:4694:b0:47f:6f9e:1e82 with SMTP id ffacd0b85a97d-4858704ad0amr35615723f8f.9.1788793141504; Mon, 07 Sep 2026 07:59:01 -0700 (PDT) X-Received: by 2002:a05:6000:4694:b0:47f:6f9e:1e82 with SMTP id ffacd0b85a97d-4858704ad0amr35615664f8f.9.1788793141100; Mon, 07 Sep 2026 07:59:01 -0700 (PDT) From: Luigi Leonardi Date: Mon, 07 Sep 2026 16:58:56 +0200 Subject: [PATCH v3 2/2] igvm: honor byte_offset when writing memory map, MADT and device tree MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260907-fix_offset-v3-2-bcffcefc0985@redhat.com> References: <20260907-fix_offset-v3-0-bcffcefc0985@redhat.com> In-Reply-To: <20260907-fix_offset-v3-0-bcffcefc0985@redhat.com> To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Stefano Garzarella , Ani Sinha , Paolo Bonzini , Zhao Liu , qemu-stable@nongnu.org, Luigi Leonardi X-Mailer: b4 0.14.3 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=leonardi@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1788793191834154100 qigvm_directive_memory_map(), qigvm_directive_madt() and qigvm_directive_device_tree() all wrote their data unconditionally at the start of the parameter area's buffer, ignoring param->byte_offset from the IGVM_VHS_PARAMETER header. This is harmless when a directive's offset happens to be 0, but breaks for IGVM files that pack multiple parameters into a single shared parameter area at different offsets: a later directive would overwrite the data written by an earlier one at the start of the buffer, corrupting it. Switch these handlers to qigvm_get_param_data(), introduced in the previous patch, and use the offset-adjusted data pointer it returns and the remaining size it sets instead of writing at param_entry->data and sizing checks against param_entry->size directly. This both honors byte_offset and validates it against the parameter area size before it is used. Fixes: c1d466d267 ("backends/igvm: Add IGVM loader and configuration") Fixes: dea1f68a5c ("igvm: Fill MADT IGVM parameter field on x86_64") Fixes: 1c4bd8f13c ("igvm: add device tree parameter support") Signed-off-by: Luigi Leonardi --- backends/igvm.c | 26 ++++++++++++++------------ target/i386/igvm.c | 13 +++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/backends/igvm.c b/backends/igvm.c index a8340d7d55..b3ff6cba4a 100644 --- a/backends/igvm.c +++ b/backends/igvm.c @@ -638,7 +638,8 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const= uint8_t *header_data, const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; int (*get_mem_map_entry)(int index, ConfidentialGuestMemoryMapEntry *e= ntry, Error **errp) =3D NULL; - QIgvmParameterData *param_entry; + uint8_t *param_data; + uint32_t param_size; int max_entry_count; int entry =3D 0; IGVM_VHS_MEMORY_MAP_ENTRY *mm_entry; @@ -659,14 +660,14 @@ static int qigvm_directive_memory_map(QIgvm *ctx, con= st uint8_t *header_data, } =20 /* Find the parameter area that should hold the memory map */ - param_entry =3D qigvm_find_param_entry(ctx, - param->parameter_area_index, errp= ); - if (param_entry =3D=3D NULL) { + param_data =3D qigvm_get_param_data(ctx, param->parameter_area_index, + param, ¶m_size, errp); + if (!param_data) { return -1; } =20 - max_entry_count =3D param_entry->size / sizeof(IGVM_VHS_MEMORY_MAP_ENT= RY); - mm_entry =3D (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data; + max_entry_count =3D param_size / sizeof(IGVM_VHS_MEMORY_MAP_ENTRY); + mm_entry =3D (IGVM_VHS_MEMORY_MAP_ENTRY *)param_data; =20 retval =3D get_mem_map_entry(entry, &cgmm_entry, errp); while (retval =3D=3D 0) { @@ -862,12 +863,13 @@ static int qigvm_directive_device_tree(QIgvm *ctx, co= nst uint8_t *header_data, { const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; g_autofree void *fdt_packed =3D NULL; - QIgvmParameterData *param_entry; + uint8_t *param_data; + uint32_t param_size; uint32_t fdt_size; =20 - param_entry =3D qigvm_find_param_entry(ctx, - param->parameter_area_index, errp= ); - if (param_entry =3D=3D NULL) { + param_data =3D qigvm_get_param_data(ctx, param->parameter_area_index, + param, ¶m_size, errp); + if (!param_data) { return -1; } =20 @@ -885,14 +887,14 @@ static int qigvm_directive_device_tree(QIgvm *ctx, co= nst uint8_t *header_data, } =20 fdt_size =3D fdt_totalsize(fdt_packed); - if (fdt_size > param_entry->size) { + if (fdt_size > param_size) { error_setg(errp, "IGVM: device tree size exceeds parameter area" " defined in IGVM file"); return -1; } =20 - memcpy(param_entry->data, fdt_packed, fdt_size); + memcpy(param_data, fdt_packed, fdt_size); =20 return 0; } diff --git a/target/i386/igvm.c b/target/i386/igvm.c index ad9bf87761..6ae662b033 100644 --- a/target/i386/igvm.c +++ b/target/i386/igvm.c @@ -187,20 +187,21 @@ void qigvm_x86_bsp_reset(CPUX86State *env) int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **e= rrp) { const IGVM_VHS_PARAMETER *param =3D (const IGVM_VHS_PARAMETER *)header= _data; - QIgvmParameterData *param_entry; + uint8_t *param_data; + uint32_t param_size; int result =3D 0; =20 /* Find the parameter area that should hold the MADT data */ - param_entry =3D qigvm_find_param_entry(ctx, - param->parameter_area_index, errp= ); - if (param_entry =3D=3D NULL) { + param_data =3D qigvm_get_param_data(ctx, param->parameter_area_index, + param, ¶m_size, errp); + if (!param_data) { return -1; } =20 GArray *madt =3D acpi_build_madt_standalone(ctx->machine_state); =20 - if (madt->len <=3D param_entry->size) { - memcpy(param_entry->data, madt->data, madt->len); + if (madt->len <=3D param_size) { + memcpy(param_data, madt->data, madt->len); } else { error_setg( errp, --=20 2.55.0