[PATCH] arm64: mm: unaligned access by user-land should be received as SIGBUS

Victor Kamensky kamensky at cisco.com
Sun Apr 2 22:45:14 PDT 2017


After 52d7523 (arm64: mm: allow the kernel to handle alignment faults on
user accesses) commit user-land accesses that produce unaligned exceptions
like in case of aarch32 ldm/stm/ldrd/strd instructions operating on
unaligned memory received by user-land as SIGSEGV. It is wrong, it should
be reported as SIGBUS as it was before 52d7523 commit.

Changed do_bad_area function to take signal and code parameters, so caller
can pass them down properly depending on fault type, as SIGSEGV in case of
do_translation_fault and SIGBUS in case of do_alignment_fault.

Signed-off-by: Victor Kamensky <kamensky at cisco.com>
Cc: xe-linux-external at cisco.com
Fixes: 52d7523 (arm64: mm: allow the kernel to handle alignment faults on user accesses)
---
 arch/arm64/mm/fault.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 4bf899f..204eb58 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -215,7 +215,8 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr,
 	force_sig_info(sig, &si, tsk);
 }
 
-static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *regs)
+static void do_bad_area(unsigned long addr, unsigned int esr,
+			struct pt_regs *regs, int sig, int code)
 {
 	struct task_struct *tsk = current;
 	struct mm_struct *mm = tsk->active_mm;
@@ -225,7 +226,7 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re
 	 * handle this fault with.
 	 */
 	if (user_mode(regs))
-		__do_user_fault(tsk, addr, esr, SIGSEGV, SEGV_MAPERR, regs);
+		__do_user_fault(tsk, addr, esr, sig, code, regs);
 	else
 		__do_kernel_fault(mm, addr, esr, regs);
 }
@@ -469,14 +470,14 @@ static int __kprobes do_translation_fault(unsigned long addr,
 	if (addr < TASK_SIZE)
 		return do_page_fault(addr, esr, regs);
 
-	do_bad_area(addr, esr, regs);
+	do_bad_area(addr, esr, regs, SIGSEGV, SEGV_MAPERR);
 	return 0;
 }
 
 static int do_alignment_fault(unsigned long addr, unsigned int esr,
 			      struct pt_regs *regs)
 {
-	do_bad_area(addr, esr, regs);
+	do_bad_area(addr, esr, regs, SIGBUS,  BUS_ADRALN);
 	return 0;
 }
 
-- 
1.9.3




More information about the linux-arm-kernel mailing list