From patchwork Tue Apr 9 20:58:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Wildt X-Patchwork-Id: 1082739 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=blueri.se Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44f0506SYDz9sSs for ; Wed, 10 Apr 2019 06:58:42 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4E686C21E08; Tue, 9 Apr 2019 20:58:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A302FC21D8A; Tue, 9 Apr 2019 20:58:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 926BDC21C29; Tue, 9 Apr 2019 20:58:33 +0000 (UTC) Received: from pony.blueri.se (pony.blueri.se [163.172.214.9]) by lists.denx.de (Postfix) with ESMTPS id 46517C21C29 for ; Tue, 9 Apr 2019 20:58:33 +0000 (UTC) Received: from nyx.fritz.box (p200300C1C7250300FC0BBA6A89B3BCA4.dip0.t-ipconnect.de [IPv6:2003:c1:c725:300:fc0b:ba6a:89b3:bca4]) by pony.blueri.se (OpenSMTPD) with ESMTPSA id c1082df9 (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO) for ; Tue, 9 Apr 2019 22:58:31 +0200 (CEST) Date: Tue, 9 Apr 2019 22:58:30 +0200 From: Patrick Wildt To: u-boot@lists.denx.de Message-ID: <20190409205830.GA5818@nyx.fritz.box> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.11.4 (2019-03-13) Subject: [U-Boot] efi: fix memory calculation overflow on 32-bit systems X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hi, There are Cubox-i machines out there with nearly 4 GiB of RAM. The RAM starts at 0x10000000 with a size of 0xf0000000. Thus the end of RAM is at 0x100000000. This overflows a 32-bit integer, which should be fine since in the EFI memory code the variables used are all 64-bit with a fixed size. Unfortunately EFI_PAGE_MASK, which is used in the EFI memory code to remove the lower bits, is based on the EFI_PAGE_SIZE macro which, uses 1UL with a shift. This means the resulting mask is UL, which is only 32-bit on ARMv7. Use ULL to make sure that even on 32-bit platforms we use a 64-bit long mask. Without this there will be no memory available in the EFI memory map and bootefi will fail allocating pages. Best regards, Patrick Reviewed-by: Heinrich Schuchardt Reviewed-by: Patrick Delaunay diff --git a/include/efi.h b/include/efi.h index d98441ab19d..3c9d20f8c0b 100644 --- a/include/efi.h +++ b/include/efi.h @@ -190,7 +190,7 @@ enum efi_mem_type { #define EFI_MEM_DESC_VERSION 1 #define EFI_PAGE_SHIFT 12 -#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) +#define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT) #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1) struct efi_mem_desc {