5.5 Access permissions
Stage 1 permissions are built in layers. Conceptually they compose as follows (the Arm ARM pseudocode interleaves some steps, for example WXN is evaluated together with the overlay, but every layer after the first can only remove permission):
- The base permission comes from the descriptor. It is either direct (the
AP/XNbits) or indirect (an index intoPIR_ELx, with FEAT_S1PIE). - Hierarchical restrictions from table descriptors are applied, unless they are disabled.
- Global modifiers are applied:
WXN, the implicit “EL0-writable is never EL1-executable” rule, PAN/EPAN, and the unprivileged-access rules. - A permission overlay (FEAT_S1POE) can only remove permissions.
- If stage 2 is active, its permissions are intersected with the result (11.3).
A failure at any step is a Permission fault (DFSC 0b0011LL, where LL is the level of the final descriptor). Decode is in 5.8.
Direct permissions: AP[2:1], UXN, PXN
AP[2:1] (descriptor bits [7:6]) in a two-range regime (EL1&0, EL2&0):
AP[2:1] | Privileged (EL1 or EL2) | Unprivileged (EL0) |
|---|---|---|
00 | Read/write | None |
01 | Read/write | Read/write |
10 | Read-only | None |
11 | Read-only | Read-only |
AP[2] selects read-only, and AP[1] grants EL0 access. In the single-range regimes (EL2 with E2H=0, EL3), there is no EL0, so AP[1] is RES1 (TF-A sets it as AP_ONE_VA_RANGE_RES1) and only AP[2] matters.
Execute permission is separate from read permission. In two-range regimes, UXN (bit 54) forbids execution at EL0 and PXN (bit 53) at the privileged EL. In single-range regimes, bit 54 is XN and bit 53 is RES0. Two architectural rules add to these bits:
- EL0-writable memory is never privileged-executable. In the EL1&0 regime, any location with
AP[2:1] = 01is treated asPXNfor EL1, whatever bit 53 says. The EL2&0 regime has the same rule for EL2. Kernel code cannot be planted through a user-writable mapping. SCTLR_ELx.WXN = 1treats every writable location as execute-never for the regime (under direct permissions; with PIE,WXNaffects only thePIRencoding0110, see below).WXNis permitted to be cached in TLB entries, so changing it needs a TLB invalidate for the regime, not just anISB.
Security note: At EL3, also set
SCR_EL3.SIF. It makes a Secure-state instruction fetch from a Non-secure PA a Permission fault, even when the EL3 or S-EL1 tables mark the page executable. A stray EL3 table entry that maps normal-world memory as executable then cannot be turned into code execution.
Hierarchical permissions: APTable, XNTable, PXNTable
Table descriptors can restrict everything below them:
| Field | Bits | Effect on all subsequent levels |
|---|---|---|
APTable[1:0] | [62:61] | x1: no EL0 access; 1x: no write access at any EL (APTable[0] RES0 in single-range regimes) |
UXNTable (XNTable) | [60] | Execute-never at EL0 (at all ELs in single-range regimes) |
PXNTable | [59] | Execute-never at the privileged EL |
They can only remove permission, never grant it. TCR_ELx.HPD0/HPD1 (FEAT_HPDS, v8.1; TCR_EL3.HPD, TCR_EL2.HPD) makes the walk ignore them, which frees the bits for PBHA (FEAT_HPDS2). When stage 1 permission indirection is enabled, hierarchical permissions are disabled as if HPD were 1, because the PIE model has no table-level counterpart. The same happens when a stage 1 permission overlay (TCR2_ELx.POE or E0POE) is enabled. Firmware that relies on APTable to make a whole subtree read-only loses that protection silently when PIE or POE is switched on.
PAN, EPAN, UAO and unprivileged accesses
PAN (FEAT_PAN, v8.1). When PSTATE.PAN = 1, a privileged data access (at EL1, or at EL2 in the EL2&0 regime) to a location that EL0 can access (AP[1] = 1) takes a Permission fault. Instruction fetches are not affected. SCTLR_EL1.SPAN = 0 makes the PE set PSTATE.PAN automatically on exception entry to EL1 (SCTLR_EL2.SPAN does the same for EL2 with E2H=1), so a kernel does not have a window between taking an exception and setting PAN. Software flips PAN cheaply with MSR PAN, #imm.
FEAT_PAN2 (v8.2) adds AT S1E1RP and AT S1E1WP, which translate with the current PSTATE.PAN applied. Plain AT S1E1R/W ignore PAN.
EPAN (FEAT_PAN3, v8.7). PAN keys off AP[1], so an execute-only user mapping (AP = 00, UXN = 0: EL0 may only execute, and EL1 has RW) was not covered. A kernel could be tricked into reading user code through it. With SCTLR_ELx.EPAN = 1, PAN also faults privileged data accesses to locations that are executable at EL0.
Unprivileged loads and stores (LDTR*, STTR*, and the unprivileged FEAT_MOPS forms) executed at EL1 are checked against EL0 permissions. The same holds at EL2 with E2H = TGE = 1. PAN does not fault them, because they are not privileged accesses. That is the intended way for a kernel to copy to and from user memory: PAN stays on, and the access is checked as if EL0 had made it.
UAO (FEAT_UAO, v8.2). With PSTATE.UAO = 1, LDTR*/STTR* at EL1 (and at EL2 in EL2&0) use the privileged permissions instead. Linux once used it to run the same copy_*_user code on kernel addresses (set_fs(KERNEL_DS)), and has since removed it. New code has no reason to set UAO.
Permission indirection (FEAT_S1PIE, FEAT_S2PIE)
With TCR2_EL1.PIE = 1 (or TCR2_EL2.PIE, or TCR_EL3.PIE), the stage 1 permission bits no longer encode permissions directly. Four descriptor bits form a 4-bit PIIndex:
| PIIndex bit | 3 | 2 | 1 | 0 |
|---|---|---|---|---|
| Descriptor bit | 54 (UXN) | 53 (PXN) | 51 (DBM) | 6 (AP[1]) |
The index selects a 4-bit field in two registers: PIR_ELx for privileged accesses and PIRE0_ELx for EL0 accesses in two-range regimes. The EL3 regime has PIR_EL3 only. Selected Perm encodings:
| Encoding | Permission | Overlay |
|---|---|---|
0000 | No access | Applied |
0001 | Read | Applied |
0010 | Execute only | Applied |
0011 | Read, execute | Applied |
0101 | Read, write | Applied |
0110 | Read, write, execute; execute is removed when SCTLR_ELx.WXN = 1 | Applied |
0111 | Read, write, execute | Applied |
1000 | Read | Not applied |
1001 | Read, plus GCS read/write (13.2) | Not applied |
1010 | Read, execute | Not applied |
1100 | Read, write | Not applied |
1110 | Read, write, execute | Not applied |
The remaining encodings (0100, 1011, 1101, 1111) are reserved and give no access. See the PIR_EL1 register description. 0110 is the only encoding that WXN affects under PIE. The implicit “EL0-writable is never privileged-executable” rule also survives, in a stronger form: if the selected PIR entry grants privileged execute and the PIRE0 entry grants EL0 write, the location gives no access at all. Three properties matter:
- Permissions become a table that software designs. The OS picks up to 16 page “types” (kernel text, user execute-only, GCS stack and so on), and the descriptor carries only the type number. A true EL0 execute-only page with no EL1 access, which direct permissions cannot express, is one PIR/PIRE0 pair of entries.
- PIR contents may be cached in TLBs. Changing
PIR_ELxafter enabling therefore needs TLB maintenance. Treat the registers as boot-time constants. - PIE is required by FEAT_D128. With
TCR2_EL1.D128 = 1, the indirect scheme is always in effect, because the 128-bit format has no direct-permission encoding (5.7).
The stage 2 counterpart (FEAT_S2PIE) is enabled by VTCR_EL2.S2PIE and uses S2PIR_EL2. Its index is formed from the stage 2 permission bits. See 11.3.
Permission overlays (FEAT_S1POE, FEAT_S2POE)
An overlay is a second, per-thread permission layer. With POE enabled, descriptor bits [62:60] are a 3-bit POIndex, which selects a 4-bit field in a Permission Overlay Register:
POR_EL0for EL0 accesses (enabled byTCR2_EL1.E0POE);POR_EL1for EL1 accesses (enabled byTCR2_EL1.POE);POR_EL2/POR_EL3for those regimes (TCR2_EL2.POE,TCR_EL3.POE).
POR field | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
|---|---|---|---|---|---|---|---|---|
| Permits | none | R | X | RX | W | RW | WX | RWX |
Values 1xxx are reserved and give no access.
The effective permission is base ∩ overlay. The overlay can only restrict. With PIE enabled, it applies only where the selected PIR encoding says “overlay applied”. Under direct permissions, it applies to every access of the enabled kind (privileged for POE, EL0 for E0POE). When the overlay is in use and WXN = 1, an overlay value that grants execute has its write permission removed instead. The bits [62:60] overlap the PBHA bits, so a platform cannot use both for the same descriptors.
The TCR2 enable bits are not permitted to be cached in TLBs. The overlay registers are system registers that a thread can switch with an MSR + ISB, without touching page tables or TLBs. That is the point of the feature: the page tables stay shared, and each thread holds its own view of them. An overlay violation is reported as a Permission fault with ESR_ELx.ISS2.Overlay set, which distinguishes it from a base-permission fault. Stage 2 overlays (FEAT_S2POE, enabled by VTCR_EL2.S2POE, indexed by bits of the stage 2 descriptor) apply the same idea to stage 2. Their register, S2POR_EL1, is an EL1-accessible register (trappable through the EL2 fine-grained traps), so it can be switched as part of a guest’s context while the stage 2 tables stay shared (11.3).
FEAT_S1PIE, S2PIE, S1POE, S2POE and TCR2 are Armv8.9/v9.4 (2022) extensions. For their permitted-from versions, see DDI0487 A2. Before EL1 can use them, EL3 must enable access: SCR_EL3.TCR2En and SCR_EL3.PIEn (which covers the PIR/POR registers). Under EL2, HCRX_EL2.TCR2En and the fine-grained trap controls for those registers must also allow EL1 access. The checklist is in 17.3.
Security note:
POR_EL0is user-controlled protection keys, the Arm equivalent of x86 PKU, and Linux exposes it throughpkey_alloc()/pkey_mprotect(). A process can tag its secret-holding pages with key k and give itself access only around the code that needs them:// grant RW for key 1 only for this window mrs x9, por_el0 bfi x9, x10, #4, #4 // x10 = 0b0101 (RW) into Perm1 msr por_el0, x9 isb ldr x0, [x1] // access the protected page ...This is an isolation and bug-containment tool, not a security boundary against code that already executes in the process. Any attacker who reaches an
MSR POR_EL0gadget can rewrite the register. Make it robust with control-flow integrity, so that such gadgets cannot be reached: BTI and PAC (13.1) and GCS (13.2). Also make sure that signal delivery savesPOR_EL0and sets a known value for the handler (Linux does this), so a handler does not inherit a window that happened to be open. Because the kernel’sPOR_EL1is separate, user keys never weaken kernel accesses. A kernel copying to user memory withSTTRis checked againstPOR_EL0, which is the correct behaviour.
Validation note: Build a permission matrix test. For each PIIndex (0–15) × {EL0, EL1} × {read, write, execute} × {PAN 0/1} × {overlay on/off}, predict the outcome from the
PIR/PIRE0/PORvalues, perform the access, and compare against the result and theESR(DFSC level andISS2.Overlay). Run every cell with bothAT S1E1R/W/AT S1E0R/Wand a real access: anAT/access disagreement is a walker bug. Cover theTCR2En = 0case: theMSRmust trap, and the walker must behave as if everyTCR2_EL1field were 0 (no PIE, no overlay), whatever value was previously written.
Checkpoint
Q5.5.1 A kernel maps a user page with AP[2:1] = 01 and PXN = 0, and then jumps to it at EL1. What happens?
- A. It executes, because
PXNis clear and PAN does not apply to instruction fetches - B. It takes a Permission fault, because memory writable at EL0 is always treated as PXN at EL1
- C. It executes only if
SCTLR_EL1.WXN = 0 - D. It faults only when
PSTATE.PAN = 1
Answer
B. In the EL1&0 regime, locations that EL0 can write are treated as privileged execute-never, independent of the PXN bit, WXN and PAN. Option A correctly says PAN ignores fetches, but misses this separate implicit rule.
Read more: Arm ARM (DDI0487), “Instruction execution permissions”, “Access permissions for instruction execution”
Q5.5.2 With PSTATE.PAN = 1 and SCTLR_EL1.EPAN = 0, a user mapping has AP[2:1] = 00, UXN = 0 (execute-only for EL0). Which EL1 access succeeds, and why does EPAN exist?
- A. None. PAN blocks all EL1 accesses to user pages
- B.
LDTRsucceeds, and EPAN exists to blockLDTR - C. A plain
LDRfaults, because PAN checksUXN - D. A plain
LDRsucceeds, because PAN only checksAP[1], which is 0 here. EPAN extends PAN to EL0-executable locations to close this gap
Answer
D. AP = 00 means EL1 RW and EL0 no data access, so PAN (which tests EL0 data accessibility) does not fire, and the kernel can read user code. FEAT_PAN3/EPAN adds “executable at EL0” to the PAN condition. Option B is wrong because LDTR is checked against EL0 permissions, and EL0 has no read access here, so LDTR would fault.
Read more: Arm ARM (DDI0487), SCTLR_EL1.EPAN, “PSTATE.PAN”
Q5.5.3 A hypervisor-free EL1 OS enables TCR2_EL1.PIE. Its tables mark a whole kernel-data subtree read-only through APTable = 0b10 in an L1 table descriptor. After enabling PIE, a store to that subtree succeeds. Why?
- A. With permission indirection enabled, hierarchical permissions are disabled, so
APTableis ignored - B.
APTableonly affects EL0 - C.
PIR_EL1caching made the old permissions stale, and a TLBI would fix it - D.
APTable = 0b10is reserved under PIE and grants write access
Answer
A. Enabling stage 1 PIE disables hierarchical permission controls, as if HPD were set. The protection must move into the PIIndex of each leaf descriptor. Option C is a real concern for later changes to PIR_EL1, but it does not explain a write being allowed through a table that is meant to forbid it.
Read more: Arm ARM (DDI0487), “Hierarchical permissions”, “Stage 1 indirect permissions”; TCR2_EL1.PIE