Skip to contentSkip to conversation

ARM: Fix unparseable signal frame with CONFIG_IWMMXT

RFC PATCH New Dave Martin 2 participants 6 messages Jun 27, 2017 – Jun 28, 2017 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v2 cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT

Changes since RFC v1:

* Emit a dummy block instead of omitting ixmmxt_sigframe. A new magic, DUMMY_MAGIC, is defined for this purpose.

* Optionally consume the dummy block on sigreturn, but don't maintain it in case some userspace is crafting its own sigframes.

Limited manual testing, but not tested on iWMMXt hardware so far.

Original blurb:

In kernels with CONFIG_IWMMXT=y running on non-iWMMXt hardware, the signal frame can be left partially uninitialised in such a way that userspace cannot parse uc_regspace[] safely. In particular, this means that the VFP registers cannot be located reliably in the signal frame when a multi_v7_defconfig kernel is run on the majority of platforms.

I don't know whether any userspace has implemented any sort of workaround for this, but the ABI by itself is insufficient anyway.

This series attempts to omit the spurious iWMMXt record when appropriate.

Not extensively tested, and the ABI impact is unknown for now.

Dave Martin (2):
ARM: iwmmxt: Add missing __user annotations to sigframe accessors
ARM: signal: Fix unparseable iwmmxt_sigframe in uc_regspace[]

 arch/arm/include/asm/ucontext.h |  6 ++++
 arch/arm/kernel/signal.c        | 79 +++++++++++++++++++++++++++++++----------
 2 files changed, 67 insertions(+), 18 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

RFC PATCH v2 1/2 ARM: iwmmxt: Add missing __user annotations to sigframe accessors

preserve_iwmmxt_context() and restore_iwmmxt_context() lack __user accessors on their arguments pointing to the user signal frame.

There does not be appear to be a bug here, but this omission is inconsistent with the crunch and vfp sigframe access functions.

This patch adds the annotations, for consistency.

---
 arch/arm/kernel/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/signal.c +2 -2
index 7b8f214..8f06480 100644
@@ -59,7 +59,7 @@ static int restore_crunch_context(struct crunch_sigframe __user *frame)
 
 #ifdef CONFIG_IWMMXT
 
-static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
+static int preserve_iwmmxt_context(struct iwmmxt_sigframe __user *frame)
 {
 	char kbuf[sizeof(*frame) + 8];
 	struct iwmmxt_sigframe *kframe;
@@ -72,7 +72,7 @@ static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
 	return __copy_to_user(frame, kframe, sizeof(*frame));
 }
 
-static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
+static int restore_iwmmxt_context(struct iwmmxt_sigframe __user *frame)
 {
 	char kbuf[sizeof(*frame) + 8];
 	struct iwmmxt_sigframe *kframe;
Signature · 1 line
2.1.4
#2 lore raw

RFC PATCH v2 1/2 ARM: iwmmxt: Add missing __user annotations to sigframe accessors

Quoted 9 lines · Dave Martin

preserve_iwmmxt_context() and restore_iwmmxt_context() lack __user accessors on their arguments pointing to the user signal frame.

There does not be appear to be a bug here, but this omission is inconsistent with the crunch and vfp sigframe access functions.

This patch adds the annotations, for consistency.

Absolutely the right thing to do. Please drop this into the patch system, thanks.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#3 lore raw

RFC PATCH v2 2/2 ARM: signal: Fix unparseable iwmmxt_sigframe in uc_regspace[]

In reply to Dave Martin

In kernels with CONFIG_IWMMXT=y running on non-iWMMXt hardware, the signal frame can be left partially uninitialised in such a way that userspace cannot parse uc_regspace[] safely. In particular, this means that the VFP registers cannot be located reliably in the signal frame when a multi_v7_defconfig kernel is run on the majority of platforms.

The cause is that the uc_regspace[] is laid out statically based on the kernel config, but the decision of whether to save/restore the iWMMXt registers must be a runtime decision.

To minimise breakage of software that may assume a fixed layout, this patch emits a dummy block of the same size as iwmmxt_sigframe, for non-iWMMXt threads. However, the magic and size of this block are now filled in to help parsers skip over it. A new DUMMY_MAGIC is defined for this purpose.

It is probably legitimate (if non-portable) for userspace to manufacture its own sigframe for sigreturn, and there is no obvious reason why userspace should be required to insert a DUMMY_MAGIC block when running on non-iWMMXt hardware, when omitting it has worked just fine forever in other configurations. So in this case, sigreturn does not require this block to be present.

---
 arch/arm/include/asm/ucontext.h |  6 ++++
 arch/arm/kernel/signal.c        | 77 ++++++++++++++++++++++++++++++++---------
 2 files changed, 66 insertions(+), 17 deletions(-)
arch/arm/include/asm/ucontext.h +6 -0
index 14749ae..921d827 100644
@@ -35,6 +35,12 @@ struct ucontext {
  * bytes, to prevent unpredictable padding in the signal frame.
  */
 
+/*
+ * Dummy padding block: if this magic is encountered, the block should
+ * be skipped using the corresponding size field.
+ */
+#define DUMMY_MAGIC		0xb0d9ed01
+
 #ifdef CONFIG_CRUNCH
 #define CRUNCH_MAGIC		0x5065cf03
 #define CRUNCH_STORAGE_SIZE	(CRUNCH_SIZE + 8)
arch/arm/kernel/signal.c +60 -17

147 lines not on this page · raw message

Signature · 1 line
2.1.4
#4 lore raw

RFC PATCH v2 2/2 ARM: signal: Fix unparseable iwmmxt_sigframe in uc_regspace[]

Quoted 24 lines · Dave Martin

In kernels with CONFIG_IWMMXT=y running on non-iWMMXt hardware, the signal frame can be left partially uninitialised in such a way that userspace cannot parse uc_regspace[] safely. In particular, this means that the VFP registers cannot be located reliably in the signal frame when a multi_v7_defconfig kernel is run on the majority of platforms.

The cause is that the uc_regspace[] is laid out statically based on the kernel config, but the decision of whether to save/restore the iWMMXt registers must be a runtime decision.

To minimise breakage of software that may assume a fixed layout, this patch emits a dummy block of the same size as iwmmxt_sigframe, for non-iWMMXt threads. However, the magic and size of this block are now filled in to help parsers skip over it. A new DUMMY_MAGIC is defined for this purpose.

It is probably legitimate (if non-portable) for userspace to manufacture its own sigframe for sigreturn, and there is no obvious reason why userspace should be required to insert a DUMMY_MAGIC block when running on non-iWMMXt hardware, when omitting it has worked just fine forever in other configurations. So in this case, sigreturn does not require this block to be present.

Quoted 2 lines

This looks fine to me. Please drop it in the patch system, thanks.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#5 lore raw

RFC PATCH v2 2/2 ARM: signal: Fix unparseable iwmmxt_sigframe in uc_regspace[]

Quoted 25 lines · Russell King - ARM Linux
Quoted 24 lines · Dave Martin

In kernels with CONFIG_IWMMXT=y running on non-iWMMXt hardware, the signal frame can be left partially uninitialised in such a way that userspace cannot parse uc_regspace[] safely. In particular, this means that the VFP registers cannot be located reliably in the signal frame when a multi_v7_defconfig kernel is run on the majority of platforms.

The cause is that the uc_regspace[] is laid out statically based on the kernel config, but the decision of whether to save/restore the iWMMXt registers must be a runtime decision.

To minimise breakage of software that may assume a fixed layout, this patch emits a dummy block of the same size as iwmmxt_sigframe, for non-iWMMXt threads. However, the magic and size of this block are now filled in to help parsers skip over it. A new DUMMY_MAGIC is defined for this purpose.

It is probably legitimate (if non-portable) for userspace to manufacture its own sigframe for sigreturn, and there is no obvious reason why userspace should be required to insert a DUMMY_MAGIC block when running on non-iWMMXt hardware, when omitting it has worked just fine forever in other configurations. So in this case, sigreturn does not require this block to be present.

Quoted 4 lines
Quoted 2 lines

This looks fine to me. Please drop it in the patch system, thanks.

Do you have a view on whether I should Cc-stable on this?

The patches seem to apply cleanly back to v3.4, but I'm not in a position to test that far back easily.

As a reference point, Debian stretch seems to use v4.9.x for its multiplatform distro kernel, so it may be worth going at least that far back. (jessie uses v3.16.x.)

Cheers
---Dave