ARM: Fix unparseable signal frame with CONFIG_IWMMXT
cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
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: Remove unparseable iwmmxt_sigframe from uc_regspace[]
arch/arm/include/asm/ucontext.h | 20 ---------------- arch/arm/kernel/signal.c | 52 +++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 37 deletions(-)
Signature · 1 line
2.1.4
RFC PATCH 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
@@ -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
RFC PATCH 2/2 ARM: signal: Remove unparseable iwmmxt_sigframe from uc_regspace[]
In reply to Dave MartinIn 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. There is no obvious way to pad the hole left when the iWMMXt registers are not saved, because there is no dummy record type that we can rely on userspace to ignore, and no clear semantics for what an iwmmxt_sigframe record is supposed to mean if the hardware doesn't support iXMMXt.
One option would be to write the magic and size for iwmmxt_sigframe, and leave the body uninitialised or fill it with zeros or deadc0de. But this may confuse userspace if it is taken as evidence that iWMMXt is present.
However, there seems to be a clear design intention that the records in uc_regspace[] be parsed as a tagged list, with the parser sequentially examining the magic number in each record and using the size field to step to the next record until a record with null magic is found.
So, instead of placing each record at a fixed offset in uc_regspace[], this patch only advances the offset for a record that is actually populated. Later records following an unpopulated record will shift to lower offsets in uc_regspace[] as a result.
This change causes the fixed-layout definition of struct aux_sigframe to become useless. Since it is not present in a uapi header, this patch simply removes the definition.
These changes are not expected to break ABI except for VFP-aware software that has been explicitly hacked to work around this issue on CONFIG_IWMMXT=y kernels, which is unlikely to be a common case and would obviously violate the design intent of the arm signal frame.
There is no clear solution that definitely does not break ABI.
--- arch/arm/include/asm/ucontext.h | 20 ---------------- arch/arm/kernel/signal.c | 52 +++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 37 deletions(-)
arch/arm/include/asm/ucontext.h +0 -20
@@ -77,26 +77,6 @@ struct vfp_sigframe#endif /* CONFIG_VFP */ -/* -* Auxiliary signal frame. This saves stuff like FP state. -* The layout of this structure is not part of the user ABI, -* because the config options aren't. uc_regspace is really -* one of these. -*/ -struct aux_sigframe { -#ifdef CONFIG_CRUNCH -struct crunch_sigframe crunch; -#endif -#ifdef CONFIG_IWMMXT -struct iwmmxt_sigframe iwmmxt; -#endif -#ifdef CONFIG_VFP -struct vfp_sigframe vfp; -#endif -/* Something that isn't a valid magic number for any coprocessor. */ -unsigned long end_magic; -} __attribute__((__aligned__ (8 ))); -#endif #endif /* !_ASMARM_UCONTEXT_H */
arch/arm/kernel/signal.c +35 -17
167 lines not on this page · raw message
Signature · 1 line
2.1.4
Russell King - ARM Linux
maintainercover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
In reply to Dave MartinQuoted 7 lines · Dave Martin
In kernels with
CONFIG_IWMMXT=yrunning 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 amulti_v7_defconfigkernel is run on the majority of platforms.
Quoted 7 lines
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.
Hmm, I would actually suggest that we poke in a correct size for the missing iWMMXt record, and an invalid magic number as the "simple" solution for this - that doesn't make any layout changes to the data structures, and is probably the safest solution for backporting.
Going forward, I think something along the lines of your proposal is okay.
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.
cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 14 lines · Russell King - ARM Linux
Quoted 13 lines · Dave Martin
In kernels with
CONFIG_IWMMXT=yrunning 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 amulti_v7_defconfigkernel 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.
Quoted 6 lines
Quoted 1 line
Not extensively tested, and the ABI impact is unknown for now.
Hmm, I would actually suggest that we poke in a correct size for the missing iWMMXt record, and an invalid magic number as the "simple" solution for this - that doesn't make any layout changes to the data structures, and is probably the safest solution for backporting.
This avoids altering the sigframe layout at all in this case, which feels less dirsuptive, but overall I'm not sure it's lower-risk.
I'm concerned that there are a some userspace sigframe parsers out there that work only by accident, especially given that the kernel sigreturn implementation is the primary example and that doesn't need to be fully robust (since the kernel lays out the sigframe itself during signal delivery).
Quoted 2 lines
Going forward, I think something along the lines of your proposal is okay.
I'm happy to do either, or propose one approach for stable and the other for mainline, but it's hard to know which is least likely to break userspace, or exactly what the ABI is.
Cheers
---Dave
Russell King - ARM Linux
maintainercover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 6 lines · Dave Martin
Quoted 4 lines · Russell King - ARM Linux
Hmm, I would actually suggest that we poke in a correct size for the missing iWMMXt record, and an invalid magic number as the "simple" solution for this - that doesn't make any layout changes to the data structures, and is probably the safest solution for backporting.
Quoted 8 lines
This avoids altering the sigframe layout at all in this case, which feels less dirsuptive, but overall I'm not sure it's lower-risk.
I'm concerned that there are a some userspace sigframe parsers out there that work only by accident, especially given that the kernel sigreturn implementation is the primary example and that doesn't need to be fully robust (since the kernel lays out the sigframe itself during signal delivery).
I'd hope that the kernel implementation is not used as an example - it most certainly is not an example, as it does no parsing of the data structures. As the kernel is responsible for creating the layout, it expects the exact same layout coming back in, and any deviation from that results in the task being forcefully exited.
Userspace doesn't have the luxury of prior knowledge of the layout - it doesn't know how the kernel is configured. It can't assume (eg) that VFP will be at 0xa0 bytes in if IWMMXT but not CRUNCH is enabled.
Basically, the layout that the kernel creates is entirely dependent on the kernel configuration, and any scheme that replicates what the kernel is doing in the restore paths is doomed to failure. (However, that's not to say userspace isn't, but if it is, userspace breaks if the kernel configuration is changed. I don't regard that as a kernel-induced userspace regression though - it's a bit like expecting EABI userspace to work with OABI-only supporting kernel.)
Now, the possibilities for userspace to parse the "broken" kernel layout for VFP information are:
1. To use a fixed offset from the start (which means it breaks if the kernel is reconfigured.)
2. userspace checks several fixed offsets for the VFP identifier (at 0, 0xa0, 0xc0 or 0x160). That's risky if the other state happens to contain a word that looks like the VFP identifier.
If userspace is using the proper method that the original code intended, userspace would hit uninitialised memory for the iWMMXT block identifier and size (they'd see stale data on the stack) and if they interpret the "size" field to try and skip over it, they could end up anywhere in memory space.
Fixing it using your approach would mean that the VFP block ends up at a variable location depending on whether the iWMMXT state was saved - which certainly breaks (1) in a way that does not depend on kernel configuration. (2) survives as they'd find the identifier whatever happens.
My proposal solves all three cases, because userspace ends up with a correct size for what is an unknown block of code, and doesn't involve moving anything around. It shouldn't break the "correct" parsing that userspace should be doing either, because it should skip over the unknown block. The only case that it would break is if the identifier were to somehow match, and I think the chances of that are very slim. So I believe (without evidence to the contary) that this would be the lowest risk.
Quoted 6 lines
Quoted 2 lines
Going forward, I think something along the lines of your proposal is okay.
I'm happy to do either, or propose one approach for stable and the other for mainline, but it's hard to know which is least likely to break userspace, or exactly what the ABI is.
The intended ABI is a tagged list, where the list headers are made up of an identifier and a size (where the size gives the offset from the start of this block to the next - iow, from the address of the identifer.) The aux_sigframe structure is there as a convenience to the kernel (which is why it's not in uapi/).
The interface was created by Daniel Jacobowitz from Codesourcery, and I believe Daniel was working on the userspace side at the same time, so I would hope that the userspace side does proper parsing - except for one issue - when Daniel was working on it, we weren't saving VFP state across signal handlers.
The issue that you've found looks to have been there since the original design back in 2006.
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.
cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 16 lines · Russell King - ARM Linux
Quoted 6 lines · Dave Martin
Quoted 4 lines · Russell King - ARM Linux
Hmm, I would actually suggest that we poke in a correct size for the missing iWMMXt record, and an invalid magic number as the "simple" solution for this - that doesn't make any layout changes to the data structures, and is probably the safest solution for backporting.
Quoted 8 lines
This avoids altering the sigframe layout at all in this case, which feels less dirsuptive, but overall I'm not sure it's lower-risk.
I'm concerned that there are a some userspace sigframe parsers out there that work only by accident, especially given that the kernel sigreturn implementation is the primary example and that doesn't need to be fully robust (since the kernel lays out the sigframe itself during signal delivery).
Quoted 5 lines
I'd hope that the kernel implementation is not used as an example - it most certainly is not an example, as it does no parsing of the data structures. As the kernel is responsible for creating the layout, it expects the exact same layout coming back in, and any deviation from that results in the task being forcefully exited.
Unfortunately, things that are not intended as examples do still get used. We can argue that's the userspace folks' fault, but it still creates de facto ABI...
Quoted 3 lines
Userspace doesn't have the luxury of prior knowledge of the layout - it doesn't know how the kernel is configured. It can't assume (eg) that VFP will be at
0xa0bytes in if IWMMXT but not CRUNCH is enabled.
Agreed
Quoted 7 lines
Basically, the layout that the kernel creates is entirely dependent on the kernel configuration, and any scheme that replicates what the kernel is doing in the restore paths is doomed to failure. (However, that's not to say userspace isn't, but if it is, userspace breaks if the kernel configuration is changed. I don't regard that as a kernel-induced userspace regression though - it's a bit like expecting EABI userspace to work with OABI-only supporting kernel.)
I'm actually a little confused by, say,
Assuming I'm looking in the right place here, glibc effectively uses its own private format for uc_regspace -- maybe there is kernel history here I'm not aware of, or maybe it's not even trying to be compatible.
Also, libunwind does not appear to attempt to parse uc_regspace:
git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob;f=src/arm/Gstep.c;h=37e6c12f115173ebbc9ebcf511c53fd7c0a7d9a1;hb=HEAD
I've not fully understood the gdb code, but there is a comment in arm-linux-tdep.c that suggests that uc_regspace is not processed (nor do I see any other mention of uc_regspace or things like VFP_MAGIC:
/* The VFP or iWMMXt registers may be saved on the stack, but there's
no reliable way to restore them (yet). */
Do you know of any userspace parser of uc_regspace?
All I have so far is this, from the reporter of the bug:
https://github.com/DynamoRIO/dynamorio/commit/0b75c635033d01ab04f955f5affe14a3ced9ab56
Quoted 22 lines
Now, the possibilities for userspace to parse the "broken" kernel layout for VFP information are:
1. To use a fixed offset from the start (which means it breaks if the kernel is reconfigured.)
2. userspace checks several fixed offsets for the VFP identifier (at 0,
0xa0,0xc0or0x160). That's risky if the other state happens to contain a word that looks like the VFP identifier.If userspace is using the proper method that the original code intended, userspace would hit uninitialised memory for the iWMMXT block identifier and size (they'd see stale data on the stack) and if they interpret the "size" field to try and skip over it, they could end up anywhere in memory space.
Fixing it using your approach would mean that the VFP block ends up at a variable location depending on whether the iWMMXT state was saved - which certainly breaks (1) in a way that does not depend on kernel configuration. (2) survives as they'd find the identifier whatever happens.
Quoted 8 lines
My proposal solves all three cases, because userspace ends up with a correct size for what is an unknown block of code, and doesn't involve moving anything around. It shouldn't break the "correct" parsing that userspace should be doing either, because it should skip over the unknown block. The only case that it would break is if the identifier were to somehow match, and I think the chances of that are very slim. So I believe (without evidence to the contary) that this would be the lowest risk.
This seems reasonable.
Although I'm concerned that parsers may give up as soon as they see an unknown block, that is at least a clean failure, and is better than wandering off into the weeds. I haven't seen evidence of such a parser existing, so far -- there will be ones I don't know about.
Quoted 13 lines
Quoted 6 lines
Quoted 2 lines
Going forward, I think something along the lines of your proposal is okay.
I'm happy to do either, or propose one approach for stable and the other for mainline, but it's hard to know which is least likely to break userspace, or exactly what the ABI is.
The intended ABI is a tagged list, where the list headers are made up of an identifier and a size (where the size gives the offset from the start of this block to the next - iow, from the address of the identifer.) The
aux_sigframestructure is there as a convenience to the kernel (which is why it's not in uapi/).
Quoted 8 lines
The interface was created by Daniel Jacobowitz from Codesourcery, and I believe Daniel was working on the userspace side at the same time, so I would hope that the userspace side does proper parsing - except for one issue - when Daniel was working on it, we weren't saving VFP state across signal handlers.
The issue that you've found looks to have been there since the original design back in 2006.
Looks like it.
I'll update the patch to preserve the iWMMXt block on signal delivery but define a new dummy tag for this case.
Should we enforce the same on sigreturn, or be more tolerant?
One issue is that I believe there is software out there (ab)using sigreturn to do an atomic siglongjmp type operation.
There is some merit to this, since the effect cannot be achieved 100% safely in any other way. However, it may require the caller to manufacture a sigframe from scratch. If so, it may be natural to omit the IWMMXT block (and indeed the VFP block, if the caller doesn't care what's in the VFP registers at the destination).
The DynamoRIO example above takes a signal to generate a "template" sigframe, which is then modified to produce the desired result. Putting aside the issue of whether this is an abuse of sigreturn or not (and the question of why they are doing it at all), this seems a reasonable approach -- which they also apparently use for x86. So their sigframe will contain the dummy iWMMXt block, but it will have a valid tag if we patch the kernel to write one.
Other projects may not be so lucky if they don't use a delivered signal as a template in this way.
Cheers
---Dave
Russell King - ARM Linux
maintainercover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 10 lines · Dave Martin
Quoted 5 lines · Russell King - ARM Linux
I'd hope that the kernel implementation is not used as an example - it most certainly is not an example, as it does no parsing of the data structures. As the kernel is responsible for creating the layout, it expects the exact same layout coming back in, and any deviation from that results in the task being forcefully exited.
Unfortunately, things that are not intended as examples do still get used. We can argue that's the userspace folks' fault, but it still creates de facto ABI...
Given that the contents of the structure depend on kernel configuration symbols, it's impossible for userspace to use it unless they also have some kind of static configuration as well.
Quoted 7 lines
Quoted 7 lines
Basically, the layout that the kernel creates is entirely dependent on the kernel configuration, and any scheme that replicates what the kernel is doing in the restore paths is doomed to failure. (However, that's not to say userspace isn't, but if it is, userspace breaks if the kernel configuration is changed. I don't regard that as a kernel-induced userspace regression though - it's a bit like expecting EABI userspace to work with OABI-only supporting kernel.)
The kernel gained the tagged-list approach in 2006, and didn't start preserving the VFP state until 2010.
Quoted 7 lines
I'm actually a little confused by, say,
Assuming I'm looking in the right place here, glibc effectively uses its own private format for
uc_regspace-- maybe there is kernel history here I'm not aware of, or maybe it's not even trying to be compatible.
It looks to me like glibc is expecting:
- If the HWCAP includes VFP
- 64 bytes of d8-d15 registers
- fpscr
- If the HWCAP includes iWMMXT
- 48 bytes of iWMMXT state
The kernel has never used that (partial!) format - note that it seems to omit d0-d7 from the context.
Given that setcontext()'s man page says:
The function setcontext() restores the user context pointed at by ucp.
A successful call does not return. The context should have been
obtained by a call of getcontext(), or makecontext(3), or passed as third argument to a signal handler.
it seems that for this to work in the signal handler case, there would have to be some kind of translation from the kernel format to glibc's format when calling into the signal handler - maybe there is... but what you point out is definitely incompatible with the kernel today, and has always been incompatible.
If there's no translation going on, then this has never worked, and so there's no possibility of a regression!
Quoted 3 lines
Also, libunwind does not appear to attempt to parse
uc_regspace:git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob;f=src/arm/Gstep.c;h=37e6c12f115173ebbc9ebcf511c53fd7c0a7d9a1;hb=HEAD
Yea, it's just looking at the integer register set.
Quoted 8 lines
I've not fully understood the gdb code, but there is a comment in
arm-linux-tdep.cthat suggests thatuc_regspaceis not processed (nor do I see any other mention ofuc_regspaceor things likeVFP_MAGIC:/* The VFP or iWMMXt registers may be saved on the stack, but there's
no reliable way to restore them (yet). */
It sounds like no one implemented the userspace side of this then!
Quoted 5 lines
Do you know of any userspace parser of
uc_regspace?All I have so far is this, from the reporter of the bug:
https://github.com/DynamoRIO/dynamorio/commit/0b75c635033d01ab04f955f5affe14a3ced9ab56
Hmm, well, it seems like they're the first to test this feature, which is pretty sad.
Quoted 1 line
Should we enforce the same on sigreturn, or be more tolerant?
I've been thinking about that, and haven't come to a decision. There is the matter that more complex parsing is harder to be correct (think about out of bounds 'size' values, although that can be mitigated by ensuring that size is numerically correct for the magic ID - but then what if we have a wrong ID, or the size is incorrect for the magic ID?)
Quoted 5 lines
There is some merit to this, since the effect cannot be achieved 100% safely in any other way. However, it may require the caller to manufacture a sigframe from scratch. If so, it may be natural to omit the IWMMXT block (and indeed the VFP block, if the caller doesn't care what's in the VFP registers at the destination).
As you can see, the kernel hasn't really catered for manufactured sigframes - it expects to see the same sigframe that it wrote out. Whether that's reasonable or not, I'm not sure, but no one's complained about it yet!
Quoted 7 lines
The DynamoRIO example above takes a signal to generate a "template" sigframe, which is then modified to produce the desired result. Putting aside the issue of whether this is an abuse of sigreturn or not (and the question of why they are doing it at all), this seems a reasonable approach -- which they also apparently use for x86. So their sigframe will contain the dummy iWMMXt block, but it will have a valid tag if we patch the kernel to write one.
Bear in mind that parsing the data in uc_regspace is going to be hardware specific, it's hard to do it in a generic way. Debuggers necessarily have to know the intricate hardware details of the system its running on, so it's reasonable for them to poke about in that area. I'm not so sure about generic applications though.
Anyway, I don't have time this evening to continue this reply... so I'll send it anyway. :)
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.
cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · Dave Martin
Quoted 5 lines · Russell King - ARM Linux
I'd hope that the kernel implementation is not used as an example - it most certainly is not an example, as it does no parsing of the data structures. As the kernel is responsible for creating the layout, it expects the exact same layout coming back in, and any deviation from that results in the task being forcefully exited.
Quoted 7 lines
Quoted 3 lines
Unfortunately, things that are not intended as examples do still get used. We can argue that's the userspace folks' fault, but it still creates de facto ABI...
Given that the contents of the structure depend on kernel configuration symbols, it's impossible for userspace to use it unless they also have some kind of static configuration as well.
Agreed
Quoted 37 lines
Quoted 7 lines
Quoted 7 lines
Basically, the layout that the kernel creates is entirely dependent on the kernel configuration, and any scheme that replicates what the kernel is doing in the restore paths is doomed to failure. (However, that's not to say userspace isn't, but if it is, userspace breaks if the kernel configuration is changed. I don't regard that as a kernel-induced userspace regression though - it's a bit like expecting EABI userspace to work with OABI-only supporting kernel.)
The kernel gained the tagged-list approach in 2006, and didn't start preserving the VFP state until 2010.
Quoted 7 lines
I'm actually a little confused by, say,
Assuming I'm looking in the right place here, glibc effectively uses its own private format for
uc_regspace-- maybe there is kernel history here I'm not aware of, or maybe it's not even trying to be compatible.It looks to me like glibc is expecting:
- If the HWCAP includes VFP
- 64 bytes of d8-d15 registers
- fpscr
- If the HWCAP includes iWMMXT
- 48 bytes of iWMMXT stateThe kernel has never used that (partial!) format - note that it seems to omit d0-d7 from the context.
Given that setcontext()'s man page says:
The function
setcontext()restores the user context pointed at by ucp.
A successful call does not return. The context should have been
obtained by a call ofgetcontext(), or makecontext(3), or passed as third argument to a signal handler.
Quoted 8 lines
it seems that for this to work in the signal handler case, there would have to be some kind of translation from the kernel format to glibc's format when calling into the signal handler - maybe there is... but what you point out is definitely incompatible with the kernel today, and has always been incompatible.
If there's no translation going on, then this has never worked, and so there's no possibility of a regression!
Yes. Sadly, there's no indication of whether the incompatibility is intentional or not.
Quoted 17 lines
Quoted 3 lines
Also, libunwind does not appear to attempt to parse
uc_regspace:git.savannah.gnu.org/gitweb/?p=libunwind.git;a=blob;f=src/arm/Gstep.c;h=37e6c12f115173ebbc9ebcf511c53fd7c0a7d9a1;hb=HEAD
Yea, it's just looking at the integer register set.
Quoted 8 lines
I've not fully understood the gdb code, but there is a comment in
arm-linux-tdep.cthat suggests thatuc_regspaceis not processed (nor do I see any other mention ofuc_regspaceor things likeVFP_MAGIC:/* The VFP or iWMMXt registers may be saved on the stack, but there's
no reliable way to restore them (yet). */It sounds like no one implemented the userspace side of this then!
Quoted 8 lines
Quoted 5 lines
Do you know of any userspace parser of
uc_regspace?All I have so far is this, from the reporter of the bug:
https://github.com/DynamoRIO/dynamorio/commit/0b75c635033d01ab04f955f5affe14a3ced9ab56
Hmm, well, it seems like they're the first to test this feature, which is pretty sad.
Hmm indeed
Quoted 27 lines
Quoted 1 line
Should we enforce the same on sigreturn, or be more tolerant?
I've been thinking about that, and haven't come to a decision. There is the matter that more complex parsing is harder to be correct (think about out of bounds 'size' values, although that can be mitigated by ensuring that size is numerically correct for the magic ID - but then what if we have a wrong ID, or the size is incorrect for the magic ID?)
Quoted 5 lines
There is some merit to this, since the effect cannot be achieved 100% safely in any other way. However, it may require the caller to manufacture a sigframe from scratch. If so, it may be natural to omit the IWMMXT block (and indeed the VFP block, if the caller doesn't care what's in the VFP registers at the destination).
As you can see, the kernel hasn't really catered for manufactured sigframes - it expects to see the same sigframe that it wrote out. Whether that's reasonable or not, I'm not sure, but no one's complained about it yet!
Quoted 7 lines
The DynamoRIO example above takes a signal to generate a "template" sigframe, which is then modified to produce the desired result. Putting aside the issue of whether this is an abuse of sigreturn or not (and the question of why they are doing it at all), this seems a reasonable approach -- which they also apparently use for x86. So their sigframe will contain the dummy iWMMXt block, but it will have a valid tag if we patch the kernel to write one.
Quoted 8 lines
Bear in mind that parsing the data in
uc_regspaceis going to be hardware specific, it's hard to do it in a generic way. Debuggers necessarily have to know the intricate hardware details of the system its running on, so it's reasonable for them to poke about in that area. I'm not so sure about generic applications though.Anyway, I don't have time this evening to continue this reply... so I'll send it anyway. :)
There's certainly a limit to the portability that userspace can expect here. Returning from a signal is portable; poking about inside mcontext_t is not, though we should aim for least surprise.
For the RFC v2 I just posted, I've aimed for a halfway house where the code is kept a simple as possible without mandating the iWMMXt dummy block to be present on non-iWMMXt hardware.
If present, the block must have the same location and size as the iwmmxt_sigframe would have. This should avoid the possibility of any runtime overrun when attempting to skip blocks.
Cheers
---Dave
A message that is not in the archive (sent off-list or not yet received): AM4PR08MB2659BFF0EAEB020F7571A115D5DF0@AM4PR08MB2659.eurprd08.prod.outlook.com
Russell King - ARM Linux
maintainercover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 1 line · Edmund Grimley-Evans
As a user (I recently implemented a work-around for this problem in DynamoRIO: https://github.com/DynamoRIO/dynamorio/commit/0b75c635033d01ab04f955f5affe14a3ced9ab56) I'm happy with any of the proposed solutions, provided that in the "invalid magic number" case user space is not required to regenerate the bogus block with the same invalid magic number when invoking sigreturn.
I have to ask why a bug report was never sent to kernel people on this. If no one tells people that software is buggy, that software stands little chance of being fixed!
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.
cover ARM: Fix unparseable signal frame with CONFIG_IWMMXT
Quoted 6 lines · Russell King - ARM Linux
Quoted 1 line · Edmund Grimley-Evans
As a user (I recently implemented a work-around for this problem in DynamoRIO: https://github.com/DynamoRIO/dynamorio/commit/0b75c635033d01ab04f955f5affe14a3ced9ab56) I'm happy with any of the proposed solutions, provided that in the "invalid magic number" case user space is not required to regenerate the bogus block with the same invalid magic number when invoking sigreturn.
I have to ask why a bug report was never sent to kernel people on this. If no one tells people that software is buggy, that software stands little chance of being fixed!
Partly because I fielded it before it got raised on the list.
However, it would have been good to have more discussion on the list and to get the DynamoRIO guys commenting on there -- since they are the ones actually trying to use this feature.
I'll try to encourage that more in the future...
Cheers
---Dave