Skip to content

Commit

Permalink
CLoadTags: Try accessing the first and last capability-size chunk
Browse files Browse the repository at this point in the history
Check that we can access the first and last capability-size chunk.
This also ensures that the bad access address is updated correctly
in case any of these addresses are not accessible.
In theory we should try to access the entire memory region (to match what
sail does), but first and last will be equivalent for trapping/RVFI.

Previously we were just checking the tag memory, which returns 0 for
unmapped memory regions, but we should trap if these accesses are prevent
e.g. by the PMP.
  • Loading branch information
arichardson committed Aug 3, 2023
1 parent a7013df commit 7a2fee0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion target/cheri-common/op_helper_cheri_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1607,8 +1607,18 @@ target_ulong CHERI_HELPER_IMPL(cloadtags(CPUArchState *env, uint32_t cb))
cbp, sizealign, raise_unaligned_load_exception);

target_ulong result = cheri_tag_get_many(env, addr, cb, NULL, GETPC());
/*
* Check that we can access the first and last capability-size chunk.
* This also ensures that the bad access address is updated correctly
* in case any of these addresses are not accessible.
* In theory we should try to access the entire memory region (to match what
* sail does), but first and last will be equivalent for trapping.
*/
(void)cpu_ld_cap_word_ra(env, addr, _host_return_address);
(void)cpu_ld_cap_word_ra(env, addr + sizealign - CHERI_CAP_SIZE,
_host_return_address);
#if defined(TARGET_RISCV) && defined(CONFIG_RVFI_DII)
/* For RVFI tracing, sail reports the valu of th last capability read. */
/* For RVFI tracing, sail reports the value of the last capability read. */
target_ulong unused1, unused2;
(void)load_cap_from_memory_raw(env, &unused1, &unused2, cb, cbp,
addr + sizealign - CHERI_CAP_SIZE,
Expand Down

0 comments on commit 7a2fee0

Please sign in to comment.