Skip to contentSkip to conversation

arm64: signal: Ensure si_code is valid for all fault signals

PATCH In review Dave Martin 2 participants 3 messages Mar 8, 2018 – Mar 9, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 arm64: signal: Ensure si_code is valid for all fault signals

Changes since v2:

* Rebased to v4.16-rc4.

* Split out the SIGFPE related changes (which impact core/x86 code) into a separate series.

Original blurb:

Currently, as reported by Eric, an invalid si_code value 0 is passed in many signals delivered to userspace in response to faults and other kernel errors. Typically 0 is passed when the fault is insufficiently diagnosable or when there does not appear to be any sensible alternative value to choose.

This appears to violate POSIX, and is intuitively wrong for at least two reasons arising from the fact that 0 == SI_USER:

1) si_code is a union selector, and SI_USER (and si_code <= 0 in general) implies the existence of a different set of fields (siginfo._kill) from that which exists for a fault signal (siginfo._sigfault). However, the code raising the signal typically writes only the _sigfault fields, and the _kill fields make no sense in this case.

Thus when userspace sees si_code == 0 (SI_USER) it may legitimately inspect fields in the inactive union member _kill and obtain garbage as a result.

There appears to be software in the wild relying on this, albeit generally only for printing diagnostic messages.

2) Software that wants to be robust against spurious signals may discard signals where si_code == SI_USER (or <= 0), or may filter such signals based on the si_uid and si_pid fields of siginfo._sigkill. In the case of fault signals, this means that important (and usually fatal) error conditions may be silently ignored.

In practice, many of the faults for which arm64 passes si_code == 0 are undiagnosable conditions such as exceptions with syndrome values in ESR_ELx to which the architecture does not yet assign any meaning, or conditions indicative of a bug or error in the kernel or system and thus that are unrecoverable and should never occur in normal operation.

The approach taken in this patch is to translate all such undiagnosable or "impossible" synchronous fault conditions to SIGKILL, since these are at least probably localisable to a single process. Some of these conditions should really result in a kernel panic, but due to the lack of diagnostic information it is difficult to be certain: this patch does not add any calls to panic(), but this could change later if justified.

Although si_code will not reach userspace in the case of SIGKILL, it is still desirable to pass a nonzero value so that the common siginfo handling code can detect incorrect use of si_code == 0 without false positives. In this case the si_code dependent siginfo fields will not be correctly initialised, but since they are not passed to userspace I deem this not to matter.

A few faults can reasonably occur in realistic userspace scenarios, and _should_ raise a regular, handleable (but perhaps not ignorable/blockable) signal: for these, this patch attempts to choose a suitable standard si_code value for the raised signal in each case instead of 0.

arm64 was the only arch to define a BUS_FIXME code, so after this patch nobody defines it. This patch therefore also removes the relevant code from siginfo_layout().

---

 arch/arm64/include/uapi/asm/siginfo.h |  14 ----
 arch/arm64/kernel/fpsimd.c            |   4 +-
 arch/arm64/mm/fault.c                 | 116 +++++++++++++++++-----------------
 kernel/signal.c                       |   4 --
 4 files changed, 60 insertions(+), 78 deletions(-)
arch/arm64/include/uapi/asm/siginfo.h +0 -14
index 9b4d912..8d7dbbc 100644
@@ -28,18 +28,4 @@
 #define FPE_FIXME	0	/* Broken dup of SI_USER */
 #endif /* __KERNEL__ */
 
-/*
- * SIGBUS si_codes
- */
-#ifdef __KERNEL__
-#define BUS_FIXME	0	/* Broken dup of SI_USER */
-#endif /* __KERNEL__ */
-
-/*
- * SIGTRAP si_codes
- */
-#ifdef __KERNEL__
-#define TRAP_FIXME	0	/* Broken dup of SI_USER */
-#endif /* __KERNEL__ */
-
 #endif
arch/arm64/kernel/fpsimd.c +2 -2
index e7226c4..c2e87a20 100644
@@ -285,8 +285,8 @@ static void task_fpsimd_save(void)
 				 * re-enter user with corrupt state.
 				 * There's no way to recover, so kill it:
 				 */
-				force_signal_inject(
-					SIGKILL, 0, current_pt_regs(), 0);
+				force_signal_inject(SIGKILL, SI_KERNEL,
+						    current_pt_regs(), 0);
 				return;
 			}
 
arch/arm64/mm/fault.c +58 -58

148 lines not on this page · raw message

kernel/signal.c +0 -4
index c6e4c83d..049a482 100644
@@ -2844,10 +2844,6 @@ enum siginfo_layout siginfo_layout(int sig, int si_code)
 		if ((sig == SIGFPE) && (si_code == FPE_FIXME))
 			layout = SIL_FAULT;
 #endif
-#ifdef BUS_FIXME
-		if ((sig == SIGBUS) && (si_code == BUS_FIXME))
-			layout = SIL_FAULT;
-#endif
 	}
 	return layout;
 }
Signature · 1 line
2.1.4
#1 lore raw

Hi Dave,

Thanks for resending this one separately -- I'll pick it up for 4.17. Just a minor thing:

Quoted 8 lines · Dave Martin

Changes since v2:

* Rebased to v4.16-rc4.

* Split out the SIGFPE related changes (which impact core/x86 code) into a separate series.

Original blurb:

In future, please put this sort of stuff ^^ after the '---', otherwise I have to manually remove it from the commit message when committing and one day I'll end up forgetting.

Cheers,

Will

#2 lore raw

Re: [PATCH v3] arm64: signal: Ensure si_code is valid for all fault signalsy

Quoted 10 lines · Will Deacon

Hi Dave,

Thanks for resending this one separately -- I'll pick it up for 4.17. Just a minor thing:

Quoted 4 lines · Dave Martin

Changes since v2:

* Rebased to v4.16-rc4.

Quoted 8 lines
Quoted 4 lines

* Split out the SIGFPE related changes (which impact core/x86 code) into a separate series.

Original blurb:

In future, please put this sort of stuff ^^ after the '---', otherwise I have to manually remove it from the commit message when committing and one day I'll end up forgetting.

Oops, yes, just trim that off. I'd moved that changelog from the tearoff to the top of the "cover letter" for reviewer convenience, but guess what, there's no cover letter now I've split this patch by itself.

[removes face from palm]

Cheers
---Dave