Received: by 2002:ac2:4c26:0:0:0:0:0 with SMTP id u6csp334097lfq; Wed, 23 Sep 2020 03:43:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuyNtUksHTFJkEVtcm5sJ9PObX/KLeNHQ/7SG8veP2w4D/HOVP7wK+gHq29riVfXTlVDuk X-Received: by 2002:a25:6041:: with SMTP id u62mr14069063ybb.70.1600857831989; Wed, 23 Sep 2020 03:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600857831; cv=none; d=google.com; s=arc-20160816; b=vrorR5zFxFwkGnA0No7caeSIStyoiFYipCVDecWOL/GeBIleRG4alMOY7363pAXIqs fYIarhzwj9a5t8A5Mb8ILIg8jnVBsWIz1EVrXNYFI3DVKGjTJjxrPce9PfRL8cJaj11T QAccEbzYC7GjDODxAkZNQBKfs407jYp/NqZwr4sTZ5+phjt2geX2KTi6utiee5hnx2NJ 8bW7pk8VblXHNDlmi5G7UWWEt+0+LGCjPdjdS/ndY37HPQ9eRPbDr30rbKusofIVgKa5 rDPcfQjD3h0RKfcmWDvYKJvN+9jLrtEt0UsTcpeFZsxqhrSbS+qgCypBW0ObwRPAPg8m te8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Phgc4cmO3ruvrymUHH88m7f0AQy1BCw/bV6mMezeXhc=; b=O2yM2+Es5CfMDI9KrxfAm5uHCjRNSKM5HZeEfQa9LRm+NlzudsHlFF/nQHgvZ3p11V mP+dGYToMX7SS9L7H4CtuAwL5V5jRXUCXxrfGVAypJGkidHTYMZsovD3KGCOFM5KjQCy /gnLshOPxEBxaNGJaliavWAIjPzx54LwmJ3kF5YG2Fdh4yW02RCL4N4xjhd+wbMoL7Xg 586fUpvnafb4WRKFxf9CpWIjPVSP0N3dBZD5loISbgpYUjBLR64Luk9AnVwEQQMjE5TH PvIw6OP78nMktqQHc7p7geT4MVLy70DxS4jF5ZlmAjnTwUeztVefZVImh4cjgp/uFd+I K5EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=cyxrZjgD; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g6si20906783ybk.4.2020.09.23.03.43.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Sep 2020 03:43:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=cyxrZjgD; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:46980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kL2Fb-0001WT-Do for alex.bennee@linaro.org; Wed, 23 Sep 2020 06:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kL2DM-00085D-80 for qemu-arm@nongnu.org; Wed, 23 Sep 2020 06:41:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60865) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kL2DI-0006xY-Gf for qemu-arm@nongnu.org; Wed, 23 Sep 2020 06:41:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600857686; 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=Phgc4cmO3ruvrymUHH88m7f0AQy1BCw/bV6mMezeXhc=; b=cyxrZjgD0dH0HkM87q7eabdnAfHl84J4wpefdWoy8KCKzjgKbVq5CHkWcmADKGuVfvdn6b SLBOhwjRf8vh+O91J74hyG5KzAxO1JJlQCYgC23tF2oSqlQDPxaYq5ph/hDcbueV0o8Uvf Fqtrd1gxdHl9mqrqMLbr4EckIbelO/g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-4wht2beYNFGWIDv3DRZiRA-1; Wed, 23 Sep 2020 06:41:22 -0400 X-MC-Unique: 4wht2beYNFGWIDv3DRZiRA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7CAF9393B6; Wed, 23 Sep 2020 10:41:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-73.ams2.redhat.com [10.36.114.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D4021002C03; Wed, 23 Sep 2020 10:41:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] hw/smbios: report error if table size is too large Date: Wed, 23 Sep 2020 11:41:01 +0100 Message-Id: <20200923104102.2068416-3-berrange@redhat.com> In-Reply-To: <20200923104102.2068416-1-berrange@redhat.com> References: <20200923104102.2068416-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=63.128.21.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/23 00:53:58 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-arm@nongnu.org, Marcel Apfelbaum , Paolo Bonzini , Igor Mammedov , Laszlo Ersek , Richard Henderson Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: HPmpBdGGaNwW The SMBIOS 2.1 entry point uses a uint16 data type for reporting the total length of the tables. If the user passes -smbios configuration to QEMU that causes the table size to exceed this limit then various bad behaviours result, including - firmware hangs in an infinite loop - firmware triggers a KVM crash on bad memory access - firmware silently discards user's SMBIOS data replacing it with a generic data set. Limiting the size to 0xffff in QEMU avoids triggering most of these problems. There is a remaining bug in SeaBIOS which tries to prepend its own data for table 0, and does not check whether there is sufficient space before attempting this. Reviewed-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Daniel P. Berrangé --- hw/smbios/smbios.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 8450fad285..3c87be6c91 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -365,6 +365,13 @@ static void smbios_register_config(void) opts_init(smbios_register_config); +/* + * The SMBIOS 2.1 "structure table length" field in the + * entry point uses a 16-bit integer, so we're limited + * in total table size + */ +#define SMBIOS_21_MAX_TABLES_LEN 0xffff + static void smbios_validate_table(MachineState *ms) { uint32_t expect_t4_count = smbios_legacy ? @@ -375,6 +382,13 @@ static void smbios_validate_table(MachineState *ms) expect_t4_count, smbios_type4_count); exit(1); } + + if (smbios_ep_type == SMBIOS_ENTRY_POINT_21 && + smbios_tables_len > SMBIOS_21_MAX_TABLES_LEN) { + error_report("SMBIOS 2.1 table length %zu exceeds %d", + smbios_tables_len, SMBIOS_21_MAX_TABLES_LEN); + exit(1); + } } -- 2.26.2