Skip to content
Permalink
Browse files
arm64: armv8_deprecated: Fix swp_handler() signal generation
arm64_notify_segfault() was written to decide on the si_code from the
assembly emulation of the swp_handler(), but was also used for the
signal generation from failed access_ok() and unaligned instructions.

When access_ok() fails, there is no need to search for the offending
address in the VMA space.  Instead, simply set the error to SIGSEGV with
si_code SEGV_ACCERR.

Change the return code from emulate_swpX() when there is an unaligned
pointer so the caller can differentiate from the EFAULT.  It is
unnecessary to search the VMAs in the case of an unaligned pointer.
This change uses SIGSEGV and SEGV_ACCERR instead of SIGBUS to keep with
what was returned before.

Fixes: bd35a4a (arm64: Port SWP/SWPB emulation support from arm)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
  • Loading branch information
howlett authored and intel-lab-lkp committed Apr 20, 2021
1 parent a27a881 commit 96a011695861072d32851ba3a104b19106955869
Showing 1 changed file with 13 additions and 7 deletions.
@@ -324,7 +324,7 @@ static int emulate_swpX(unsigned int address, unsigned int *data,
if ((type != TYPE_SWPB) && (address & 0x3)) {
/* SWP to unaligned address not permitted */
pr_debug("SWP instruction on unaligned pointer!\n");
return -EFAULT;
return -ENXIO;
}

while (1) {
@@ -406,15 +406,17 @@ static int swp_handler(struct pt_regs *regs, u32 instr)
user_ptr = (const void __user *)(unsigned long)(address & ~3);
if (!access_ok(user_ptr, 4)) {
pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
address);
goto fault;
address);
goto e_access;
}

res = emulate_swpX(address, &data, type);
if (res == -EFAULT)
goto fault;
else if (res == 0)
if (!res)
regs->user_regs.regs[destreg] = data;
else if (res == -EFAULT)
goto e_fault;
else if (res = -ENXIO) /* Unaligned pointer */
goto e_align;

ret:
if (type == TYPE_SWPB)
@@ -428,10 +430,14 @@ static int swp_handler(struct pt_regs *regs, u32 instr)
arm64_skip_faulting_instruction(regs, 4);
return 0;

fault:
e_fault:
pr_debug("SWP{B} emulation: access caused memory abort!\n");
arm64_notify_segfault(address);
return 0;

e_align:
e_access:
force_signal_inject(SIGSEGV, SEGV_ACCERR, address, 0);
return 0;
}

0 comments on commit 96a0116

Please sign in to comment.