From nobody Tue May 13 07:19:55 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646694288267881.9522388748062; Mon, 7 Mar 2022 15:04:48 -0800 (PST) Received: from localhost ([::1]:49570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nRMPH-0003fG-95 for importer2@patchew.org; Mon, 07 Mar 2022 18:04:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRM6b-0006YV-Jt for qemu-devel@nongnu.org; Mon, 07 Mar 2022 17:45:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nRM6Z-0005WH-TH for qemu-devel@nongnu.org; Mon, 07 Mar 2022 17:45:29 -0500 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-RSt4UaU3PB6oPZtr2yQMQA-1; Mon, 07 Mar 2022 17:45:26 -0500 Received: by mail-wm1-f72.google.com with SMTP id 187-20020a1c19c4000000b0037cc0d56524so264667wmz.2 for ; Mon, 07 Mar 2022 14:45:26 -0800 (PST) Received: from redhat.com ([2.55.138.228]) by smtp.gmail.com with ESMTPSA id u4-20020adfdb84000000b001e8d8ac5394sm13277572wri.110.2022.03.07.14.45.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 14:45:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646693127; 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=hG63fk2e7vwNR105jMKcH2PAlFDWHa3moRydXJnnvuY=; b=INIrGLXM9BPeQbOnUVxMdf9eNeZZyx3ffv3mfmzCZ8IMXwbyKo/AaXKlU0SWdMdpd7Uhs1 Dq3FKMPOTrWJ/3k6qiyVnNruTlKpyA/+ZJff3wpgbnmYmaQO91CMmDPx/XjAQ0rLcbKJSD LLmCflVrnD/r95cDVc82EtQW673JKLE= X-MC-Unique: RSt4UaU3PB6oPZtr2yQMQA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=hG63fk2e7vwNR105jMKcH2PAlFDWHa3moRydXJnnvuY=; b=A91BD/JpzaADUmbUaQ5YA14ayxAeX3gmfIhzQ+0Fp42tE7ELbFf6+zLDKggIZKwv4j KOf7vGJT8gu8HSAyz2MZMK2tLV2F7Nzy6/nqX9VDbpldikjzGjqMnEg1gx9WjPwALtFJ ZmLQkIaqd3eSrKSqu2iWc9wBKIS1yVbOBSvH7T95woLd9yk7/8fPxRqjqsv++6Z0QVCs 2YMfEpuQmQWTUald1ZLcPlWnjwyagm7Iz/E6ZFFDdp6lC6lvPvaAZQXCZluCYQKC7kuJ sCkqqFBEKFYoqfZ5yNp6SoWC/qbikNsO5p9QLSVhygNK2+luQe4WD57QDOboW9y+y6+1 OF4w== X-Gm-Message-State: AOAM530/ehea3VxxhsiSyibll1zIp+tBKpb1u4bYgwQ0Du1yLf0+p8+g ZMlGdCcYQkprxTHjJ+Q/ZuNuNnAin1i8hSxgHZaKjlWOYGco9lEodBsXo7pbru/m2SIw9wurwga W2VIuQDp/kjSom+6O9hTOg41FXACbO2Q297dSUi+w0ieI7ptp2ssePNKI3xri X-Received: by 2002:a7b:c855:0:b0:384:91d1:8120 with SMTP id c21-20020a7bc855000000b0038491d18120mr1013431wml.110.1646693124755; Mon, 07 Mar 2022 14:45:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7NjgGJQLscxD0tdfB/eYmpyLXX4U9b70fYCbkT3omrHQR0JI6WztBBvhvFM2vLMAvBJce8g== X-Received: by 2002:a7b:c855:0:b0:384:91d1:8120 with SMTP id c21-20020a7bc855000000b0038491d18120mr1013404wml.110.1646693124352; Mon, 07 Mar 2022 14:45:24 -0800 (PST) Date: Mon, 7 Mar 2022 17:45:20 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v4 16/47] hw/i386: Improve bounds checking in OVMF table parsing Message-ID: <20220307224357.682101-17-mst@redhat.com> References: <20220307224357.682101-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220307224357.682101-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Disposition: inline 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Peter Maydell , Daniel P =?utf-8?B?LiBCZXJyYW5nw6k=?= , Richard Henderson , "Dr . David Alan Gilbert" , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Dov Murik , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646694288773100001 From: Dov Murik When pc_system_parse_ovmf_flash() parses the optional GUIDed table in the end of the OVMF flash memory area, the table length field is checked for sizes that are too small, but doesn't error on sizes that are too big (bigger than the flash content itself). Add a check for maximal size of the OVMF table, and add an error report in case the size is invalid. In such a case, an error like this will be displayed during launch: qemu-system-x86_64: OVMF table has invalid size 4047 and the table parsing is skipped. Signed-off-by: Dov Murik Message-Id: <20220222071906.2632426-2-dovmurik@linux.ibm.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert --- hw/i386/pc_sysfw_ovmf.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c index f4dd92c588..df15c9737b 100644 --- a/hw/i386/pc_sysfw_ovmf.c +++ b/hw/i386/pc_sysfw_ovmf.c @@ -24,6 +24,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "hw/i386/pc.h" #include "cpu.h" =20 @@ -66,7 +67,13 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size= _t flash_size) ptr -=3D sizeof(uint16_t); tot_len =3D le16_to_cpu(*(uint16_t *)ptr) - sizeof(guid) - sizeof(uint= 16_t); =20 - if (tot_len <=3D 0) { + if (tot_len < 0 || tot_len > (ptr - flash_ptr)) { + error_report("OVMF table has invalid size %d", tot_len); + return; + } + + if (tot_len =3D=3D 0) { + /* no entries in the OVMF table */ return; } =20 --=20 MST