Skip to content

Commit 3166422

Browse files
mro-github-12345Andy Bui
authored andcommitted
elfloader: Set Exec-Never for Device Memory
Type PTE. The ARM spec (ARM DDI 0487J.a) says on page B2-216 ("Aarch64 Application Level Memory Model"): "Hardware does not prevent speculative instruction fetches from a memory location with any of the Device memory attributes unless the memory location is also marked as execute-never for all Exception levels." and "Failure to mark a memory location with any Device memory attribute as execute-never for all Exception levels is a programming error." Similar statements can be found in the chapter about the Aarch32 Application Level Memory Model for aarch32 mode. Signed-off-by: Andy Bui <andy.bui@nio.io>
1 parent c3c5e49 commit 3166422

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

elfloader-tool/include/arch-arm/64/mode/aarch64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@
6363
#define MT_NORMAL 4
6464
#define MT_NORMAL_WT 5
6565
#define MAIR(_attr, _mt) ((_attr) << ((_mt) * 8))
66+
67+
#define IS_DEV_MEM_INDEX(_idx) ((_idx) <= MT_DEVICE_GRE)

elfloader-tool/include/elfloader_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef uintptr_t vaddr_t;
1414

1515
#define PAGE_BITS 12
1616

17-
#define BIT(x) (1 << (x))
17+
#define BIT(x) (1ul << (x))
1818
#define MASK(n) (BIT(n) - 1)
1919
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
2020
#define IS_ALIGNED(n, b) (!((n) & MASK(b)))

elfloader-tool/src/arch-arm/64/mmu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ void init_boot_vspace(struct image_info *kernel_info)
3030
_boot_pgd_down[0] = ((uintptr_t)_boot_pud_down) | BIT(1) | BIT(0); /* its a page table */
3131

3232
for (i = 0; i < BIT(PUD_BITS); i++) {
33+
/* For exec-never bit(s), see Table D8-46 for EL2 translation regime (TR)
34+
* and Table D8-45 for all others.*/
3335
_boot_pud_down[i] = (i << ARM_1GB_BLOCK_BITS)
36+
| BIT(54) /* UXN */
37+
| BIT(53) /* PXN */
3438
| BIT(10) /* access flag */
3539
| (MT_DEVICE_nGnRnE << 2) /* strongly ordered memory */
3640
| BIT(0); /* 1G block */
@@ -68,7 +72,10 @@ void init_hyp_boot_vspace(struct image_info *kernel_info)
6872
_boot_pgd_down[0] = ((uintptr_t)_boot_pud_down) | BIT(1) | BIT(0);
6973

7074
for (i = 0; i < BIT(PUD_BITS); i++) {
75+
/* For exec-never bit(s), see Table D8-46 for EL2 translation regime (TR)
76+
* and Table D8-45 for all others. Note: for EL2 TR, PXN (bit 53) is RES0. */
7177
_boot_pud_down[i] = (i << ARM_1GB_BLOCK_BITS)
78+
| BIT(54) /* UXN */
7279
| BIT(10) /* access flag */
7380
| (MT_DEVICE_nGnRnE << 2) /* strongly ordered memory */
7481
| BIT(0); /* 1G block */

0 commit comments

Comments
 (0)