Skip to content

Commit 2733f4b

Browse files
committed
[Headers] Trap on caprelocs with unknown permissions
This is error-prone in case new bit patterns are allocated, as will shortly be done. We can't fix that problem for existing versions, but we can avoid it going forwards.
1 parent 6e1131b commit 2733f4b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clang/lib/Headers/cheri_init_globals.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,16 @@ cheri_init_globals_impl(const struct capreloc *start_relocs,
171171
data_cap, reloc->capability_location + base_addr);
172172
const void *__capability base_cap;
173173
bool can_set_bounds = true;
174-
if ((reloc->permissions & function_reloc_flag) == function_reloc_flag) {
174+
if (reloc->permissions == function_reloc_flag) {
175175
base_cap = code_cap; /* code pointer */
176176
/* Do not set tight bounds for functions (unless we are in the plt ABI) */
177177
can_set_bounds = tight_code_bounds;
178-
} else if ((reloc->permissions & constant_reloc_flag) ==
179-
constant_reloc_flag) {
178+
} else if (reloc->permissions == constant_reloc_flag) {
180179
base_cap = rodata_cap; /* read-only data pointer */
181-
} else {
180+
} else if (reloc->permissions == 0) {
182181
base_cap = data_cap; /* read-write data */
182+
} else {
183+
__builtin_trap(); /* unknown permissions */
183184
}
184185
const void *__capability src =
185186
cheri_address_or_offset_set(base_cap, reloc->object + base_addr);

0 commit comments

Comments
 (0)