Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j6ZI4-00049L-3U for mharc-grub-devel@gnu.org; Tue, 25 Feb 2020 07:26:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55641) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ZI1-00041S-5e for grub-devel@gnu.org; Tue, 25 Feb 2020 07:26:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ZHz-0006cR-WD for grub-devel@gnu.org; Tue, 25 Feb 2020 07:26:17 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50308 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j6ZHz-0006bq-Rv for grub-devel@gnu.org; Tue, 25 Feb 2020 07:26:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582633575; 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=99tqvScNo+IdwsAYQ/x5HN6kwMg/CmU2YAUdH/EeIOA=; b=MxLkr3FNVnbdqsaJ0SthFBjNfUtIrf6H5o0O/UyFaol/7ZCk8T/901GKbObIeqwKzy0SyF CDjFNwy+H/GIJqBbDTh+xjujxC2UsynabobacnkUwU+VIp3feZR8fcv1T0VZYDV7pzp8vh 0ayZOe2MnDSH6GDJJ1kGDNd5AFGtyl0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-8-DECa5Vd4OYGquNtbdEZoow-1; Tue, 25 Feb 2020 07:26:13 -0500 X-MC-Unique: DECa5Vd4OYGquNtbdEZoow-1 Received: by mail-wr1-f72.google.com with SMTP id o9so7238624wrw.14 for ; Tue, 25 Feb 2020 04:26:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UCsSSOOX4d2jur++2hUFWMwNHsPsgt9ZQrI+KNMltRg=; b=bOgiAkv+TbsyUL1Ye5SU/Ro5HLgoGq1mhHl700wQCKIbP8/QRk1ZLE24XbkUGqC9Hv mcrtB3rt4JTyChTSisKE0bdY5G1XsPGRF2cj7P1AJWuzdm9JjJH2RzL8yYDF2NdMzM3x Shd0bgRgyKSC6ijdKosu3rE4rD46oyjZiQ7RH/LV2+JuLUfSXeXIVW+KQ6BbIWjbeAbN jNclZItjq1FBV+CzvSutqHGCEJ/ir0J7NWzdSiBiNXqqxb28AuTtcTcoZbr1t0IstY8q eHquoWt87gjbM4rvc2TbPP5F6UIvFQyuRa8tUPX51lCylCmiTYwYAd4X9AX2417HxF3E 1O8g== X-Gm-Message-State: APjAAAWveZGI/V3FKNlJlMYR3wh2Rn1ojF8T2gH6WibEhqHLK8u3N2hL 1ukbEGNjypTpHOpulhfPrhnMSQ60Cbrepbf8CYgphbunFCDG4iXVVM6XiKh2N6rbsdsvVb7W0dm nr0fKa9oCl3Y= X-Received: by 2002:a1c:f713:: with SMTP id v19mr4924339wmh.113.1582633572147; Tue, 25 Feb 2020 04:26:12 -0800 (PST) X-Google-Smtp-Source: APXvYqzqCnFPK4TGyavXilEPKQjTdiobRSkWmsvu9jBMjOPFLRGtTpiLQYeRUdeyficybYEfwhk48A== X-Received: by 2002:a1c:f713:: with SMTP id v19mr4924313wmh.113.1582633571923; Tue, 25 Feb 2020 04:26:11 -0800 (PST) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id q6sm17251653wrf.67.2020.02.25.04.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 04:26:11 -0800 (PST) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , Andrei Borzenkov , Javier Martinez Canillas Subject: [PATCH 07/10] efi/uga: Use 64 bit for fb_base Date: Tue, 25 Feb 2020 13:25:50 +0100 Message-Id: <20200225122553.1120216-8-javierm@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200225122553.1120216-1-javierm@redhat.com> References: <20200225122553.1120216-1-javierm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Feb 2020 12:26:18 -0000 From: Andrei Borzenkov We get 64 bit from PCI BAR but then truncate by assigning to 32 bit. Make sure to check that pointer does not overflow on 32 bit platform. Closes: 50931 Signed-off-by: Andrei Borzenkov Signed-off-by: Javier Martinez Canillas --- grub-core/video/efi_uga.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/grub-core/video/efi_uga.c b/grub-core/video/efi_uga.c index 044af1d20d3..97a607c01a5 100644 --- a/grub-core/video/efi_uga.c +++ b/grub-core/video/efi_uga.c @@ -34,7 +34,7 @@ GRUB_MOD_LICENSE ("GPLv3+"); =20 static grub_efi_guid_t uga_draw_guid =3D GRUB_EFI_UGA_DRAW_GUID; static struct grub_efi_uga_draw_protocol *uga; -static grub_uint32_t uga_fb; +static grub_uint64_t uga_fb; static grub_uint32_t uga_pitch; =20 static struct @@ -52,7 +52,7 @@ static struct #define FBTEST_COUNT=098 =20 static int -find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) +find_line_len (grub_uint64_t *fb_base, grub_uint32_t *line_len) { grub_uint32_t *base =3D (grub_uint32_t *) (grub_addr_t) *fb_base; int i; @@ -67,7 +67,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *lin= e_len) =09 { =09 if ((base[j] & RGB_MASK) =3D=3D RGB_MAGIC) =09=09{ -=09=09 *fb_base =3D (grub_uint32_t) (grub_addr_t) base; +=09=09 *fb_base =3D (grub_uint64_t) (grub_addr_t) base; =09=09 *line_len =3D j << 2; =20 =09=09 return 1; @@ -84,7 +84,7 @@ find_line_len (grub_uint32_t *fb_base, grub_uint32_t *lin= e_len) /* Context for find_framebuf. */ struct find_framebuf_ctx { - grub_uint32_t *fb_base; + grub_uint64_t *fb_base; grub_uint32_t *line_len; int found; }; @@ -129,7 +129,9 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, = void *data) =09 if (i =3D=3D 5) =09=09break; =20 -=09 old_bar2 =3D grub_pci_read (addr + 4); +=09 i++; +=09 addr +=3D 4; +=09 old_bar2 =3D grub_pci_read (addr); =09 } =09 else =09 old_bar2 =3D 0; @@ -138,10 +140,15 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid= , void *data) =09 base64 <<=3D 32; =09 base64 |=3D (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); =20 -=09 grub_dprintf ("fb", "%s(%d): 0x%llx\n", +=09 grub_dprintf ("fb", "%s(%d): 0x%" PRIxGRUB_UINT64_T "\n", =09=09=09((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? -=09=09=09"VMEM" : "MMIO"), i, -=09=09 (unsigned long long) base64); +=09=09=09"VMEM" : "MMIO"), type =3D=3D GRUB_PCI_ADDR_MEM_TYPE_64 ? i - 1 := i, +=09=09=09base64); + +#if GRUB_CPU_SIZEOF_VOID_P =3D=3D 4 +=09 if (old_bar2) +=09 continue; +#endif =20 =09 if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! ctx->found)) =09 { @@ -149,12 +156,6 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid,= void *data) =09 if (find_line_len (ctx->fb_base, ctx->line_len)) =09=09ctx->found++; =09 } - -=09 if (type =3D=3D GRUB_PCI_ADDR_MEM_TYPE_64) -=09 { -=09 i++; -=09 addr +=3D 4; -=09 } =09} } =20 @@ -162,7 +163,7 @@ find_card (grub_pci_device_t dev, grub_pci_id_t pciid, = void *data) } =20 static int -find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) +find_framebuf (grub_uint64_t *fb_base, grub_uint32_t *line_len) { struct find_framebuf_ctx ctx =3D { .fb_base =3D fb_base, --=20 2.24.1