Skip to content

Commit f2995bc

Browse files
Nicolas Pitrenashif
Nicolas Pitre
authored andcommitted
aarch64: arch_buffer_validate() implementation
This leverages the AT (address translation) instruction to test for given access permission. The result is then provided in the PAR_EL1 register. Thanks to @jharris-intel for the suggestion. Signed-off-by: Nicolas Pitre <[email protected]>
1 parent 9ec1c1a commit f2995bc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

arch/arm/core/aarch64/userspace.S

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ strlen_done:
4949
str w4, [x2]
5050
ret
5151

52+
/*
53+
* int arch_buffer_validate(void *addr, size_t size, int write)
54+
*/
55+
56+
GTEXT(arch_buffer_validate)
57+
SECTION_FUNC(TEXT, arch_buffer_validate)
58+
59+
add x1, x1, x0
60+
mrs x3, DAIF
61+
msr DAIFSET, #DAIFSET_IRQ_BIT
62+
63+
abv_loop:
64+
cbnz w2, 1f
65+
at S1E0R, x0
66+
b 2f
67+
1: at S1E0W, x0
68+
69+
2: orr x0, x0, #(CONFIG_MMU_PAGE_SIZE - 1)
70+
add x0, x0, #1
71+
72+
isb
73+
mrs x4, PAR_EL1
74+
tbnz x4, #0, abv_fail
75+
76+
cmp x0, x1
77+
blo abv_loop
78+
79+
msr DAIF, x3
80+
mov x0, #0
81+
ret
82+
83+
abv_fail:
84+
msr DAIF, x3
85+
mov x0, #-1
86+
ret
87+
5288
/*
5389
* Routine to jump into userspace
5490
*

0 commit comments

Comments
 (0)