From nobody Fri Dec 19 19:07:30 2025 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1663609803; cv=none; d=zohomail.com; s=zohoarc; b=O+5K5GqaW+UQACGuyS5TLrXhNdnQufY4Habe2z9KK9WN5z+Noj3PCPTo++8fgBeUOYTvT2Qevm1NTdfVqaL/yk5OTDgOQ+C8KKXE8bzkT5EeV9W5+vbpTAYBu36uA7ab8Cij6tJJSQzV0YbqOV1qJxPZokfRJOEeYTZ5TFEN9cU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663609803; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=LPmkvFFnw4l1tMXKx8/IyCKxy4gYtSCDr8RggRRaD2zb3CiCz5A47FHJoz1Wybtt++51EWuxfDhxYbDvlpj+tJZKLHO7UeFfoLg9DBMFpMtJJxf72BHqRbXr00MlJVh93+Yy+oV0GPUT5SRyqF8F6K9NHwyqp/iatNxZd2uNJKc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1663609803813332.82056837029427; Mon, 19 Sep 2022 10:50:03 -0700 (PDT) Received: from localhost ([::1]:40886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oaKuA-0000wh-JV for importer@patchew.org; Mon, 19 Sep 2022 13:50:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaKfm-0002xS-L5 for qemu-devel@nongnu.org; Mon, 19 Sep 2022 13:35:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:28286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oaKfl-00034C-0R for qemu-devel@nongnu.org; Mon, 19 Sep 2022 13:35:10 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-601-42QQCsFEO9eGu1yc3sZ30A-1; Mon, 19 Sep 2022 13:35:06 -0400 Received: by mail-wr1-f69.google.com with SMTP id i27-20020adfaadb000000b0022a48b6436dso26372wrc.23 for ; Mon, 19 Sep 2022 10:35:06 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id q17-20020adff951000000b00228dff8d975sm14414592wrr.109.2022.09.19.10.35.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 10:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663608908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=BKcPdo8Da+hjX9IrIIy2k5ZPhWC8IgnhNg9tSG2P7VeNyVOXZKsTTF+SULOeujf7sZB5+y 190FFUrSL3xsXsce0BQfUrIq4ZSL9rX49WnjCgJZWIw0UW1pRnSYHYDCybwIIoi8Ed8uHz 59kOYqjEeUK8gLE4QMqg8ACBtAdrouI= X-MC-Unique: 42QQCsFEO9eGu1yc3sZ30A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=CW74wzCEIOR9BqZ2vemjjTjhKKwJj/fzW0jc/QsP3Vk+syIyFrKpRqMbKnuPVpZKsA ALTlrRvkLdw+gSdVRXMmxu0t8wL/yRdZ9aGomJPeyPSZ2CV0Qz7IRzi5nToOn/BNK8w8 OsKniBqrQGdFXbDVXrbZS2M48EATPsjtrN1gsD2JyMjVF/6wlGFqGRbNIatdiEANit5M 5eoM7R4CVtpxAcBuboajTcZ/VzUFjEyY64aGdnhbCMmwNPfz/RXLxkHfZn2CXXXG8/8a cdkvCwNtJKZxPDo1ozXRStYnlKesBYI20COgkUNDBttws7WlXGodcDlptTSiarOGUQTl w88w== X-Gm-Message-State: ACrzQf23qtbe2HG+O1XUyCw0h7gJmsNQSYAJnXKJzmdOcRyalpPE7wu1 XvUhw8N9o+yk80jlxnZhIanDbs4e9Qvmtvi5ovmufUoTTCprRDu4QjHAobAgwWLOowRmO7ll1II RBMUJsFYvSSgbQbfNYIBmko1CUlJrO/8WVmY4gLASj8x9df8gXpfjNwi1QYsDQZw47pc= X-Received: by 2002:a05:600c:4f11:b0:3b4:bf6c:4566 with SMTP id l17-20020a05600c4f1100b003b4bf6c4566mr10945367wmq.34.1663608905436; Mon, 19 Sep 2022 10:35:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5V2Gv4EBPUWJXWTiHqoGEid7AQNvsK5zsgOLJ7qKgniHueC+xtazw+vg3aFZg3drmXOai8XA== X-Received: by 2002:a05:600c:4f11:b0:3b4:bf6c:4566 with SMTP id l17-20020a05600c4f1100b003b4bf6c4566mr10945357wmq.34.1663608905148; Mon, 19 Sep 2022 10:35:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/21] smbios: sanitize type from external type before checking have_fields_bitmap Date: Mon, 19 Sep 2022 19:34:35 +0200 Message-Id: <20220919173449.5864-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220919173449.5864-1-pbonzini@redhat.com> References: <20220919173449.5864-1-pbonzini@redhat.com> MIME-Version: 1.0 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1663609805357100001 Content-Type: text/plain; charset="utf-8" test_bit uses header->type as an offset; if the file incorrectly specifies a type greater than 127, smbios_entry_add will read and write garbage. To fix this, just pass the smbios data through, assuming the user knows what to do. Reported by Coverity as CID 1487255. Signed-off-by: Paolo Bonzini --- hw/smbios/smbios.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 60349ee402..4c9f664830 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -1205,13 +1205,15 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) return; } =20 - if (test_bit(header->type, have_fields_bitmap)) { - error_setg(errp, - "can't load type %d struct, fields already specifie= d!", - header->type); - return; + if (header->type <=3D SMBIOS_MAX_TYPE) { + if (test_bit(header->type, have_fields_bitmap)) { + error_setg(errp, + "can't load type %d struct, fields already spec= ified!", + header->type); + return; + } + set_bit(header->type, have_binfile_bitmap); } - set_bit(header->type, have_binfile_bitmap); =20 if (header->type =3D=3D 4) { smbios_type4_count++; --=20 2.37.2