From nobody Tue Nov 18 19:45:37 2025 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611948683; cv=none; d=zohomail.com; s=zohoarc; b=lVhF+Pn4cYNO4j9/iPjFhhOVUY41Qmr+JXbfWkdFOZNIXevrot/3Qtgf1JmAeUXEtnoADDB9Pxzg8r0uWtT3lyVjL0jGYPhAwgJaOJlNstzyi0E9h4HLeGFJ8YTwR00Z6r7S1/pJPAhYzx2T6dC4sW2OEbZkBKiRKjL7w2P22Mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611948683; h=Content-Transfer-Encoding:Cc: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=AzYhMXskdJJjtZLtwvwFrwykEA7TzJv7brNc4V8DwwQ=; b=HVh8vpXzmXncqh2pPhDGqqgYWY29ba1ytwzrXYonjL5o8cQixIxs7PnkFm4QGCXV//NfPWQvAZ5a4vm3r4FS8AroW4c0KV7Ni+3psuxGhMer1US2Kqx6cC9Qc0WnWfwuKsIrRqa217ubnLaftT62IBw8o3vGu4ykt4LeBl+vpxI= ARC-Authentication-Results: i=1; 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+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16119486836441.4291506794845645; Fri, 29 Jan 2021 11:31:23 -0800 (PST) Received: from localhost ([::1]:44074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5ZUI-0000c6-DO for importer@patchew.org; Fri, 29 Jan 2021 14:31:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5ZRl-0007iB-6U for qemu-devel@nongnu.org; Fri, 29 Jan 2021 14:28:45 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:40184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5ZRj-00074r-9H for qemu-devel@nongnu.org; Fri, 29 Jan 2021 14:28:44 -0500 Received: by mail-wr1-x42b.google.com with SMTP id c12so9957042wrc.7 for ; Fri, 29 Jan 2021 11:28:42 -0800 (PST) Received: from avogadro.lan ([93.56.170.5]) by smtp.gmail.com with ESMTPSA id l18sm10964528wme.37.2021.01.29.11.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jan 2021 11:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AzYhMXskdJJjtZLtwvwFrwykEA7TzJv7brNc4V8DwwQ=; b=T+0WR4g0R9JUihpKjrkHemFcAtSqlzspGH8v8sRYC1V1QMFLK0R9AS05hhXk8GzhCd Baq0Lf+GoxxOo1qOyPvpajtm03rqYe2CfngXsNz6Su/L0ojbUOVnLQwGOt7NT0n4og0K tg1EAdb7d2goY45/miycO1umu0danQfP8fJeFeFqTZjaInkCsyFhnxVu8XTPygrcHQ1S 5mbb6YXU5D/szm6O265+LB7bH7z6gdcNwnH3CKizfpouTfStPHFY+T+Mu1GG75JDIKlt QwRQsj7Obc5WEgHWAy7uLG446e5gEArdG5cor1uh2dUFJU4p0nwoXQpxo9PXU5VcDr5i g1JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=AzYhMXskdJJjtZLtwvwFrwykEA7TzJv7brNc4V8DwwQ=; b=opRc5SCRy0d+4IeYKvlfyzk7KFI3D3mKfNbYDY4jD3Z+QOzsmdU3Jg4X0oYWKmqd/K 17IVkQJB9qZWXelo5zAhzAsvDtWKpB5mRIduIaAz3JGMLHXItzCXdWthd2DqbGUJOAue CmNr5voXkgfMvKIgVMXDSn7lY2nbsTylDZH+nFawHYtfVMuFfPEBCDeguxs9x3Z8H91W d9JkjJNF+5guTao2gDmQw5Km2/g/gUM8bsFxh13lnn1J6Q/4Q6b2QI3pOF4E1zyqu6kl rI1I/r+a5mLVPz43HoPCurLSLcHyFnVrcZfVtvnTVJ6BwXpL+fvueQ8URLaaXEQGMfO6 mN7w== X-Gm-Message-State: AOAM530G4e11nYae1qu5IqERcyo1ynaRd5ce6IGujVEUgh+TiY23CfZs o6rMXMASPlrd5kNuyjx0AX/dxSEeeXnqKg== X-Google-Smtp-Source: ABdhPJwm583lXGNZqKPsn39SYMDSzZDjmpHFvoiUdiihS9FbR/oaYlCllbTbp47NjjOgphFe8zeGLw== X-Received: by 2002:a5d:5908:: with SMTP id v8mr6436747wrd.113.1611948521600; Fri, 29 Jan 2021 11:28:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] pci: reject too large ROMs Date: Fri, 29 Jan 2021 20:28:37 +0100 Message-Id: <20210129192838.582771-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210129192838.582771-1-pbonzini@redhat.com> References: <20210129192838.582771-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=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, dgilbert@redhat.com, peterx@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" get_image_size() returns an int64_t, which pci_add_option_rom() assigns to an "int" without any range checking. A 32-bit BAR could be up to 2 GiB in size, so reject anything above it. In order to accomodate a rounded-up size of 2 GiB, change pci_patch_ids's size argument to unsigned. Signed-off-by: Paolo Bonzini Reviewed-by: Laszlo Ersek Reviewed-by: Peter Xu Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/pci/pci.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a6b0c5602e..bbce10050b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -25,6 +25,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/datadir.h" +#include "qemu/units.h" #include "hw/irq.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bridge.h" @@ -2258,7 +2258,7 @@ static uint8_t pci_find_capability_at_offset(PCIDevic= e *pdev, uint8_t offset) =20 /* Patch the PCI vendor and device ids in a PCI rom image if necessary. This is needed for an option rom which is used for more than one device= . */ -static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size) +static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, uint32_t size) { uint16_t vendor_id; uint16_t device_id; @@ -2316,7 +2316,7 @@ static void pci_patch_ids(PCIDevice *pdev, uint8_t *p= tr, int size) static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, Error **errp) { - int size; + int64_t size; char *path; void *ptr; char name[32]; @@ -2366,6 +2366,11 @@ static void pci_add_option_rom(PCIDevice *pdev, bool= is_default_rom, error_setg(errp, "romfile \"%s\" is empty", pdev->romfile); g_free(path); return; + } else if (size > 2 * GiB) { + error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 G= iB)", + pdev->romfile); + g_free(path); + return; } size =3D pow2ceil(size); =20 --=20 2.29.2