From nobody Tue Apr 23 15:40:01 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599578500; cv=none; d=zohomail.com; s=zohoarc; b=MmDaA+t9mE/ZBT2brmhF8NYB/1SnGM66bEj8T762aJ632sT5rQDFd2dp9GFra0TUIo4nt1UPD0UcW6atSMc1dp+XLeeyYy4gGk8pShWOT6lQQwxibNYT4sw5dpD9xajfN9Fcy0gJr+Dac6HoG0ART3DgCGvzzK2mor1fy64LyG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599578500; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:To; bh=u2sP78uvavrXyP/mf9YkKfSSAoCjOfmXNZuFrIHyfDI=; b=HAHT6BEcmiNIVlAB82jsqbwOwYdCcUzYx7THaAlN6bnNw0f2GJ3isQ7V2+HczJKNpzgqccL9ffk1nV87mS+FV3bw7bqdxkYVnnoXx8CE0nOl5m7n+sj6WxYkP1W3xEahfYQ6Ldv4ITt91DcX7zGwzGp4ibTWpSYe9rBiKbAN/ok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 78.46.105.101 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1599578500799868.274526114117; Tue, 8 Sep 2020 08:21:40 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 08FE410C004E; Tue, 8 Sep 2020 15:21:36 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id D351A10C0045 for ; Tue, 8 Sep 2020 15:21:16 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-292-LBxrcHw0M3mQ_49f4XjS-Q-1; Tue, 08 Sep 2020 11:21:13 -0400 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA7F318C5206 for ; Tue, 8 Sep 2020 15:21:12 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37C7319C4F; Tue, 8 Sep 2020 15:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599578475; 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; bh=AfREGtnA5uHEpdYGU0B6+BQvOZLcSdYm9j3Q28PZqWQ=; b=EM18fyrIaaqxoLPyuRLvh01jP8HOMi3zNbDpmYJqW8kyn8VMZ0zu8ZjrtGOvC9ykwiEx3e od7xgSRgkv7o3YTULlD1QFn7QNK1gOXo1unXTOIC7CX7MzwRYUAt8obI/spqvTRJu/Pudo rGzXAmINpbSzASNRhZVWs5B9dPFAHVw= X-MC-Unique: LBxrcHw0M3mQ_49f4XjS-Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: seabios@seabios.org Date: Tue, 8 Sep 2020 16:21:03 +0100 Message-Id: <20200908152103.987849-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3EMIOY6YS6MG5UQN3JJJS2A3DJZOVFR6 X-Message-ID-Hash: 3EMIOY6YS6MG5UQN3JJJS2A3DJZOVFR6 X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-Mailman-Version: 3.3.2b1 Precedence: list Subject: [SeaBIOS] [PATCH] smbios: avoid integer overflow adding SMBIOS type 0 table List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: -- X-ZohoMail-DKIM: fail (Header signature does not verify) SeaBIOS implements the SMBIOS 2.1 entry point which is limited to a maximum length of 0xffff. If the SMBIOS data received from QEMU is large enough, then adding the type 0 table will cause integer overflow. This results in fun behaviour such as a KVM crash, or hangs in SeaBIOS. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- src/fw/biostables.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fw/biostables.c b/src/fw/biostables.c index 0c07833..794b5be 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -462,10 +462,16 @@ smbios_romfile_setup(void) /* common case: add our own type 0, with 3 strings and 4 '\0's */ u16 t0_len =3D sizeof(struct smbios_type_0) + strlen(BIOS_NAME) + strlen(VERSION) + strlen(BIOS_DATE) + 4; - ep.structure_table_length +=3D t0_len; - if (t0_len > ep.max_structure_size) - ep.max_structure_size =3D t0_len; - ep.number_of_structures++; + if (t0_len > (0xffff - ep.structure_table_length)) { + dprintf(1, "Insufficient space (%d bytes) to add SMBIOS type 0= table (%d bytes)\n", + 0xffff - ep.structure_table_length, t0_len); + need_t0 =3D 0; + } else { + ep.structure_table_length +=3D t0_len; + if (t0_len > ep.max_structure_size) + ep.max_structure_size =3D t0_len; + ep.number_of_structures++; + } } =20 /* allocate final blob and record its address in the entry point */ --=20 2.26.2 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org