Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1j9SgZ-0003dR-7J for mharc-grub-devel@gnu.org; Wed, 04 Mar 2020 06:59:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50821) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9SgT-0003T5-Bx for grub-devel@gnu.org; Wed, 04 Mar 2020 06:59:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9SgS-0003GL-6M for grub-devel@gnu.org; Wed, 04 Mar 2020 06:59:29 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:56161 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9SgR-0003GA-OI for grub-devel@gnu.org; Wed, 04 Mar 2020 06:59:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583323167; 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=y82Zzu+jNLt5iBCt6nHYCC+ArxDsBSAiA/UdqwyYH5k=; b=Zkz9T3ph+g4FOzrgxXBZlZ52mc2znTHwVfrHhuWYs+GiRUrTxGTCvzx59621Yjgyr8UU9S sb4sWiUD9Yk1o3fDRYFeAP+aoOynBYSCR6aS8xAwzjYXVRK2q0Wc6A7CrefjDeKItxkmWB cDelYGARiQWcq4KbSVfOw2ZP2Ypu9Wo= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-422-LN24qyXnP1Wp74-YdedKww-1; Wed, 04 Mar 2020 06:59:26 -0500 X-MC-Unique: LN24qyXnP1Wp74-YdedKww-1 Received: by mail-wr1-f71.google.com with SMTP id m18so727969wro.22 for ; Wed, 04 Mar 2020 03:59:25 -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=iMREM4Rm0rSmrX01SeD9kII8Qjko2ppmnaPrkGaM4GU=; b=ucF76D8CgB8mvtOjUpuvFYrYj6AQIWTH3olTh5vzB5k+7lGkuxXfVwqHOAEACRmSix XqOyXK4QEvvCqab1ltZmVWLMEWvAnkj+VBFqnnq/My+x1I5LEvGCvpv7pKkaupEmXfuT sqTKd8YuP/3AmAa7yGN8JGvOnB5YgSDqAv1UquVkQcKERKc9PLaW5vt97p1RJNQieKAE zmzK7ozNDwzo4gOamHcmCKB6PsJ0mjVutHBbGO60vhb2cSNM0gccTeCJtekps/SR2AJH N+WS/EnQSdrof2hHzyonnM61ReuubReRArjM/zXGXkttvfKFsddk7dGZsT9NAeShg3xC okFQ== X-Gm-Message-State: ANhLgQ296HsTKisigK8gFY5RuJPO/h5cj/iPDZSDCRN6xlTz1rJghGp7 KjAS+lEhyYnyhhrIo+4BAbiuqotLWc/V7hEHHodidJiUlQHj2fhsY4dxW0in/Bqn2qMbla/W98U 9cbO1EVZ2eq0= X-Received: by 2002:adf:a304:: with SMTP id c4mr3639722wrb.186.1583323164238; Wed, 04 Mar 2020 03:59:24 -0800 (PST) X-Google-Smtp-Source: ADFU+vsudLr6r4FvLPuU6QMey+W+moj4lB/avRfn/0cphqrUylWVY+biV7CJEIRzhm74Q+agIM6AHg== X-Received: by 2002:adf:a304:: with SMTP id c4mr3639709wrb.186.1583323163968; Wed, 04 Mar 2020 03:59:23 -0800 (PST) Received: from minerva.redhat.com ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b]) by smtp.gmail.com with ESMTPSA id t14sm5911207wrp.63.2020.03.04.03.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 03:59:23 -0800 (PST) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Daniel Kiper , Andrei Borzenkov , Javier Martinez Canillas Subject: [PATCH v2 07/12] efi/uga: Use 64 bit for fb_base Date: Wed, 4 Mar 2020 12:58:46 +0100 Message-Id: <20200304115851.3474263-8-javierm@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200304115851.3474263-1-javierm@redhat.com> References: <20200304115851.3474263-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: Wed, 04 Mar 2020 11:59:30 -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 Reviewed-by: Daniel Kiper --- 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