Skip to content

Commit 49cee36

Browse files
LeviYeoReumctmarinas
authored andcommitted
kselftest/arm64/mte: Add verification for address tag in signal handler
Add the address tag [63:60] verification when synchronous mte fault is happen. when signal handler is registered with SA_EXPOSE_TAGBITS, address includes not only memory tag [59:56] but also address tag. Therefore, when verify fault address location, remove both tags Signed-off-by: Yeoreum Yun <[email protected]> Reviewed-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent ed434c6 commit 49cee36

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

tools/testing/selftests/arm64/mte/mte_common_util.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,25 @@ static unsigned int mte_cur_pstate_tco;
3333

3434
void mte_default_handler(int signum, siginfo_t *si, void *uc)
3535
{
36+
struct sigaction sa;
3637
unsigned long addr = (unsigned long)si->si_addr;
38+
unsigned char si_tag, si_atag;
39+
40+
sigaction(signum, NULL, &sa);
41+
42+
if (sa.sa_flags & SA_EXPOSE_TAGBITS) {
43+
si_tag = MT_FETCH_TAG(addr);
44+
si_atag = MT_FETCH_ATAG(addr);
45+
addr = MT_CLEAR_TAGS(addr);
46+
} else {
47+
si_tag = 0;
48+
si_atag = 0;
49+
}
3750

3851
if (signum == SIGSEGV) {
3952
#ifdef DEBUG
40-
ksft_print_msg("INFO: SIGSEGV signal at pc=%lx, fault addr=%lx, si_code=%lx\n",
41-
((ucontext_t *)uc)->uc_mcontext.pc, addr, si->si_code);
53+
ksft_print_msg("INFO: SIGSEGV signal at pc=%lx, fault addr=%lx, si_code=%lx, si_tag=%x, si_atag=%x\n",
54+
((ucontext_t *)uc)->uc_mcontext.pc, addr, si->si_code, si_tag, si_atag);
4255
#endif
4356
if (si->si_code == SEGV_MTEAERR) {
4457
if (cur_mte_cxt.trig_si_code == si->si_code)
@@ -51,13 +64,18 @@ void mte_default_handler(int signum, siginfo_t *si, void *uc)
5164
}
5265
/* Compare the context for precise error */
5366
else if (si->si_code == SEGV_MTESERR) {
67+
if ((!mtefar_support && si_atag) || (si_atag != MT_FETCH_ATAG(cur_mte_cxt.trig_addr))) {
68+
ksft_print_msg("Invalid MTE synchronous exception caught for address tag! si_tag=%x, si_atag: %x\n", si_tag, si_atag);
69+
exit(KSFT_FAIL);
70+
}
71+
5472
if (cur_mte_cxt.trig_si_code == si->si_code &&
5573
((cur_mte_cxt.trig_range >= 0 &&
56-
addr >= MT_CLEAR_TAG(cur_mte_cxt.trig_addr) &&
57-
addr <= (MT_CLEAR_TAG(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)) ||
74+
addr >= MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) &&
75+
addr <= (MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)) ||
5876
(cur_mte_cxt.trig_range < 0 &&
59-
addr <= MT_CLEAR_TAG(cur_mte_cxt.trig_addr) &&
60-
addr >= (MT_CLEAR_TAG(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)))) {
77+
addr <= MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) &&
78+
addr >= (MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)))) {
6179
cur_mte_cxt.fault_valid = true;
6280
/* Adjust the pc by 4 */
6381
((ucontext_t *)uc)->uc_mcontext.pc += 4;
@@ -73,11 +91,11 @@ void mte_default_handler(int signum, siginfo_t *si, void *uc)
7391
ksft_print_msg("INFO: SIGBUS signal at pc=%llx, fault addr=%lx, si_code=%x\n",
7492
((ucontext_t *)uc)->uc_mcontext.pc, addr, si->si_code);
7593
if ((cur_mte_cxt.trig_range >= 0 &&
76-
addr >= MT_CLEAR_TAG(cur_mte_cxt.trig_addr) &&
77-
addr <= (MT_CLEAR_TAG(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)) ||
94+
addr >= MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) &&
95+
addr <= (MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range)) ||
7896
(cur_mte_cxt.trig_range < 0 &&
79-
addr <= MT_CLEAR_TAG(cur_mte_cxt.trig_addr) &&
80-
addr >= (MT_CLEAR_TAG(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range))) {
97+
addr <= MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) &&
98+
addr >= (MT_CLEAR_TAGS(cur_mte_cxt.trig_addr) + cur_mte_cxt.trig_range))) {
8199
cur_mte_cxt.fault_valid = true;
82100
/* Adjust the pc by 4 */
83101
((ucontext_t *)uc)->uc_mcontext.pc += 4;

0 commit comments

Comments
 (0)