From nobody Wed May 22 01:51:36 2024 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=1662410694; cv=none; d=zohomail.com; s=zohoarc; b=H+ireLRaWBDlW4CIuTYiZ1XAdSaYeppaDTf/Ku//yviLdgiMUgca1Db1Dd3z7xvzue0xePajEumgqBTlSzAzFZoiukNa+37DthD0AE7iT9Z1OmlvxVwtXR9waMpaZCLl34ScAiYo6e7+TDrV283p78MZrbt7R+LmNBdAPM+H2b4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662410694; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=Q3vWtKrtdyqI5A6vhDNd+PXfLFOde/fLOM+YOrpH6w+HS+XTB/70bclMx9x5BTGVRr+9uZ3OpUhBTkrV6iSvJs2NV+fMEMjYaC7eW/JCkxlQdYP9pWLDwiLYlhL7ydFeWa0lulGK3LtL3HJPE68uCqMknH2S92fKZf2j2k1EYKY= 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 1662410694303103.30830073224365; Mon, 5 Sep 2022 13:44:54 -0700 (PDT) Received: from localhost ([::1]:43904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVIxh-0000TY-6Q for importer@patchew.org; Mon, 05 Sep 2022 16:44:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVIwo-00087j-EM for qemu-devel@nongnu.org; Mon, 05 Sep 2022 16:43:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32035) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVIwk-0007Xh-EZ for qemu-devel@nongnu.org; Mon, 05 Sep 2022 16:43:55 -0400 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-423-a3dDsnqMNTysM2vwPrZMhA-1; Mon, 05 Sep 2022 16:43:52 -0400 Received: by mail-ed1-f71.google.com with SMTP id t13-20020a056402524d00b0043db1fbefdeso6283041edd.2 for ; Mon, 05 Sep 2022 13:43:51 -0700 (PDT) Received: from goa-sendmail ([93.56.160.208]) by smtp.gmail.com with ESMTPSA id qt14-20020a170906ecee00b00728f6d4d0d7sm5534560ejb.67.2022.09.05.13.43.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 13:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662410633; 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; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=baraXIX8pOy5fPsIBWn/K9sJn8TaFOEn6g/nfMD8xxhXLBzYMG9hCuETcwZNNvfCoUC9cy mcZHx4fUCyeB3AGsTHPFcB6VzdNfTZl5MY09JLDmyZsx/4k7USwugHcXNGaiX6r1SvbKwG KEgfHzUgxghu2CIqpaooS9wSk++Z+jg= X-MC-Unique: a3dDsnqMNTysM2vwPrZMhA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=7fpYBjqvol9brkWwCpmEHRs0UL23HHBLAFtYFzWhwIU=; b=XmQmqy+qWW8aBAXwXakKIKL3X+3VuAo9l1N3VJbYdvo7RhzitCLHRgflOq5XOJfCXe bdm9dMw9J8IYuBktwHUHg6/hf8FzXAbSiIHY5dC6g7ntuuBeVYH4fc5DOzGg3wxWZHo/ b/+d3oc1BBynoqU/xofjBVVvR6JoGD1rwjouZLwQdLg7W0Vl81XZuS3lbUqDiot3yWOF fETxdQl0ZJsqP1Jn4kNbw/gAXf23inteKiKORHFxKAM7CF4ykmUCzaWRRPQMftaU+Lz9 C4nHLgzw66PIFFV1OYgpzSPQIL3tkWBd7TYZhWQEgj6XU1BIfcKLDyCBKsANdGnwu/Gr KZ4A== X-Gm-Message-State: ACgBeo0dal0qE3abRot+3wnd7OCBCTdmllK3+x7kvT3m9hiH8j3mymTz valaeD/Ogvc7RhErI1OLgVQkwyp6D00O8TdRICr+hsS6pMvSEaI2Nz3H+WrbF0PqAF9BrnZAAhm iVS7EZawtrRMLzh96+ASQJraneeJInYpwjnLBOVSg35JdtYXO8UUaVsXdiSo1hQX05rA= X-Received: by 2002:a17:906:5a42:b0:73d:b160:af0d with SMTP id my2-20020a1709065a4200b0073db160af0dmr37071877ejc.164.1662410630729; Mon, 05 Sep 2022 13:43:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6BjztZAg2+9/5DGmpSiyc+ZRnKnHkVUnSBljrbwQLW2/TEpVZqzD9mbNRRGkTpB1imrggWtg== X-Received: by 2002:a17:906:5a42:b0:73d:b160:af0d with SMTP id my2-20020a1709065a4200b0073db160af0dmr37071865ejc.164.1662410630381; Mon, 05 Sep 2022 13:43:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2] smbios: sanitize type from external type before checking have_fields_bitmap Date: Mon, 5 Sep 2022 22:43:49 +0200 Message-Id: <20220905204349.102405-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.2 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, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662410695696100001 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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