From patchwork Fri Sep 22 07:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725220 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp876065wrm; Fri, 22 Sep 2023 00:12:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDZ5ZgNK9/FzSefCGDs/NAdcp00JqjYK8c4/hfiAl6T0bliyBGXRJUMS/Mb9wRiMRN4DLU X-Received: by 2002:a05:6000:104:b0:317:55c:4936 with SMTP id o4-20020a056000010400b00317055c4936mr7627172wrx.9.1695366766616; Fri, 22 Sep 2023 00:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366766; cv=none; d=google.com; s=arc-20160816; b=lkZ0bKiyP+DppEICavlhQQfqoqXs127WgA1aWQgSdhaYX7TSB/6eY4ty5sOXPS5UFE bqhqyp1qwRL8TlLrrbsYESwFd3TfLVgT5EZ4CLviWMC1zaSlMndvY+8VHiva3bdQ9AKv D1i7hLR6+NnqcnOsRHQ2iW8mrxkqaEH9T+qBC0Oilg99XAMD2gxlDKdI69OGAbKdcZS2 EODP7rByfudcQ6I05dgboHZEGIw1VVwwmvmbwMU0YiSkbF4RaxC9ZUpnsgiARps/cOLh PWdccZmQFf29AsVvKAqUIkI9spBg329usomWyAEY0FZuzSJpux4CmqGuZXBUnCJ3cyeg /CDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=SFddoC/uPulMV4dBSGkg7gfVqun2XnrxyZTgku7LDnKGmRYcPN3Gu5zmRtMdi350tK g78vH494DBL9Kg024iylTNR0Je95LQh6ec1Cdfvd9jIEdFiqtHmF0veILKOHpZNx0t6C +V6YxQfeECrYjgrUdWKCnJGfb6nET7SJAcZ2ZkXE722/eG6oqpks98IcGHdNsimH2pwx pX+2DKraorDmZAHpje9fkZcsIVksiAvVFuSYrWwcFXpUD0eR2TeodFUZeHD3RlGIjxsx hQZZPZITIl+vFuwF+qBZ+f0kgLRt6ps8w7TER0tezHppQAvU47qGUoullix1s7Oj+S7C cK7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W6rG8e/S"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m4-20020adfe944000000b003216f1c589bsi1603510wrn.781.2023.09.22.00.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:46 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W6rG8e/S"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DBD9086A24; Fri, 22 Sep 2023 09:12:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="W6rG8e/S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9537686925; Fri, 22 Sep 2023 09:12:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 833FE869F6 for ; Fri, 22 Sep 2023 09:12:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-57354433a7dso917802eaf.1 for ; Fri, 22 Sep 2023 00:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366735; x=1695971535; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; b=W6rG8e/SIt1X1G3qFhVJk3UBXscu5WGoUz+7BUPUUK0twqneqGN7QVsyz+FleEJq4b R+P0athFnVVZsuLhIg0GTPjQm9dLPTpdEdw9H/5MIIXpEcbl40qBnAiY6OSnkBFSO8tX 7AkBSljjlgribwo07WCn+pvebgPctyxep3KNtjH5U2kREQShMfDvEsANvDXAKo+fGNwM oIpzkmzCTDw5pfBxjPKqSP4o42DiRvxoFRpGPF6IDdrkzljbOGkbi1TJQ5yx+KqSlOGm 4R4hwv8ycaKjWlByc41fuBhcUhharQxhgGtrMaBNVYRbyB38mh28/Z2DBRwZsmB5bJLj ogHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366735; x=1695971535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fwwmmRncDyhEDtzmHsqB9lGW4uFafsxOwt3w7F08tA0=; b=cY5gdHJR56uXoMQzvCRF6WYXn5Qt4Pz1y7xAVMfsmGBI1BM0t/tNqzlUn6ePQhdcYd 4g2nZ0tkQzCqIiecQZnPhI/tlEq0r7I9CLhHXJLjHdcxwHAKyo7u/L/4aVo5aKs7CY9N Id4e74RbLfL0kYZGYYZSuHNGdJ7OIHaS+iA3mj6+F+z154opqhD1WfKyqQOcuzOj17Bt E6CiIWELGvvPoS2WZmZyyMGLeNmgr3jy1OWh0tt8bkOVclDhRurk1xS/ukE0U+bc39Et F6Cgpzd12KtZMJGG9I+cu80QalNF5issoGYk0HDWg3trVwFIIGNYdFPjGP+169ufBOm+ QoXw== X-Gm-Message-State: AOJu0Yx0Ty6GadT5UI0IeEDv/iO/IobIdKrqkPcwgNmvv6M8h0ktUFJH QViZdPrXLAIoILPr8o0Z+VPWU9kOWocxLqY/FPM= X-Received: by 2002:a05:6870:b4a5:b0:1db:f7f8:ab56 with SMTP id y37-20020a056870b4a500b001dbf7f8ab56mr8335522oap.53.1695366735619; Fri, 22 Sep 2023 00:12:15 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id t63-20020a638142000000b0055c178a8df1sm2435858pgd.94.2023.09.22.00.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:14 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 5/8] efi_loader: set EFI HTTP Boot download buffer as reserved Date: Fri, 22 Sep 2023 16:11:16 +0900 Message-Id: <20230922071119.1439482-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The buffer used to download the ISO image file must be reserved to avoid the unintended access to the image. For PE-COFF file case, this memory reservation is done in LoadImage Boot Service. Signed-off-by: Masahisa Kojima --- include/efi_loader.h | 2 ++ lib/efi_loader/efi_bootmgr.c | 5 +++++ lib/efi_loader/efi_dt_fixup.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 4a29ddaef4..c4207edc91 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -554,6 +554,8 @@ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition, void **address); +/* add reserved memory to memory map */ +void efi_reserve_memory(u64 addr, u64 size, bool nomap); /* Carve out DT reserved memory ranges */ void efi_carve_out_dt_rsv(void *fdt); /* Purge unused kaslr-seed */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 605be5041e..4991056946 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -326,6 +326,11 @@ static efi_status_t try_load_from_uri_path(struct efi_device_path_uri *uridp, return EFI_INVALID_PARAMETER; ret = load_default_file_from_blk_dev(blk, handle); + if (ret != EFI_SUCCESS) + return ret; + + /* whole ramdisk must be reserved */ + efi_reserve_memory(image_addr, image_size, true); } else if (efi_check_pe((void *)image_addr, image_size, NULL) == EFI_SUCCESS) { efi_handle_t mem_handle = NULL; struct efi_device_path *file_path = NULL; diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 838023c78f..edc515b9ff 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -22,7 +22,7 @@ const efi_guid_t efi_guid_dt_fixup_protocol = EFI_DT_FIXUP_PROTOCOL_GUID; * @nomap: indicates that the memory range shall not be accessed by the * UEFI payload */ -static void efi_reserve_memory(u64 addr, u64 size, bool nomap) +void efi_reserve_memory(u64 addr, u64 size, bool nomap) { int type; efi_uintn_t ret;