Skip to contentSkip to conversation

ARM: alignment: Make SIGBUS sent to userspace POSIXly correct

PATCH New Dave Martin 3 participants 3 messages Jul 27, 2011 – Jul 28, 2011 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: alignment: Make SIGBUS sent to userspace POSIXly correct

With the UM_SIGNAL alignment fault mode, no siginfo structure is passed to userspace.

POSIX specifies how siginfo_t should be populated for alignment faults, so this patch does just that:

* si_signo = SIGBUS
* si_code = BUS_ADRALN
* si_addr = misaligned data address at which access was attempted

---
v2: si_addr in siginfo_t changed to contain the faulting data
access address, not the address of the faulting instruction.

This behaviour is consistent with the way other fault signals such as SIGSEGV are already reported, as well as matching the apparent intent of the POSIX sigaction interface.

 arch/arm/mm/alignment.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
arch/arm/mm/alignment.c +11 -3
index 724ba3b..65ed9c6 100644
@@ -22,6 +22,7 @@
 #include <linux/sched.h>
 #include <linux/uaccess.h>
 
+#include <asm/system.h>
 #include <asm/unaligned.h>
 
 #include "fault.h"
@@ -883,9 +884,16 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	if (ai_usermode & UM_FIXUP)
 		goto fixup;
 
-	if (ai_usermode & UM_SIGNAL)
-		force_sig(SIGBUS, current);
-	else {
+	if (ai_usermode & UM_SIGNAL) {
+		siginfo_t si;
+
+		si.si_signo = SIGBUS;
+		si.si_errno = 0;
+		si.si_code = BUS_ADRALN;
+		si.si_addr = (void __user *)addr;
+
+		force_sig_info(si.si_signo, &si, current);
+	} else {
 		/*
 		 * We're about to disable the alignment trap and return to
 		 * user space.  But if an interrupt occurs before actually
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v2 1/1 ARM: alignment: Make SIGBUS sent to userspace POSIXly correct

Quoted 10 lines · Dave Martin

With the UM_SIGNAL alignment fault mode, no siginfo structure is passed to userspace.

POSIX specifies how siginfo_t should be populated for alignment faults, so this patch does just that:

* si_signo = SIGBUS
* si_code = BUS_ADRALN
* si_addr = misaligned data address at which access was attempted

Quoted 8 lines

---
v2: si_addr in siginfo_t changed to contain the faulting data
access address, not the address of the faulting instruction.

This behaviour is consistent with the way other fault signals such as SIGSEGV are already reported, as well as matching the apparent intent of the POSIX sigaction interface.

Makes sense. ACK.

Quoted 39 lines
 arch/arm/mm/alignment.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
arch/arm/mm/alignment.c +11 -3
index 724ba3b..65ed9c6 100644
@@ -22,6 +22,7 @@
 #include <linux/sched.h>
 #include <linux/uaccess.h>
 
+#include <asm/system.h>
 #include <asm/unaligned.h>
 
 #include "fault.h"
@@ -883,9 +884,16 @@ do_alignment(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 	if (ai_usermode & UM_FIXUP)
 		goto fixup;
 
-	if (ai_usermode & UM_SIGNAL)
-		force_sig(SIGBUS, current);
-	else {
+	if (ai_usermode & UM_SIGNAL) {
+		siginfo_t si;
+
+		si.si_signo = SIGBUS;
+		si.si_errno = 0;
+		si.si_code = BUS_ADRALN;
+		si.si_addr = (void __user *)addr;
+
+		force_sig_info(si.si_signo, &si, current);
+	} else {
 		/*
 		 * We're about to disable the alignment trap and return to
 		 * user space.  But if an interrupt occurs before actually
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v2 1/1 ARM: alignment: Make SIGBUS sent to userspace POSIXly correct

In reply to Dave Martin
Quoted 10 lines · Dave Martin

With the UM_SIGNAL alignment fault mode, no siginfo structure is passed to userspace.

POSIX specifies how siginfo_t should be populated for alignment faults, so this patch does just that:

* si_signo = SIGBUS
* si_code = BUS_ADRALN
* si_addr = misaligned data address at which access was attempted

Quoted 8 lines

---
v2: si_addr in siginfo_t changed to contain the faulting data
access address, not the address of the faulting instruction.

This behaviour is consistent with the way other fault signals such as SIGSEGV are already reported, as well as matching the apparent intent of the POSIX sigaction interface.

Signature · 1 line
 Kirill A. Shutemov