From patchwork Fri Sep 15 10:16:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 723108 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp285837wro; Fri, 15 Sep 2023 03:18:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3famXtPa3qHuHYxl5StYf3GdGE1Uo55SZpICjyjlyVza2wTkO1MNiA241OjLEsK82X/KM X-Received: by 2002:a05:6000:5c7:b0:31f:f753:5897 with SMTP id bh7-20020a05600005c700b0031ff7535897mr1024635wrb.59.1694773103121; Fri, 15 Sep 2023 03:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694773103; cv=none; d=google.com; s=arc-20160816; b=mrPy0DLTggsaxq6iF5HDONSnERp5N5z2cuXJw3Xwbea+0m+zM/3R9T+L8i8WKnq0gL 3OESiqzyBA3/Xcar9Szh3sfWT/PwNeDkrFevrUy6G935B5M73w0Te2U+93HJIreXZXUM iinaY2VxdkStq1vMAaKYS4f0QT43SHgTsj28Xh99HqDg9jR9MWLBm8bgxVj5lt/mK7P0 rniyC3GBUODLt+vncLTPv8Wm1FwIPFd24NEC6Lnrqg+ffbmEWdxQnBFdafuJIyL0xI2U aZDGhjs9P17mJipMeszFnQFtD8ZgH7U5/jSJTLtocjBbEedS/VFsCffRwQ1b2a/ZkMFz I0Kw== 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; fh=XwOfspvhog7otCudZV1ecvxibH3YToEgjgP70JntENo=; b=eAEkTiJl9hL0/S8FWqxLeLTXC/UPPNW3XKd2IR52Ef9cYqLaAQQbVWgWN6ng/+MnXI yQgmU8TpxubLra00/c/e+g8K8GQgEaEDHTjVtPos+2iF2ZKp+PvakJKXM7Txp6FXQtIa 9/ZRM+ghJm8p7omRyNKa+oBl9FQrPipJjm/FmFS9BGkdgK7fcr8Jm8tcXznFd8YGgl6o /DmTHO+h2gY30gwESCRZebe+k60Lkvb6rK+ip7GIVLif7zHTIff/HtKR3QDFoAPMHSqW xlt+iDKzZNEylZb48+Glfa0lwq/RD+LthPyKsPQkdu/PUGcZycI6gfpAWtT5h1PVFgTC A9iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RFP5nsl2; 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 n3-20020a5d4003000000b0031970b91a5csi1466886wrp.962.2023.09.15.03.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:18:23 -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=RFP5nsl2; 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 0493B86828; Fri, 15 Sep 2023 12:18:03 +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="RFP5nsl2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A8A1868C0; Fri, 15 Sep 2023 12:18:01 +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-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 1699186504 for ; Fri, 15 Sep 2023 12:17:59 +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-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68fdd5c1bbbso1451063b3a.1 for ; Fri, 15 Sep 2023 03:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694773077; x=1695377877; 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; b=RFP5nsl2KMste4NccYa0A8KZUX9cxgG5oMrhcoB2htgganFbqa2An9KQfaOLjvTK1/ 48FzjKNPDqzYRYIhu+hSj3pMdr+8COCdt72G4Z5LMhIjWp6PC1hm19d+3n9WBXtItkJK TNX3SVik1VVZ2I/D0xmypQ7sDR09XufPymLjPit3vnGhNAFoYwhkhE75AWrlfC9RSEGR jP8UGZmcDWZWy8Ii8PcqGUp8kng/j0QSPr4S2tQQlao3lJAhSQl+XES+8pHXKR6F+cfr sd9cnupO8I2kJbL48STTSpq+HnDrGiJR1RoBBm/jhngjPKtRNX0YMeSFPEKxdbolB+CK q1MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694773077; x=1695377877; 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=/4btGceD5iKx7XC+SvX5hI4qw+NEEZDleq7acA0Pb3s=; b=C0dobyeEPgvILxIA1vkx+kTkA0y11rQkn6c8BtnB8BMB/gbB9QLRNfv7PMehTMk5MB jgo7PdQpBQDbdMnSbegnDyIXAQcmKeOoeae3PRjq0OeonNlFc1yuL+R3visSAzU2/i5h zb0msar4RpSLmsjwOcNsuNBW6JHwkg/Cc6dn6Fz3LvU1L1U8FGjvYmry1p68h4gC+zI+ 4NQpRUYEEGDWM7OwGKLZ7d8HFjXBJkrBgT1U2pB/E5Xbs9NPEGIAGDDv1g9LDDfuXxNZ vv+PnGmjogtKpr/zvWUdoJXBMqCPEQzWqz7zm0LufdrsV/Umy/W4VoWwSLr+t0SIeP0A lVjg== X-Gm-Message-State: AOJu0YzzBS8QGjxR0QdO/Wkllg5ziChbRQvbgutsBIvQHVzMA5cpaT3F 7/B7DqePoPSCUP5MiCchVsEhN6RUXqKKYT872T8= X-Received: by 2002:a05:6a00:2d9d:b0:68a:6018:a66f with SMTP id fb29-20020a056a002d9d00b0068a6018a66fmr1620054pfb.2.1694773077264; Fri, 15 Sep 2023 03:17:57 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id g7-20020aa78187000000b0066a31111cc5sm2695732pfi.152.2023.09.15.03.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 03:17:56 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v3 5/7] efi_loader: set EFI HTTP Boot download buffer as reserved Date: Fri, 15 Sep 2023 19:16:38 +0900 Message-Id: <20230915101640.1166332-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230915101640.1166332-1-masahisa.kojima@linaro.org> References: <20230915101640.1166332-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 1a287ad89d..d26c607815 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;