From patchwork Sun Nov 4 23:34:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 150127 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1959663ljp; Sun, 4 Nov 2018 15:34:36 -0800 (PST) X-Google-Smtp-Source: AJdET5chUj6+BKHgdNgovpSuTJm1vdIbe6QqB/mrHw95xwGXtWm0R1c3vqEWMZN1tTRgVAtVdEdT X-Received: by 2002:a17:906:f285:: with SMTP id gu5-v6mr12439540ejb.64.1541374476731; Sun, 04 Nov 2018 15:34:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541374476; cv=none; d=google.com; s=arc-20160816; b=RTjjdvOiqRSOSPlB/NgJ9VdDa6ATsb2shjkerQR5H/pa5+1gkwE3vi5MMGW42mKV1Z xaLY6P2jjETRF7/0FgKV7WC5VK7UTXce5nSWSLlIp838GQAX8TNhWNbhO7QbRRrMaSNc RpKqSwLeOr3KUAwYEuqt8sxHiNidboffxMwkF0a+SAfgbY8Ndh87EPL2GwmV7fvhhwfA Msodm+BiAeN0Wiwlg/ZyoenStxOOTlB16tb84BoNI3iN0cJU5vsWcDeTN4Q+/Sievw6r xEyTvKDJrkNOz5WOIF5vt8csFsm6jMnicCotKlvJZgSvTNUCC0co6QbrBb0SiocDxkUc DITA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from; bh=O8Xd80mVdfQ1fzKyruAMKj7NG2YNFVH8AkqY0Y8/MH8=; b=DKoi6715jnZYbo1HHwV1kWIMc8pvGtpwSAk1k8Jv6vIQlfKz3sf5cx51J/WaXc6T9T kUZBl0ThtZ1pliB5R4wI+CmjCSbPP35LR8uIa0MzdMUp3uUl+SEycn1p7NHSc7cZ7ASR Vx+TABxhVlxpD0QI59KZbbSnC3mlSmOB87MYOVtFcGLWlgBq6fujDgpCxFUWdgXNtoVU 6dzzZm1jPPkyT9lH4BGgqhRc6k1826p8Qe3lUQXIfSSe9Snv3mzTNzBamUmFCvIR/IRb aQXfO5KEZ0B575N1oISgJW6a9g5yznITm6IQGvHEt5h3tH60Q4NgHWFYp1GI1bUDPc0S ngXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id l26-v6si2858467eji.29.2018.11.04.15.34.35; Sun, 04 Nov 2018 15:34:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id D93C9C2215A; Sun, 4 Nov 2018 23:34:32 +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=RCVD_IN_DNSWL_BLOCKED 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 8AB29C22048; Sun, 4 Nov 2018 23:34:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8FE48C22048; Sun, 4 Nov 2018 23:34:29 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 77A7AC21DA1 for ; Sun, 4 Nov 2018 23:34:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D1422ACE8; Sun, 4 Nov 2018 23:34:27 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Mon, 5 Nov 2018 00:34:26 +0100 Message-Id: <20181104233426.24961-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt Subject: [U-Boot] [PATCH] efi_loader: Ensure memory allocations are page aligned 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" When the max_addr parameter of efi_find_free_memory() is within bounds of an existing map and fits the reservation, we just return that address as allocation value. That breaks however if max_addr is not page aligned. So ensure that it always comes to us page aligned, simplifying the allocation logic. Without this, I've seen breakage where we were allocating pages at -1U (32bit) which fits into a region that spans beyond 0x100000000. In that case, we would return 0xffffffff as a valid memory allocation, although we usually do guarantee they are all page aligned. Fix this by aligning the max address argument always. Signed-off-by: Alexander Graf --- lib/efi_loader/efi_memory.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 5bd4f4d7fc..1ffcf92eb2 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -294,6 +294,12 @@ static uint64_t efi_find_free_memory(uint64_t len, uint64_t max_addr) { struct list_head *lhandle; + /* + * Prealign input max address, so we simplify our matching + * logic below and can just reuse it as return pointer. + */ + max_addr &= ~EFI_PAGE_MASK; + list_for_each(lhandle, &efi_mem) { struct efi_mem_list *lmem = list_entry(lhandle, struct efi_mem_list, link);