Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hC3lr-0007II-B0 for mharc-grub-devel@gnu.org; Thu, 04 Apr 2019 10:55:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hC3lp-0007HZ-2W for grub-devel@gnu.org; Thu, 04 Apr 2019 10:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hC3lo-0003rW-2B for grub-devel@gnu.org; Thu, 04 Apr 2019 10:55:13 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:39319) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hC3ln-0003pG-Pv for grub-devel@gnu.org; Thu, 04 Apr 2019 10:55:12 -0400 Received: by mail-pg1-x542.google.com with SMTP id k3so1368718pga.6 for ; Thu, 04 Apr 2019 07:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Wm0HZcucHlotHt7TyQcnHBkaVT70qDBGwfHG5BT+Pm8=; b=SAmKrLY7YKGKlxbKU3OnqZ65TY414H7jnt7oZhpzhNnxqTzVL15bAsT+idFHTTpSfI druWQN5jR2K/wAooeETYzUSjAzFwPsTX7IagWwCup8415Uw0Ri9CdsQ1dtTwt54a2vx4 MK59NoXtKKBBmqWusQMnUEWqgKMw6sZJGr6YA+DpC33f4UvBj+JpgVj3w7mV/QCv9fUu YYn1v1LCzQOCYXrUyCHevFXxksSyerwAObAsKRY6cllp15h89Pft/gAabtQ9XUFjaapJ 1F0ntKOlnhp1P0NJ5V80rNq+jn9Ji+IFnxfAF21XdjsbQp7QYE+9f0vp37AkVoSp25xr ay2Q== 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; bh=Wm0HZcucHlotHt7TyQcnHBkaVT70qDBGwfHG5BT+Pm8=; b=i2oAATUojoPIAe5VPcqQl1s6Gp8TL0AxYyyQvPaXIs1MuzKoXLT7+w5kujY+42VcZy rJbII3IcXHkh6B5XHkauVhEO1Mh9m5sj3w0tvjh9R8jEUsOj7Pzv7aft4OHyf5mA8Jla SNomorYJIYDKbssEE09nlFeP6HBjB2J58v9q8EYuBD+q78hzLLxGMYPRmSJyU+L9/T0R imwUtgv90rdfRfsKqmz9cBoPE47/P6Qd71N7nzyGXHyZd3jatusIWsNczLuPX7vUaFRH qYyGsDekRM55Jr1sM16nUXEY4QO+xfQmnkWihWo1NOfjTqjADUYUO6+d2+H3Cw+I1Byd NqRg== X-Gm-Message-State: APjAAAUyBfG4ITHBSy8Z/FPPRe+ydiZRzt4M6bBSoRBgpdYO5PG2Gppa ErAPcCb2qUnC5sR9vqCZy3B1K3Lw X-Google-Smtp-Source: APXvYqw6d10XlM7uHidkL5g70xa1F3GZsYHofiuUq5Z9QL3sVEKZNuq+mExsPcIFom31z1cbU7Qp4g== X-Received: by 2002:aa7:8092:: with SMTP id v18mr6214411pff.35.1554389710283; Thu, 04 Apr 2019 07:55:10 -0700 (PDT) Received: from aw-bldr-10.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id d187sm23389684pgc.43.2019.04.04.07.55.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Apr 2019 07:55:09 -0700 (PDT) From: Jeffrey Hugo To: grub-devel@gnu.org Cc: leif.lindholm@linaro.org, Jeffrey Hugo Subject: [RFC] arm64/linux/loader: Use EFI CODE allocations for the linux kernel Date: Thu, 4 Apr 2019 07:54:55 -0700 Message-Id: <20190404145455.25872-1-jeffrey.l.hugo@gmail.com> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2019 14:55:14 -0000 Some UEFI implementations for ARM64 devices apply strict permissions on the different allocation types. In these implementations, DATA allocations have XN (execute never) permissions, preventing code execution from those pages. On these implementations, the Linux kernel is loaded to DATA pages, which causes a permission fault when GRUB attempts to kick off the kernel. This results in a device crash. Fix this by allocating CODE pages for the Linux kernel. Signed-off-by: Jeffrey Hugo --- grub-core/kern/efi/mm.c | 8 ++++++++ grub-core/loader/arm64/linux.c | 2 +- include/grub/efi/efi.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index b02fab1b1..725695e01 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -156,6 +156,14 @@ grub_efi_allocate_any_pages (grub_efi_uintn_t pages) GRUB_EFI_LOADER_DATA); } +void * +grub_efi_allocate_code_pages (grub_efi_uintn_t pages) +{ + return grub_efi_allocate_pages_real (GRUB_EFI_MAX_USABLE_ADDRESS, + pages, GRUB_EFI_ALLOCATE_MAX_ADDRESS, + GRUB_EFI_LOADER_CODE); +} + void * grub_efi_allocate_fixed (grub_efi_physical_address_t address, grub_efi_uintn_t pages) diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index ef3e9f944..877839072 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -313,7 +313,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), grub_loader_unset(); grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); - kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); + kernel_addr = grub_efi_allocate_code_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); grub_dprintf ("linux", "kernel numpages: %lld\n", (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); if (!kernel_addr) diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index e90e00dc4..697cabcd6 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -47,6 +47,8 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); void * EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages); +void * +EXPORT_FUNC(grub_efi_allocate_code_pages) (grub_efi_uintn_t pages); void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, grub_efi_uintn_t pages); grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); -- 2.17.1