siginfo_t ABI break on sparc64 from si_addr_lsb move 3y ago
Subsystems (12)
Hello, Eric,
By inspecting the logs I've seen that about 3 years ago there had been a number of siginfo_t cleanups. This included moving si_addr_lsb:
b68a68d3dcc1 ("signal: Move addr_lsb into the _sigfault union for clarity") 859d880cf544 ("signal: Correct the offset of si_pkey in struct siginfo") 8420f71943ae ("signal: Correct the offset of si_pkey and si_lower in struct siginfo on m68k")
In an ideal world, we could just have si_addr + the union in _sigfault, but it seems there are more corner cases. :-/
The reason I've stumbled upon this is that I wanted to add the just merged si_perf [1] field to glibc. But what I noticed is that glibc's definition and ours are vastly different around si_addr_lsb, si_lower, si_upper, and si_pkey.
In our current definition of siginfo_t, si_addr_lsb is placed into the same union as si_lower, si_upper, and si_pkey (and now si_perf). From the logs I see that si_lower, si_upper, and si_pkey are padded because si_addr_lsb used to be outside the union, which goes back to "signal: Move addr_lsb into the _sigfault union for clarity".
Since then, si_addr_lsb must also be pointer-aligned, because the union containing it must be pointer-aligned (because si_upper, si_lower). On all architectures where si_addr_lsb is right after si_addr, this is perfectly fine, because si_addr itself is a pointer...
... except for the anomaly that are 64-bit architectures that define __ARCH_SI_TRAPNO and want that 'int si_trapno'. Like, for example sparc64, which means siginfo_t's ABI has been subtly broken on sparc64 since v4.16.
The following static asserts illustrate this:
arch/sparc/kernel/signal_64.c +28 -0
@@ -556,3 +556,37 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +static_assert (offsetof(siginfo_t , si_signo) ==0 ); +static_assert (offsetof(siginfo_t , si_errno) ==4 ); +static_assert (offsetof(siginfo_t , si_code) ==8 ); +static_assert (offsetof(siginfo_t , si_pid) ==16 ); +static_assert (offsetof(siginfo_t , si_uid) ==20 ); +static_assert (offsetof(siginfo_t , si_tid) ==16 ); +static_assert (offsetof(siginfo_t , si_overrun) ==20 ); +static_assert (offsetof(siginfo_t , si_status) ==24 ); +static_assert (offsetof(siginfo_t , si_utime) ==32 ); +static_assert (offsetof(siginfo_t , si_stime) ==40 ); +static_assert (offsetof(siginfo_t , si_value) ==24 ); +static_assert (offsetof(siginfo_t , si_int) ==24 ); +static_assert (offsetof(siginfo_t , si_ptr) ==24 ); +static_assert (offsetof(siginfo_t , si_addr) ==16 ); +static_assert (offsetof(siginfo_t , si_trapno) ==24 ); +#if 1 /* Correct offsets, obtained from v4.14 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==28 ); +static_assert (offsetof(siginfo_t , si_lower) ==32 ); +static_assert (offsetof(siginfo_t , si_upper) ==40 ); +static_assert (offsetof(siginfo_t , si_pkey) ==32 ); +#else /* Current offsets, as of v4.16 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==32 ); +static_assert (offsetof(siginfo_t , si_lower) ==40 ); +static_assert (offsetof(siginfo_t , si_upper) ==48 ); +static_assert (offsetof(siginfo_t , si_pkey) ==40 ); +#endif +static_assert (offsetof(siginfo_t , si_band) ==16 ); +static_assert (offsetof(siginfo_t , si_fd) ==20 );
---
Granted, nobody seems to have noticed because I don't even know if these fields have use on sparc64. But I don't yet see this as justification to leave things as-is...
The collateral damage of this, and the acute problem that I'm having is defining si_perf in a sort-of readable and portable way in siginfo_t definitions that live outside the kernel, where sparc64 does not yet have broken si_addr_lsb. And the same difficulty applies to the kernel if we want to unbreak sparc64, while not wanting to move si_perf for other architectures.
There are 2 options I see to solve this:
1. Make things simple again. We could just revert the change moving si_addr_lsb into the union, and sadly accept we'll have to live with that legacy "design" mistake. (si_perf stays in the union, but will unfortunately change its offset for all architectures... this one-off move might be ok because it's new.)
2. Add special cases to retain si_addr_lsb in the union on architectures that do not have __ARCH_SI_TRAPNO (the majority). I have added a draft patch that would do this below (with some refactoring so that it remains sort-of readable), as an experiment to see how complicated this gets.
Option (1) means we'll forever be wasting the space where si_addr_lsb lives (including the padding). It'd also mean we'd move si_perf for _all_ architectures -- this might be acceptable, given there is no stable release with it yet -- the fix just needs to be merged before the release of v5.13! It is the simpler option though -- and I don't know if we need all this complexity.
Option (2) perhaps results in better space utilization. Maybe that's better long-term if we worry about space in some rather distant future -- where we need those 8 bytes on 64-bit architectures to not exceed 128 bytes. This option, however, doesn't just make us carry this complexity forever, but also forces it onto everyone else, like glibc and other libcs (including those in other languages with C FFIs) which have their own definition of siginfo_t.
Which option do you prefer? Are there better options?
Many thanks,
-- Marco
------ >8 ------
Option #2 draft:
arch/sparc/kernel/signal_64.c +34 -0
@@ -556,3 +556,37 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +/* +* Compile-time assertions for siginfo_t offsets. Unlike other architectures, +* sparc64 is special, because it requires si_trapno (int), and the following +* si_addr_lsb (short) need not be word aligned. Accidental changes around the +* offset of si_addr_lsb and the following fields would only be caught here. +*/ +static_assert (offsetof(siginfo_t , si_signo) ==0 ); +static_assert (offsetof(siginfo_t , si_errno) ==4 ); +static_assert (offsetof(siginfo_t , si_code) ==8 ); +static_assert (offsetof(siginfo_t , si_pid) ==16 ); +static_assert (offsetof(siginfo_t , si_uid) ==20 ); +static_assert (offsetof(siginfo_t , si_tid) ==16 ); +static_assert (offsetof(siginfo_t , si_overrun) ==20 ); +static_assert (offsetof(siginfo_t , si_status) ==24 ); +static_assert (offsetof(siginfo_t , si_utime) ==32 ); +static_assert (offsetof(siginfo_t , si_stime) ==40 ); +static_assert (offsetof(siginfo_t , si_value) ==24 ); +static_assert (offsetof(siginfo_t , si_int) ==24 ); +static_assert (offsetof(siginfo_t , si_ptr) ==24 ); +static_assert (offsetof(siginfo_t , si_addr) ==16 ); +static_assert (offsetof(siginfo_t , si_trapno) ==24 ); +#if 1 /* Correct offsets, obtained from v4.14 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==28 ); +static_assert (offsetof(siginfo_t , si_lower) ==32 ); +static_assert (offsetof(siginfo_t , si_upper) ==40 ); +static_assert (offsetof(siginfo_t , si_pkey) ==32 ); +#else /* Current offsets, as of v4.16 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==32 ); +static_assert (offsetof(siginfo_t , si_lower) ==40 ); +static_assert (offsetof(siginfo_t , si_upper) ==48 ); +static_assert (offsetof(siginfo_t , si_pkey) ==40 ); +#endif +static_assert (offsetof(siginfo_t , si_band) ==16 ); +static_assert (offsetof(siginfo_t , si_fd) ==20 );
include/linux/compat.h +29 -12
61 lines not on this page · raw message
include/uapi/asm-generic/siginfo.h +45 -15
92 lines not on this page · raw message
Quoted 93 lines · Marco Elver
Hello, Eric,
By inspecting the logs I've seen that about 3 years ago there had been a number of
siginfo_tcleanups. This included movingsi_addr_lsb:
b68a68d3dcc1("signal: Moveaddr_lsbinto the_sigfaultunion for clarity")859d880cf544("signal: Correct the offset ofsi_pkeyin struct siginfo")8420f71943ae("signal: Correct the offset ofsi_pkeyandsi_lowerin struct siginfo on m68k")In an ideal world, we could just have
si_addr+ the union in_sigfault, but it seems there are more corner cases. :-/The reason I've stumbled upon this is that I wanted to add the just merged
si_perf[1] field to glibc. But what I noticed is that glibc's definition and ours are vastly different aroundsi_addr_lsb,si_lower,si_upper, andsi_pkey.In our current definition of
siginfo_t,si_addr_lsbis placed into the same union assi_lower,si_upper, andsi_pkey(and nowsi_perf). From the logs I see thatsi_lower,si_upper, andsi_pkeyare padded becausesi_addr_lsbused to be outside the union, which goes back to "signal: Moveaddr_lsbinto the_sigfaultunion for clarity".Since then,
si_addr_lsbmust also be pointer-aligned, because the union containing it must be pointer-aligned (becausesi_upper,si_lower). On all architectures wheresi_addr_lsbis right aftersi_addr, this is perfectly fine, becausesi_addritself is a pointer...... except for the anomaly that are 64-bit architectures that define
__ARCH_SI_TRAPNOand want that 'intsi_trapno'. Like, for example sparc64, which means siginfo_t's ABI has been subtly broken on sparc64 since v4.16.The following static asserts illustrate this:
arch/sparc/kernel/signal_64.c +28
-1@@ -556,3 +556,37 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +static_assert (offsetof(siginfo_t , si_signo) ==0 ); +static_assert (offsetof(siginfo_t , si_errno) ==4 ); +static_assert (offsetof(siginfo_t , si_code) ==8 ); +static_assert (offsetof(siginfo_t , si_pid) ==16 ); +static_assert (offsetof(siginfo_t , si_uid) ==20 ); +static_assert (offsetof(siginfo_t , si_tid) ==16 ); +static_assert (offsetof(siginfo_t , si_overrun) ==20 ); +static_assert (offsetof(siginfo_t , si_status) ==24 ); +static_assert (offsetof(siginfo_t , si_utime) ==32 ); +static_assert (offsetof(siginfo_t , si_stime) ==40 ); +static_assert (offsetof(siginfo_t , si_value) ==24 ); +static_assert (offsetof(siginfo_t , si_int) ==24 ); +static_assert (offsetof(siginfo_t , si_ptr) ==24 ); +static_assert (offsetof(siginfo_t , si_addr) ==16 ); +static_assert (offsetof(siginfo_t , si_trapno) ==24 ); +#if 1 /* Correct offsets, obtained from v4.14 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==28 ); +static_assert (offsetof(siginfo_t , si_lower) ==32 ); +static_assert (offsetof(siginfo_t , si_upper) ==40 ); +static_assert (offsetof(siginfo_t , si_pkey) ==32 ); +#else /* Current offsets, as of v4.16 */ +static_assert (offsetof(siginfo_t , si_addr_lsb) ==32 ); +static_assert (offsetof(siginfo_t , si_lower) ==40 ); +static_assert (offsetof(siginfo_t , si_upper) ==48 ); +static_assert (offsetof(siginfo_t , si_pkey) ==40 ); +#endif +static_assert (offsetof(siginfo_t , si_band) ==16 ); +static_assert (offsetof(siginfo_t , si_fd) ==20 ); ---Granted, nobody seems to have noticed because I don't even know if these fields have use on sparc64. But I don't yet see this as justification to leave things as-is...
The collateral damage of this, and the acute problem that I'm having is defining
si_perfin a sort-of readable and portable way insiginfo_tdefinitions that live outside the kernel, where sparc64 does not yet have brokensi_addr_lsb. And the same difficulty applies to the kernel if we want to unbreak sparc64, while not wanting to movesi_perffor other architectures.There are 2 options I see to solve this:
1. Make things simple again. We could just revert the change moving
si_addr_lsbinto the union, and sadly accept we'll have to live with that legacy "design" mistake. (si_perfstays in the union, but will unfortunately change its offset for all architectures... this one-off move might be ok because it's new.)
Quoted 7 lines
2. Add special cases to retain
si_addr_lsbin the union on architectures that do not have__ARCH_SI_TRAPNO(the majority). I have added a draft patch that would do this below (with some refactoring so that it remains sort-of readable), as an experiment to see how complicated this gets.Which option do you prefer? Are there better options?
Personally the most important thing to have is a single definition shared by all architectures so that we consolidate testing.
A little piece of me cries a little whenever I see how badly we implemented the POSIX design. As specified by POSIX the fields can be place in siginfo such that 32bit and 64bit share a common definition. Unfortunately we did not addpadding after si_addr on 32bit to accommodate a 64bit si_addr.
I find it unfortunate that we are adding yet another definition that requires translation between 32bit and 64bit, but I am glad that at least the translation is not architecture specific. That common definition is what has allowed this potential issue to be caught and that makes me very happy to see.
Let's go with Option 3.
Confirm BUS_MCEERR_AR, BUS_MCEERR_AO, SEGV_BNDERR, SEGV_PKUERR are not in use on any architecture that defines __ARCH_SI_TRAPNO, and then fixup the userspace definitions of these fields.
To the kernel I would add some BUILD_BUG_ON's to whatever the best maintained architecture (sparc64?) that implements __ARCH_SI_TRAPNO just to confirm we don't create future regressions by accident.
I did a quick search and the architectures that define __ARCH_SI_TRAPNO are sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that use BUS_MCEERR_AR, BUS_MCEERR_AO, SEGV_BNDERR, SEGV_PKUERR, nor do they appear to use mm/memory-failure.c
So it doesn't look like we have an ABI regression to fix.
Eric
On Thu, 29 Apr 2021 at 19:24, Eric W. Biederman <[email protected]> wrote:
[...]
Quoted 27 lines
Quoted 19 lines
Granted, nobody seems to have noticed because I don't even know if these fields have use on sparc64. But I don't yet see this as justification to leave things as-is...
The collateral damage of this, and the acute problem that I'm having is defining
si_perfin a sort-of readable and portable way insiginfo_tdefinitions that live outside the kernel, where sparc64 does not yet have brokensi_addr_lsb. And the same difficulty applies to the kernel if we want to unbreak sparc64, while not wanting to movesi_perffor other architectures.There are 2 options I see to solve this:
1. Make things simple again. We could just revert the change moving
si_addr_lsbinto the union, and sadly accept we'll have to live with that legacy "design" mistake. (si_perfstays in the union, but will unfortunately change its offset for all architectures... this one-off move might be ok because it's new.)Quoted 7 lines
2. Add special cases to retain
si_addr_lsbin the union on architectures that do not have__ARCH_SI_TRAPNO(the majority). I have added a draft patch that would do this below (with some refactoring so that it remains sort-of readable), as an experiment to see how complicated this gets.Which option do you prefer? Are there better options?
Quoted 8 lines
Personally the most important thing to have is a single definition shared by all architectures so that we consolidate testing.
A little piece of me cries a little whenever I see how badly we implemented the POSIX design. As specified by POSIX the fields can be place in siginfo such that 32bit and 64bit share a common definition. Unfortunately we did not addpadding after
si_addron 32bit to accommodate a 64bitsi_addr.
I think it's even worse than that, see the fun I had with siginfo last
week: https://lkml.kernel.org/r/[email protected]
... because of the 3 initial ints and no padding after them, we can't portably add __u64 fields to siginfo, and are forever forced to have subtly different behaviour between 32-bit and 64-bit architectures. :-/
Quoted 16 lines
I find it unfortunate that we are adding yet another definition that requires translation between 32bit and 64bit, but I am glad that at least the translation is not architecture specific. That common definition is what has allowed this potential issue to be caught and that makes me very happy to see.
Let's go with Option 3.
Confirm
BUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERRare not in use on any architecture that defines__ARCH_SI_TRAPNO, and then fixup the userspace definitions of these fields.To the kernel I would add some BUILD_BUG_ON's to whatever the best maintained architecture (sparc64?) that implements
__ARCH_SI_TRAPNOjust to confirm we don't create future regressions by accident.
Quoted 7 lines
I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that useBUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERR, nor do they appear to usemm/memory-failure.cSo it doesn't look like we have an ABI regression to fix.
That sounds fine to me -- my guess was that they're not used on these architectures, but I just couldn't make that call.
I have patches adding compile-time asserts for sparc64, arm, arm64 ready to go. I'll send them after some more testing.
Thanks,
-- Marco
Arnd Bergmann
maintainerQuoted 23 lines · Eric W. Biederman
Quoted 1 line
Which option do you prefer? Are there better options?
Personally the most important thing to have is a single definition shared by all architectures so that we consolidate testing.
A little piece of me cries a little whenever I see how badly we implemented the POSIX design. As specified by POSIX the fields can be place in siginfo such that 32bit and 64bit share a common definition. Unfortunately we did not addpadding after
si_addron 32bit to accommodate a 64bitsi_addr.I find it unfortunate that we are adding yet another definition that requires translation between 32bit and 64bit, but I am glad that at least the translation is not architecture specific. That common definition is what has allowed this potential issue to be caught and that makes me very happy to see.
Let's go with Option 3.
Confirm
BUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERRare not in use on any architecture that defines__ARCH_SI_TRAPNO, and then fixup the userspace definitions of these fields.
Quoted 6 lines
To the kernel I would add some BUILD_BUG_ON's to whatever the best maintained architecture (sparc64?) that implements
__ARCH_SI_TRAPNOjust to confirm we don't create future regressions by accident.I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations.
I think you (slightly) misread: mips has "#undef __ARCH_SI_TRAPNO", not "#define __ARCH_SI_TRAPNO". This means it's only sparc and alpha.
I can see that the alpha instance was added to the kernel during linux-2.5, but never made it into the glibc or uclibc copy of the struct definition, and musl doesn't support alpha or sparc. Debian codesearch only turns up sparc (and BSD) references to si_trapno.
Quoted 7 lines
I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that useBUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERR, nor do they appear to usemm/memory-failure.cSo it doesn't look like we have an ABI regression to fix.
Even better!
So if sparc is the only user of _trapno and it uses none of the later fields in _sigfault, I wonder if we could take even more liberty at trying to have a slightly saner definition. Can you think of anything that might break if we put _trapno inside of the union along with _perf and _addr_lsb?
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
Arnd
Quoted 51 lines · Arnd Bergmann
Quoted 23 lines · Eric W. Biederman
Quoted 1 line
Which option do you prefer? Are there better options?
Personally the most important thing to have is a single definition shared by all architectures so that we consolidate testing.
A little piece of me cries a little whenever I see how badly we implemented the POSIX design. As specified by POSIX the fields can be place in siginfo such that 32bit and 64bit share a common definition. Unfortunately we did not addpadding after
si_addron 32bit to accommodate a 64bitsi_addr.I find it unfortunate that we are adding yet another definition that requires translation between 32bit and 64bit, but I am glad that at least the translation is not architecture specific. That common definition is what has allowed this potential issue to be caught and that makes me very happy to see.
Let's go with Option 3.
Confirm
BUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERRare not in use on any architecture that defines__ARCH_SI_TRAPNO, and then fixup the userspace definitions of these fields.Quoted 6 lines
To the kernel I would add some BUILD_BUG_ON's to whatever the best maintained architecture (sparc64?) that implements
__ARCH_SI_TRAPNOjust to confirm we don't create future regressions by accident.I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations.I think you (slightly) misread: mips has "#undef
__ARCH_SI_TRAPNO", not "#define__ARCH_SI_TRAPNO". This means it's only sparc and alpha.I can see that the alpha instance was added to the kernel during linux-2.5, but never made it into the glibc or uclibc copy of the struct definition, and musl doesn't support alpha or sparc. Debian codesearch only turns up sparc (and BSD) references to
si_trapno.Quoted 7 lines
I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that useBUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERR, nor do they appear to usemm/memory-failure.cSo it doesn't look like we have an ABI regression to fix.
Quoted 7 lines
Even better!
So if sparc is the only user of
_trapnoand it uses none of the later fields in_sigfault, I wonder if we could take even more liberty at trying to have a slightly saner definition. Can you think of anything that might break if we put_trapnoinside of the union along with_perfand_addr_lsb?
On sparc si_trapno is only set when SIGILL ILL_TRP is set. So we can limit si_trapno to that combination, and it should not be a problem for a new signal/si_code pair to use that storage. Precisely because it is new.
Similarly on alpha si_trapno is only set for:
SIGFPE {FPE_INTOVF, FPE_INTDIV, FPE_FLTOVF, FPE_FLTDIV, FPE_FLTUND, FPE_FLTINV, FPE_FLTRES, FPE_FLTUNK} and SIGTRAP {TRAP_UNK}.
Placing si_trapno into the union would also make the problem that the union is pointer aligned a non-problem as then the union immediate follows a pointer.
I hadn't had a chance to look before but we must deal with this. The definition of perf_sigtrap in 42dec9a936e7696bea1f27d3c5a0068cd9aa95fd is broken on sparc, alpha, and ia64 as it bypasses the code in kernel/signal.c that ensures the si_trapno or the ia64 special fields are set.
Not to mention that perf_sigtrap appears to abuse si_errno.
The code is only safe if the analysis that says we can move si_trapno and perhaps the ia64 fields into the union is correct. It looks like ia64 much more actively uses it's signal extension fields including for SIGTRAP, so I am not at all certain the generic definition of perf_sigtrap is safe on ia64.
Quoted 4 lines
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
If we localize the use of si_trapno to just a few special cases on alpha and sparc I think we don't even need to worry about breaking userspace on any architecture. It will complicate siginfo_layout, but it is a complication that reflects reality.
I don't have a clue how any of this affects ia64. Does perf work on ia64? Does perf work on sparc, and alpha?
If perf works on ia64 we need to take a hard look at what is going on there as well.
Eric
Quoted 1 line · Eric W. Biederman
Arnd Bergmann <[email protected]> writes:
[...]
Quoted 30 lines
Quoted 8 lines
Quoted 7 lines
I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that useBUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERR, nor do they appear to usemm/memory-failure.cSo it doesn't look like we have an ABI regression to fix.
Quoted 7 lines
Even better!
So if sparc is the only user of
_trapnoand it uses none of the later fields in_sigfault, I wonder if we could take even more liberty at trying to have a slightly saner definition. Can you think of anything that might break if we put_trapnoinside of the union along with_perfand_addr_lsb?On sparc
si_trapnois only set when SIGILLILL_TRPis set. So we can limitsi_trapnoto that combination, and it should not be a problem for a new signal/si_code pair to use that storage. Precisely because it is new.Similarly on alpha
si_trapnois only set for:SIGFPE {
FPE_INTOVF,FPE_INTDIV,FPE_FLTOVF,FPE_FLTDIV,FPE_FLTUND,FPE_FLTINV,FPE_FLTRES,FPE_FLTUNK} and SIGTRAP {TRAP_UNK}.Placing
si_trapnointo the union would also make the problem that the union is pointer aligned a non-problem as then the union immediate follows a pointer.
Quoted 7 lines
I hadn't had a chance to look before but we must deal with this. The definition of
perf_sigtrapin42dec9a936e7696bea1f27d3c5a0068cd9aa95fdis broken on sparc, alpha, and ia64 as it bypasses the code inkernel/signal.cthat ensures thesi_trapnoor the ia64 special fields are set.Not to mention that
perf_sigtrapappears to abusesi_errno.
There are a few other places in the kernel that repurpose si_errno similarly, e.g. arch/arm64/kernel/ptrace.c, kernel/seccomp.c -- it was either that or introduce another field or not have it. It is likely we could do without, but if there are different event types the user would have to sacrifice a few bits of si_perf to encode the event type, and I'd rather keep those bits for something else. Thus the decision fell to use si_errno.
Given it'd be wasted space otherwise, and we define the semantics of whatever is stored in siginfo on the new signal, it'd be good to keep.
Quoted 5 lines
The code is only safe if the analysis that says we can move
si_trapnoand perhaps the ia64 fields into the union is correct. It looks like ia64 much more actively uses it's signal extension fields including for SIGTRAP, so I am not at all certain the generic definition ofperf_sigtrapis safe on ia64.
Trying to understand the requirements of si_trapno myself: safe here would mean that si_trapno is not required if we fire our SIGTRAP / TRAP_PERF.
As far as I can tell that is the case -- see below.
Quoted 10 lines
Quoted 4 lines
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
If we localize the use of
si_trapnoto just a few special cases on alpha and sparc I think we don't even need to worry about breaking userspace on any architecture. It will complicatesiginfo_layout, but it is a complication that reflects reality.
Quoted 5 lines
I don't have a clue how any of this affects ia64. Does perf work on ia64? Does perf work on sparc, and alpha?
If perf works on ia64 we need to take a hard look at what is going on there as well.
No perf on ia64, but it seems alpha and sparc have perf:
$ git grep 'select.*HAVE_PERF_EVENTS$' -- arch/ arch/alpha/Kconfig: select HAVE_PERF_EVENTS <-- arch/arc/Kconfig: select HAVE_PERF_EVENTS arch/arm/Kconfig: select HAVE_PERF_EVENTS arch/arm64/Kconfig: select HAVE_PERF_EVENTS arch/csky/Kconfig: select HAVE_PERF_EVENTS arch/hexagon/Kconfig: select HAVE_PERF_EVENTS arch/mips/Kconfig: select HAVE_PERF_EVENTS arch/nds32/Kconfig: select HAVE_PERF_EVENTS arch/parisc/Kconfig: select HAVE_PERF_EVENTS arch/powerpc/Kconfig: select HAVE_PERF_EVENTS arch/riscv/Kconfig: select HAVE_PERF_EVENTS arch/s390/Kconfig: select HAVE_PERF_EVENTS arch/sh/Kconfig: select HAVE_PERF_EVENTS arch/sparc/Kconfig: select HAVE_PERF_EVENTS <-- arch/x86/Kconfig: select HAVE_PERF_EVENTS arch/xtensa/Kconfig: select HAVE_PERF_EVENTS
Now, given ia64 is not an issue, I wanted to understand the semantics of si_trapno. Per https://man7.org/linux/man-pages/man2/sigaction.2.html, I see:
int si_trapno; /* Trap number that caused
hardware-generated signal (unused on most architectures) */
... its intended semantics seem to suggest it would only be used by some architecture-specific signal like you identified above. So if the semantics is some code of a hardware trap/fault, then we're fine and do not need to set it.
Also bearing in mind we define the semantics any new signal, and given most architectures do not have si_trapno, definitions of new generic signals should probably not include odd architecture specific details related to old architectures.
From all this, my understanding now is that we can move si_trapno into the union, correct? What else did you have in mind?
Thanks,
-- Marco
Quoted 41 lines · Marco Elver
Quoted 1 line · Eric W. Biederman
Arnd Bergmann <[email protected]> writes:
[...]
Quoted 30 lines
Quoted 8 lines
Quoted 7 lines
I did a quick search and the architectures that define
__ARCH_SI_TRAPNOare sparc, mips, and alpha. All have 64bit implementations. A further quick search shows that none of those architectures have faults that useBUS_MCEERR_AR,BUS_MCEERR_AO,SEGV_BNDERR,SEGV_PKUERR, nor do they appear to usemm/memory-failure.cSo it doesn't look like we have an ABI regression to fix.
Quoted 7 lines
Even better!
So if sparc is the only user of
_trapnoand it uses none of the later fields in_sigfault, I wonder if we could take even more liberty at trying to have a slightly saner definition. Can you think of anything that might break if we put_trapnoinside of the union along with_perfand_addr_lsb?On sparc
si_trapnois only set when SIGILLILL_TRPis set. So we can limitsi_trapnoto that combination, and it should not be a problem for a new signal/si_code pair to use that storage. Precisely because it is new.Similarly on alpha
si_trapnois only set for:SIGFPE {
FPE_INTOVF,FPE_INTDIV,FPE_FLTOVF,FPE_FLTDIV,FPE_FLTUND,FPE_FLTINV,FPE_FLTRES,FPE_FLTUNK} and SIGTRAP {TRAP_UNK}.Placing
si_trapnointo the union would also make the problem that the union is pointer aligned a non-problem as then the union immediate follows a pointer.Quoted 7 lines
I hadn't had a chance to look before but we must deal with this. The definition of
perf_sigtrapin42dec9a936e7696bea1f27d3c5a0068cd9aa95fdis broken on sparc, alpha, and ia64 as it bypasses the code inkernel/signal.cthat ensures thesi_trapnoor the ia64 special fields are set.Not to mention that
perf_sigtrapappears to abusesi_errno.
Quoted 7 lines
There are a few other places in the kernel that repurpose
si_errnosimilarly, e.g.arch/arm64/kernel/ptrace.c,kernel/seccomp.c-- it was either that or introduce another field or not have it. It is likely we could do without, but if there are different event types the user would have to sacrifice a few bits ofsi_perfto encode the event type, and I'd rather keep those bits for something else. Thus the decision fell to usesi_errno.
arm64 only abuses si_errno in compat code for bug compatibility with arm32.
Quoted 2 lines
Given it'd be wasted space otherwise, and we define the semantics of whatever is stored in siginfo on the new signal, it'd be good to keep.
Except you don't completely. You are not defining a new signal. You are extending the definition of SIGTRAP. Anything generic that responds to all SIGTRAPs can reasonably be looking at si_errno.
Further you are already adding a field with si_perf you can just as easily add a second field with well defined semantics for that data.
Quoted 61 lines
Quoted 5 lines
The code is only safe if the analysis that says we can move
si_trapnoand perhaps the ia64 fields into the union is correct. It looks like ia64 much more actively uses it's signal extension fields including for SIGTRAP, so I am not at all certain the generic definition ofperf_sigtrapis safe on ia64.Trying to understand the requirements of
si_trapnomyself: safe here would mean thatsi_trapnois not required if we fire our SIGTRAP /TRAP_PERF.As far as I can tell that is the case -- see below.
Quoted 10 lines
Quoted 4 lines
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
If we localize the use of
si_trapnoto just a few special cases on alpha and sparc I think we don't even need to worry about breaking userspace on any architecture. It will complicatesiginfo_layout, but it is a complication that reflects reality.Quoted 5 lines
I don't have a clue how any of this affects ia64. Does perf work on ia64? Does perf work on sparc, and alpha?
If perf works on ia64 we need to take a hard look at what is going on there as well.
No perf on ia64, but it seems alpha and sparc have perf:
$ git grep 'select.*HAVE_PERF_EVENTS$' -- arch/ arch/alpha/Kconfig: select HAVE_PERF_EVENTS <-- arch/arc/Kconfig: select HAVE_PERF_EVENTS arch/arm/Kconfig: select HAVE_PERF_EVENTS arch/arm64/Kconfig: select HAVE_PERF_EVENTS arch/csky/Kconfig: select HAVE_PERF_EVENTS arch/hexagon/Kconfig: select HAVE_PERF_EVENTS arch/mips/Kconfig: select HAVE_PERF_EVENTS arch/nds32/Kconfig: select HAVE_PERF_EVENTS arch/parisc/Kconfig: select HAVE_PERF_EVENTS arch/powerpc/Kconfig: select HAVE_PERF_EVENTS arch/riscv/Kconfig: select HAVE_PERF_EVENTS arch/s390/Kconfig: select HAVE_PERF_EVENTS arch/sh/Kconfig: select HAVE_PERF_EVENTS arch/sparc/Kconfig: select HAVE_PERF_EVENTS <-- arch/x86/Kconfig: select HAVE_PERF_EVENTS arch/xtensa/Kconfig: select HAVE_PERF_EVENTSNow, given ia64 is not an issue, I wanted to understand the semantics of
si_trapno. Per https://man7.org/linux/man-pages/man2/sigaction.2.html, I see:int
si_trapno; /* Trap number that caused
hardware-generated signal (unused on most architectures) */... its intended semantics seem to suggest it would only be used by some architecture-specific signal like you identified above. So if the semantics is some code of a hardware trap/fault, then we're fine and do not need to set it.
Quoted 7 lines
Also bearing in mind we define the semantics any new signal, and given most architectures do not have
si_trapno, definitions of new generic signals should probably not include odd architecture specific details related to old architectures.From all this, my understanding now is that we can move
si_trapnointo the union, correct? What else did you have in mind?
Yes. Let's move si_trapno into the union.
That implies a few things like siginfo_layout needs to change.
The helpers in kernel/signal.c can change to not imply that if you define __ARCH_SI_TRAPNO you must always define and pass in si_trapno. A force_sig_trapno could be defined instead to handle the cases that alpha and sparc use si_trapno.
It would be nice if a force_sig_perf_trap could be factored out of perf_trap and placed in kernel/signal.c.
My experience (especially this round) is that it becomes much easier to audit the users of siginfo if there is a dedicated function in kernel/signal.c that is simply passed the parameters that need to be placed in siginfo.
So I would very much like to see if I can make force_sig_info static.
Eric
On Fri, 30 Apr 2021 at 22:15, Eric W. Biederman <[email protected]> wrote:
[...]
Quoted 9 lines
arm64 only abuses
si_errnoin compat code for bug compatibility with arm32.Quoted 2 lines
Given it'd be wasted space otherwise, and we define the semantics of whatever is stored in siginfo on the new signal, it'd be good to keep.
Except you don't completely. You are not defining a new signal. You are extending the definition of SIGTRAP. Anything generic that responds to all SIGTRAPs can reasonably be looking at
si_errno.
I see where you're coming from, and agree with this if si_errno already had some semantics for some subset of SIGTRAPs. I've tried to analyze the situation a bit further, since siginfo seems to be a giant minefield and semantics is underspecified at best. :-)
Do any of the existing SIGTRAPs define si_errno to be set? As far as I can tell, they don't.
If this is true, I think there are benefits and downsides to repurposing si_errno (similar to what SIGSYS did). The obvious downside is as you suggest, it's not always a real errno. The benefit is that we avoid introducing more and more fields -- i.e. if we permit si_errno to be repurposed for SIGTRAP and its value depends on the precise si_code, too, we simplify siginfo's overall definition (also given every new field needs more code in kernel/signal.c, too).
Given SIGTRAPs are in response to some user-selected event in the user's code (breakpoints, ptrace, etc. ... now perf events), the user must already check the si_code to select the right action because SIGTRAPs are not alike (unlike, e.g. SIGSEGV). Because of this, I think that repurposing si_errno in an si_code-dependent way for SIGTRAPs is safe.
If you think it is simply untenable to repurpose si_errno for SIGTRAPs, please confirm -- I'll just send a minimal patch to fix (I'd probably just remove setting it... everything else is too intrusive as a "fix".. sigh).
The cleanups as you outline below seem orthogonal and not urgent for 5.13 (all changes and cleanups for __ARCH_SI_TRAPNO seem too intrusive without -next exposure).
Thanks,
-- Marco
Quoted 93 lines
Further you are already adding a field with
si_perfyou can just as easily add a second field with well defined semantics for that data.Quoted 61 lines
Quoted 5 lines
The code is only safe if the analysis that says we can move
si_trapnoand perhaps the ia64 fields into the union is correct. It looks like ia64 much more actively uses it's signal extension fields including for SIGTRAP, so I am not at all certain the generic definition ofperf_sigtrapis safe on ia64.Trying to understand the requirements of
si_trapnomyself: safe here would mean thatsi_trapnois not required if we fire our SIGTRAP /TRAP_PERF.As far as I can tell that is the case -- see below.
Quoted 10 lines
Quoted 4 lines
I suppose in theory sparc64 or alpha might start using the other fields in the future, and an application might be compiled against mismatched headers, but that is unlikely and is already broken with the current headers.
If we localize the use of
si_trapnoto just a few special cases on alpha and sparc I think we don't even need to worry about breaking userspace on any architecture. It will complicatesiginfo_layout, but it is a complication that reflects reality.Quoted 5 lines
I don't have a clue how any of this affects ia64. Does perf work on ia64? Does perf work on sparc, and alpha?
If perf works on ia64 we need to take a hard look at what is going on there as well.
No perf on ia64, but it seems alpha and sparc have perf:
$ git grep 'select.*HAVE_PERF_EVENTS$' -- arch/ arch/alpha/Kconfig: select HAVE_PERF_EVENTS <-- arch/arc/Kconfig: select HAVE_PERF_EVENTS arch/arm/Kconfig: select HAVE_PERF_EVENTS arch/arm64/Kconfig: select HAVE_PERF_EVENTS arch/csky/Kconfig: select HAVE_PERF_EVENTS arch/hexagon/Kconfig: select HAVE_PERF_EVENTS arch/mips/Kconfig: select HAVE_PERF_EVENTS arch/nds32/Kconfig: select HAVE_PERF_EVENTS arch/parisc/Kconfig: select HAVE_PERF_EVENTS arch/powerpc/Kconfig: select HAVE_PERF_EVENTS arch/riscv/Kconfig: select HAVE_PERF_EVENTS arch/s390/Kconfig: select HAVE_PERF_EVENTS arch/sh/Kconfig: select HAVE_PERF_EVENTS arch/sparc/Kconfig: select HAVE_PERF_EVENTS <-- arch/x86/Kconfig: select HAVE_PERF_EVENTS arch/xtensa/Kconfig: select HAVE_PERF_EVENTSNow, given ia64 is not an issue, I wanted to understand the semantics of
si_trapno. Per https://man7.org/linux/man-pages/man2/sigaction.2.html, I see:int
si_trapno; /* Trap number that caused
hardware-generated signal (unused on most architectures) */... its intended semantics seem to suggest it would only be used by some architecture-specific signal like you identified above. So if the semantics is some code of a hardware trap/fault, then we're fine and do not need to set it.
Quoted 7 lines
Also bearing in mind we define the semantics any new signal, and given most architectures do not have
si_trapno, definitions of new generic signals should probably not include odd architecture specific details related to old architectures.From all this, my understanding now is that we can move
si_trapnointo the union, correct? What else did you have in mind?Yes. Let's move
si_trapnointo the union.That implies a few things like
siginfo_layoutneeds to change.The helpers in
kernel/signal.ccan change to not imply that if you define__ARCH_SI_TRAPNOyou must always define and pass insi_trapno. Aforce_sig_trapnocould be defined instead to handle the cases that alpha and sparc usesi_trapno.It would be nice if a
force_sig_perf_trapcould be factored out ofperf_trapand placed inkernel/signal.c.My experience (especially this round) is that it becomes much easier to audit the users of siginfo if there is a dedicated function in
kernel/signal.cthat is simply passed the parameters that need to be placed in siginfo.So I would very much like to see if I can make
force_sig_infostatic.Eric
cover signal: Move si_trapno into the _si_fault union
In reply to Marco ElverEric W. Biederman (3):
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals with si_trapno set
arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++++++------ arch/alpha/mm/fault.c | 4 +- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 +++++------ arch/sparc/kernel/traps_64.c | 44 ++++++++++------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- fs/signalfd.c | 7 +--- include/linux/compat.h | 4 +- include/linux/sched/signal.h | 12 ++---- include/linux/signal.h | 1 + include/uapi/asm-generic/siginfo.h | 6 +-- kernel/signal.c | 77 ++++++++++++++++++++++---------------- 18 files changed, 107 insertions(+), 112 deletions(-)
PATCH 1/3 siginfo: Move si_trapno inside the union inside _si_fault
It turns out that linux uses si_trapno very sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.
As such move si_trapno inside the union inside of _si_fault. This results in no change in placement, and makes it eaiser to extend _si_fault in the future as this reduces the number of special cases. In particular with si_trapno included in the union it is no longer a concern that the union must be pointer alligned on most architectures because the union followes immediately after si_addr which is a pointer.
--- include/linux/compat.h | 4 +--- include/uapi/asm-generic/siginfo.h | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-)
include/linux/compat.h +1 -3
@@ -214,12 +214,10 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {compat_uptr_t _addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))union { +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
include/uapi/asm-generic/siginfo.h +1 -5
@@ -63,9 +63,6 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {void __user *_addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #ifdef __ia64__int _imm;/* immediate value for "break" */ unsigned int _flags;/* see ia64 si_flags */
@@ -75,6 +72,7 @@ union __sifields {#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \ sizeof(short) : __alignof__(void *))union { +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
@@ -150,9 +148,7 @@ typedef struct siginfo {#define si_int _sifields._rt._sigval.sival_int#define si_ptr _sifields._rt._sigval.sival_ptr#define si_addr _sifields._sigfault._addr -#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno -#endif #define si_addr_lsb _sifields._sigfault._addr_lsb#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper
Signature · 1 line
2.30.1
Re: [PATCH 1/3] siginfo: Move si_trapno inside the union inside _si_fault
Quoted 6 lines · Eric W. Biederman
It turns out that linux uses
si_trapnovery sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.
Quoted 8 lines
As such move
si_trapnoinside the union inside of_si_fault. This results in no change in placement, and makes it eaiser to extend_si_faultin the future as this reduces the number of special cases. In particular withsi_trapnoincluded in the union it is no longer a concern that the union must be pointer alligned on most architectures because the union followes immediately aftersi_addrwhich is a pointer.
Maybe add "Link:
https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com"
Quoted 1 line
Signed-off-by "Eric W. Biederman" <[email protected]>
By no longer guarding it with __ARCH_SI_TRAPNO we run the risk that it will be used by something else at some point. Is that intentional?
Thanks,
-- Marco
Quoted 57 lines
--- include/linux/compat.h | 4 +--- include/uapi/asm-generic/siginfo.h | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-)include/linux/compat.h +1
-3@@ -214,12 +214,10 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {compat_uptr_t _addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))union { +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO include/uapi/asm-generic/siginfo.h +1
-6@@ -63,9 +63,6 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {void __user *_addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #ifdef __ia64__int _imm;/* immediate value for "break" */ unsigned int _flags;/* see ia64 si_flags */ @@ -75,6 +72,7 @@ union __sifields {#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \ sizeof(short) : __alignof__(void *))union { +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO @@ -150,9 +148,7 @@ typedef struct siginfo {#define si_int _sifields._rt._sigval.sival_int#define si_ptr _sifields._rt._sigval.sival_ptr#define si_addr _sifields._sigfault._addr -#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno -#endif #define si_addr_lsb _sifields._sigfault._addr_lsb#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper --2.30.1
Re: [PATCH 1/3] siginfo: Move si_trapno inside the union inside _si_fault
Quoted 19 lines · Marco Elver
Quoted 6 lines · Eric W. Biederman
It turns out that linux uses
si_trapnovery sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.Quoted 8 lines
As such move
si_trapnoinside the union inside of_si_fault. This results in no change in placement, and makes it eaiser to extend_si_faultin the future as this reduces the number of special cases. In particular withsi_trapnoincluded in the union it is no longer a concern that the union must be pointer alligned on most architectures because the union followes immediately aftersi_addrwhich is a pointer.Maybe add "Link:
https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com"
Quoted 6 lines
Quoted 1 line
Signed-off-by "Eric W. Biederman" <[email protected]>Acked-by Marco Elver <[email protected]>By no longer guarding it with
__ARCH_SI_TRAPNOwe run the risk that it will be used by something else at some point. Is that intentional?
The motivation was letting the code be tested on other architectures.
But once si_trapno falls inside the union instead of being present for every signal reporting a fault it doesn't really matter.
I think it would be poor taste but harmless to use si_trapno, mostly because defining a new entry in the union could be more specific and well defined.
Eric
PATCH 2/3 signal: Implement SIL_FAULT_TRAPNO
In reply to Eric W. BiedermanNow that si_trapno is part of the union in _si_fault and available on all architectures, add SIL_FAULT_TRAPNO and update siginfo_layout to return SIL_FAULT_TRAPNO when si_trapno is actually used.
Update the code that uses siginfo_layout to deal with SIL_FAULT_TRAPNO and have the same code ignore si_trapno in in all other cases.
--- fs/signalfd.c | 7 ++----- include/linux/signal.h | 1 + kernel/signal.c | 36 ++++++++++++++---------------------- 3 files changed, 17 insertions(+), 27 deletions(-)
fs/signalfd.c +2 -5
@@ -123,15 +123,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :
include/linux/signal.h +1 -0
@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,
kernel/signal.c +14 -22
@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -3206,6 +3208,12 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (SPARC ) && (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR
@@ -3317,30 +3325,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
@@ -3401,30 +3401,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
Signature · 1 line
2.30.1
Re: [PATCH 2/3] signal: Implement SIL_FAULT_TRAPNO
Quoted 6 lines · [email protected] (Eric W. Biederman) writes:
Now that
si_trapnois part of the union in_si_faultand available on all architectures, addSIL_FAULT_TRAPNOand updatesiginfo_layoutto returnSIL_FAULT_TRAPNOwhensi_trapnois actually used.Update the code that uses
siginfo_layoutto deal withSIL_FAULT_TRAPNOand have the same code ignoresi_trapnoin in all other cases.
This change is missing a break in signalfd.
Eric
Quoted 12 lines
Signed-off-by "Eric W. Biederman" <[email protected]>--- fs/signalfd.c | 7 ++----- include/linux/signal.h | 1 + kernel/signal.c | 36 ++++++++++++++---------------------- 3 files changed, 17 insertions(+), 27 deletions(-)fs/signalfd.c +0
-0
fs/signalfd.c static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, · line 125
Quoted 3 lines
fs/signalfd.c +0
-0@@ -123,15 +123,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr;
+ break;
Quoted 127 lines
fs/signalfd.c +2
-5-#ifdef __ARCH_SI_TRAPNO +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :include/linux/signal.h +1
-0@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,kernel/signal.c +14
-22@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -3206,6 +3208,12 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (SPARC ) && (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR @@ -3317,30 +3325,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :@@ -3401,30 +3401,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
Re: [PATCH 2/3] signal: Implement SIL_FAULT_TRAPNO
In reply to Eric W. BiedermanQuoted 70 lines · Eric W. Biederman
Now that
si_trapnois part of the union in_si_faultand available on all architectures, addSIL_FAULT_TRAPNOand updatesiginfo_layoutto returnSIL_FAULT_TRAPNOwhensi_trapnois actually used.Update the code that uses
siginfo_layoutto deal withSIL_FAULT_TRAPNOand have the same code ignoresi_trapnoin in all other cases.Signed-off-by "Eric W. Biederman" <[email protected]>--- fs/signalfd.c | 7 ++----- include/linux/signal.h | 1 + kernel/signal.c | 36 ++++++++++++++---------------------- 3 files changed, 17 insertions(+), 27 deletions(-)fs/signalfd.c +2
-5@@ -123,15 +123,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :include/linux/signal.h +1
-0@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,kernel/signal.c +2
-0@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
kernel/signal.c enum siginfo_layout siginfo_layout(unsigned sig, int si_code) · line 3216
Quoted 9 lines
kernel/signal.c +6
-0@@ -3206,6 +3208,12 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (SPARC ) && (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;
The breakage isn't apparent here, but in later patches. These need to become CONFIG_SPARC and CONFIG_ALPHA.
Quoted 73 lines
kernel/signal.c +6
-23else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR @@ -3317,30 +3325,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :@@ -3401,30 +3401,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT : --2.30.1
Re: [PATCH 2/3] signal: Implement SIL_FAULT_TRAPNO
Quoted 75 lines · Marco Elver
Quoted 74 lines · Eric W. Biederman
Now that
si_trapnois part of the union in_si_faultand available on all architectures, addSIL_FAULT_TRAPNOand updatesiginfo_layoutto returnSIL_FAULT_TRAPNOwhensi_trapnois actually used.Update the code that uses
siginfo_layoutto deal withSIL_FAULT_TRAPNOand have the same code ignoresi_trapnoin in all other cases.Signed-off-by "Eric W. Biederman" <[email protected]>--- fs/signalfd.c | 7 ++----- include/linux/signal.h | 1 + kernel/signal.c | 36 ++++++++++++++---------------------- 3 files changed, 17 insertions(+), 27 deletions(-)fs/signalfd.c +2
-5@@ -123,15 +123,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :include/linux/signal.h +1
-0@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,kernel/signal.c +3
-0@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -3206,6 +3208,12 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; + else if (IS_ENABLED(ALPHA) &&
Quoted 8 lines
kernel/signal.c enum siginfo_layout siginfo_layout(unsigned sig, int si_code) · line 3216
Quoted 5 lines
kernel/signal.c +5
-0+ ((sig == SIGFPE) || + ((sig == SIGTRAP) && (si_code == TRAP_UNK)))) + layout =SIL_FAULT_TRAPNO ; + else if (IS_ENABLED(SPARC) && (sig == SIGILL) && (si_code == ILL_ILLTRP)) + layout =SIL_FAULT_TRAPNO ;The breakage isn't apparent here, but in later patches. These need to become
CONFIG_SPARCandCONFIG_ALPHA.
Good catch. For some reason I thought IS_ENABLED added the CONFIG_ prefix but I looked and it doesn't.
Quoted 73 lines
Quoted 73 lines
kernel/signal.c +6
-23else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR @@ -3317,30 +3325,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :@@ -3401,30 +3401,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT : --2.30.1
PATCH 3/3 signal: Use dedicated helpers to send signals with si_trapno set
In reply to Eric W. BiedermanNow that si_trapno is no longer expected to be present for every fault reported using siginfo on alpha and sparc remove the trapno parameter from force_sig_fault, force_sig_fault_to_task and send_sig_fault.
Add two new helpers force_sig_fault_trapno and send_sig_fault_trapno for those signals where trapno is expected to be set.
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 24 ++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++++++++-------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++++------------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 12 +++------ kernel/signal.c | 41 +++++++++++++++++++++-------- 14 files changed, 88 insertions(+), 77 deletions(-)
arch/alpha/kernel/osf_sys.c +1 -1
@@ -878,7 +878,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,send_sig_fault (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ -0 , current); + current); }return 0 ; }
arch/alpha/kernel/signal.c +2 -2
@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
arch/alpha/kernel/traps.c +12 -12
@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void
@@ -268,12 +268,12 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc, current);return ;
@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */
@@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }
@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a
@@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }
@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }
arch/alpha/mm/fault.c +2 -2
@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC
arch/sparc/kernel/process_64.c +1 -1
@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \
arch/sparc/kernel/sys_sparc_32.c +1 -1
@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);
arch/sparc/kernel/sys_sparc_64.c +1 -1
@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif
arch/sparc/kernel/traps_32.c +11 -11
@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */
@@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;
@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif
@@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE
arch/sparc/kernel/traps_64.c +19 -25
144 lines not on this page · raw message
arch/sparc/kernel/unaligned_32.c +1 -1
@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }
arch/sparc/mm/fault_32.c +1 -1
@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)
arch/sparc/mm/fault_64.c +1 -1
@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)
include/linux/sched/signal.h +4 -8
@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else
@@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);
@@ -327,6 +319,10 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *task); +int force_sig_ptrace_errno_trap (int errno,void __user *addr);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);
kernel/signal.c +31 -10
78 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH 3/3] signal: Use dedicated helpers to send signals with si_trapno set
Quoted 9 lines · Eric W. Biederman
Now that
si_trapnois no longer expected to be present for every fault reported using siginfo on alpha and sparc remove the trapno parameter fromforce_sig_fault,force_sig_fault_to_taskandsend_sig_fault.Add two new helpers
force_sig_fault_trapnoandsend_sig_fault_trapnofor those signals where trapno is expected to be set.Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 16 lines
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 24 ++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++++++++-------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++++------------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 12 +++------ kernel/signal.c | 41 +++++++++++++++++++++-------- 14 files changed, 88 insertions(+), 77 deletions(-)
This still breaks sparc64:
Quoted 2 lines
sparc64-linux-gnu-ld:
arch/sparc/kernel/traps_64.o: in function `bad_trap':
(.text+0x2a4): undefined reference to `force_sig_fault_trapno'
[...]
Quoted 1 line
+#if
IS_ENABLED(SPARC)
This should be 'IS_ENABLED(CONFIG_SPARC)'.
Quoted 5 lines
kernel/signal.c +5
-0+int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) +{ +struct kernel_siginfo info; + +clear_siginfo (&info);
kernel/signal.c int force_sig_pkuerr(void __user *addr, u32 pkey) · line 1771
Quoted 10 lines
kernel/signal.c +10
-0+ info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; + return force_sig_info(&info); +} +#endif + +#if IS_ENABLED (ALPHA )
CONFIG_ALPHA
Quoted 21 lines
kernel/signal.c +15
-1+int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return send_sig_info (info.si_signo, &info, t); +} +#endif +/* For the crazy architectures that include trap information in * the errno field, instead of an actual errno value. */ --2.30.1
[PATCH 4/3] signal: Remove __ARCH_SI_TRAPNO
In reply to Eric W. BiedermanNow that this define is no longer used remove it from the kernel.
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/mips/include/uapi/asm/siginfo.h | 2 -- arch/sparc/include/uapi/asm/siginfo.h | 3 --- 3 files changed, 7 deletions(-)
arch/alpha/include/uapi/asm/siginfo.h +0 -2
@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif
arch/mips/include/uapi/asm/siginfo.h +0 -2
@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFO
arch/sparc/include/uapi/asm/siginfo.h +0 -3
@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h>
Signature · 1 line
2.30.1
Is perf_sigtrap synchronous?
In reply to Eric W. BiedermanI am looking at perf_sigtrap and I am confused by the code.
/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the * case on architectures that do not implement arch_irq_work_raise(). */ if (WARN_ON_ONCE(event->ctx->task != current)) return; /* * perf_pending_event() can race with the task exiting. */ if (current->flags & PF_EXITING) return;
It performs tests that absolutely can never fail if we are talking about a synchronous exception. The code force_sig family of functions only make sense to use with and are only safe to use with synchronous exceptions.
Are the tests in perf_sigtrap necessary or is perf_sigtrap not reporting a synchronous event?
Eric
Re: Is perf_sigtrap synchronous?
Quoted 19 lines · Eric W. Biederman
I am looking at
perf_sigtrapand I am confused by the code./* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the * case on architectures that do not implement arch_irq_work_raise(). */ if (WARN_ON_ONCE(event->ctx->task != current)) return; /* * perf_pending_event() can race with the task exiting. */ if (current->flags & PF_EXITING) return;
Quoted 7 lines
It performs tests that absolutely can never fail if we are talking about a synchronous exception. The code
force_sigfamily of functions only make sense to use with and are only safe to use with synchronous exceptions.Are the tests in
perf_sigtrapnecessary or isperf_sigtrapnot reporting a synchronous event?
Yes it's synchronous, insofar that the user will receive the signal right when the event happens (I've tested this extensively, also see tools/testing/selftests/perf_events). Of course, there's some effort involved from the point where the event triggered to actually safely delivering the signal. In particular, for HW events, these arrive in NMI, and we can't do much in NMI, and therefore will queue an irq_work.
On architectures that properly implement irq_work, it will do a self-IPI, so that once it is safe to do so, another interrupt is delivered where we process the event and do the force_sig_info(). The task where the event occurred never got a chance to run -- except for bad architectures with broken irq_work, and the first WARN_ON() is there so we don't crash the kernel if somebody botched their irq_work.
Since we're talking about various HW events, these can still trigger while the task is exiting, before perf_event_exit_task() being called during do_exit(). That's why we have the 2nd check.
Thanks,
-- Marco
[PATCH 5/3] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
In reply to Eric W. BiedermanIt helps to know which part of the siginfo structure the siginfo_layout value is talking about.
--- fs/signalfd.c | 2 +- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/signalfd.c +1 -1
@@ -132,7 +132,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; new.ssi_perf = kinfo->si_perf;break ;
include/linux/signal.h +1 -1
@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,
kernel/signal.c +5 -5
@@ -1198,7 +1198,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;
@@ -2553,7 +2553,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;
@@ -3242,7 +3242,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;
@@ -3364,7 +3364,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf = from->si_perf;break ;
@@ -3440,7 +3440,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf = from->si_perf;break ;
Signature · 1 line
2.30.1
Marco Elver
Acked-byRe: [PATCH 5/3] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
Quoted 3 lines · Eric W. Biederman
It helps to know which part of the siginfo structure the
siginfo_layoutvalue is talking about.
Your Signed-off-by seems to be missing.
Otherwise,
Quoted 84 lines
--- fs/signalfd.c | 2 +- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)fs/signalfd.c +1
-1@@ -132,7 +132,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; new.ssi_perf = kinfo->si_perf;break ;include/linux/signal.h +1
-1@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,kernel/signal.c +5
-6@@ -1198,7 +1198,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;@@ -2553,7 +2553,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;@@ -3242,7 +3242,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;@@ -3364,7 +3364,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf = from->si_perf;break ;@@ -3440,7 +3440,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf = from->si_perf;break ; --2.30.1
[PATCH 6/3] signal: Factor force_sig_perf out of perf_sigtrap
In reply to Eric W. BiedermanSeparate generating the signal from deciding it needs to be sent.
--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)
include/linux/sched/signal.h +1 -0
@@ -318,6 +318,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
kernel/events/core.c +2 -9
@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
@@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)
kernel/signal.c +13 -0
@@ -1753,6 +1753,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *pending_addr,u32 type,u64 sig_data) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = pending_addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +#if IS_ENABLED (SPARC )int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) {
Signature · 1 line
2.30.1
Re: [PATCH 6/3] signal: Factor force_sig_perf out of perf_sigtrap
Quoted 56 lines · Eric W. Biederman
Separate generating the signal from deciding it needs to be sent.
Signed-off-by "Eric W. Biederman" <[email protected]>--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)include/linux/sched/signal.h +1
-0@@ -318,6 +318,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,kernel/events/core.c +2
-9@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the @@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)kernel/signal.c +0
-0
kernel/signal.c int force_sig_pkuerr(void __user *addr, u32 pkey) · line 1756
Quoted 4 lines
kernel/signal.c +1
-0@@ -1753,6 +1753,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *pending_addr,u32 type,u64 sig_data)
s/pending_addr/addr/
to match force_sig_perf() declaration.
Quoted 17 lines
kernel/signal.c +12
-1+{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = pending_addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +#if IS_ENABLED (SPARC )int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) { --2.30.1
[PATCH 7/3] signal: Deliver all of the perf_data in si_perf
In reply to Eric W. BiedermanDon't abuse si_errno and deliver all of the perf data in si_perf.
--- fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 5 ++++- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 18 +++++++++++------- 5 files changed, 23 insertions(+), 12 deletions(-)
fs/signalfd.c +2 -1
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf.type; + new.ssi_perf_data = kinfo->si_perf.data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;
include/linux/compat.h +4 -1
@@ -235,7 +235,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t data; +u32 type; + } _perf; }; } _sigfault;
include/uapi/asm-generic/siginfo.h +4 -1
@@ -90,7 +90,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long data; +u32 type; + } _perf; }; } _sigfault;
include/uapi/linux/signalfd.h +2 -2
@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
kernel/signal.c +11 -7
@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *pending_addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = pending_addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = pending_addr; + info.si_perf.data = sig_data; + info.si_perf.type = type; +return force_sig_info (&info); }
@@ -3379,7 +3381,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -3455,7 +3458,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
Signature · 1 line
2.30.1
Re: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
Quoted 5 lines · Eric W. Biederman
Don't abuse
si_errnoand deliver all of the perf data insi_perf.Signed-off-by "Eric W. Biederman" <[email protected]>---
Thank you for the fix, this looks cleaner.
Just note that this patch needs to include updates to tools/testing/selftests/perf_events. This should do it:
Quoted 1 line
sed -i 's/si_perf/si_perf.data/g; s/si_errno/si_perf.type/g'
tools/testing/selftests/perf_events/*.c
Subject: s/perf_data/perf data/ ?
For uapi, need to switch to __u32, see below.
Quoted 42 lines
fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 5 ++++- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 18 +++++++++++------- 5 files changed, 23 insertions(+), 12 deletions(-)fs/signalfd.c +2
-1@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf.type; + new.ssi_perf_data = kinfo->si_perf.data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;include/linux/compat.h +4
-1@@ -235,7 +235,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t data; +u32 type; + } _perf; }; } _sigfault;include/uapi/asm-generic/siginfo.h +0
-0
include/uapi/asm-generic/siginfo.h union __sifields { · line 95
Quoted 7 lines
include/uapi/asm-generic/siginfo.h +3
-1@@ -90,7 +90,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long data; +u32 type;
This needs to be __u32.
Quoted 64 lines
include/uapi/asm-generic/siginfo.h +1
-0+ } _perf; }; } _sigfault;include/uapi/linux/signalfd.h +2
-2@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the kernel/signal.c +11
-8@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *pending_addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = pending_addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = pending_addr; + info.si_perf.data = sig_data; + info.si_perf.type = type; +return force_sig_info (&info); }@@ -3379,7 +3381,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid;@@ -3455,7 +3458,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid; --2.30.1
Re: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
Quoted 9 lines · Marco Elver
Quoted 5 lines · Eric W. Biederman
Don't abuse
si_errnoand deliver all of the perf data insi_perf.Signed-off-by "Eric W. Biederman" <[email protected]>---
Thank you for the fix, this looks cleaner.
Quoted 7 lines
Just note that this patch needs to include updates to
tools/testing/selftests/perf_events. This should do it:Quoted 1 line
sed -i 's/si_perf/si_perf.data/g; s/si_errno/si_perf.type/g'
tools/testing/selftests/perf_events/*.cSubject: s/perf_data/perf data/ ?
For uapi, need to switch to
__u32, see below.
Good point.
The one thing that this doesn't do is give you a 64bit field on 32bit architectures.
On 32bit builds the layout is:
int si_signo; int si_errno; int si_code; void __user *_addr;
So I believe if the first 3 fields were moved into the _sifields union si_perf could define a 64bit field as it's first member and it would not break anything else.
Given that the data field is 64bit that seems desirable.
Eric
Quoted 117 lines
Quoted 42 lines
fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 5 ++++- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 18 +++++++++++------- 5 files changed, 23 insertions(+), 12 deletions(-)fs/signalfd.c +2
-1@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf.type; + new.ssi_perf_data = kinfo->si_perf.data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;include/linux/compat.h +4
-1@@ -235,7 +235,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t data; +u32 type; + } _perf; }; } _sigfault;include/uapi/asm-generic/siginfo.h +0
-0include/uapi/asm-generic/siginfo.h union __sifields { · line 95
Quoted 7 lines
include/uapi/asm-generic/siginfo.h +3
-1@@ -90,7 +90,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long data; +u32 type;This needs to be
__u32.Quoted 64 lines
include/uapi/asm-generic/siginfo.h +1
-0+ } _perf; }; } _sigfault;include/uapi/linux/signalfd.h +2
-2@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the kernel/signal.c +11
-8@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *pending_addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = pending_addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = pending_addr; + info.si_perf.data = sig_data; + info.si_perf.type = type; +return force_sig_info (&info); }@@ -3379,7 +3381,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid;@@ -3455,7 +3458,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf.data = from->si_perf.data; + to->si_perf.type = from->si_perf.type;break ;case SIL_CHLD : to->si_pid = from->si_pid; --2.30.1
Re: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
Quoted 32 lines · Eric W. Biederman
Quoted 9 lines · Marco Elver
Quoted 5 lines · Eric W. Biederman
Don't abuse
si_errnoand deliver all of the perf data insi_perf.Signed-off-by "Eric W. Biederman" <[email protected]>---
Thank you for the fix, this looks cleaner.
Quoted 7 lines
Just note that this patch needs to include updates to
tools/testing/selftests/perf_events. This should do it:Quoted 1 line
sed -i 's/si_perf/si_perf.data/g; s/si_errno/si_perf.type/g'
tools/testing/selftests/perf_events/*.cSubject: s/perf_data/perf data/ ?
For uapi, need to switch to
__u32, see below.Good point.
The one thing that this doesn't do is give you a 64bit field on 32bit architectures.
On 32bit builds the layout is:
int si_signo; int si_errno; int si_code; void __user *_addr;
Quoted 5 lines
So I believe if the first 3 fields were moved into the
_sifieldsunionsi_perfcould define a 64bit field as it's first member and it would not break anything else.Given that the data field is 64bit that seems desirable.
Yes, it's quite unfortunate -- it was __u64 at first, but then we noticed it broke 32-bit architectures like arm:
https://lore.kernel.org/linux-arch/[email protected]/
Thanks,
-- Marco
Peter Zijlstra
maintainerRe: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
In reply to Eric W. BiedermanQuoted 10 lines · Eric W. Biederman
The one thing that this doesn't do is give you a 64bit field on 32bit architectures.
On 32bit builds the layout is:
int si_signo; int si_errno; int si_code; void __user *_addr;
Quoted 5 lines
So I believe if the first 3 fields were moved into the
_sifieldsunionsi_perfcould define a 64bit field as it's first member and it would not break anything else.Given that the data field is 64bit that seems desirable.
The data field is fundamentally an address, it is internally a u64 because the perf ring buffer has u64 alignment and it saves on compat crap etc.
So for the 32bit/compat case the high bits will always be 0 and truncating into an unsigned long is fine.
Re: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
Quoted 16 lines · Peter Zijlstra
Quoted 14 lines · Eric W. Biederman
The one thing that this doesn't do is give you a 64bit field on 32bit architectures.
On 32bit builds the layout is:
int si_signo; int si_errno; int si_code; void __user *_addr;So I believe if the first 3 fields were moved into the
_sifieldsunionsi_perfcould define a 64bit field as it's first member and it would not break anything else.
Quoted 8 lines
Quoted 1 line
Given that the data field is 64bit that seems desirable.
The data field is fundamentally an address, it is internally a u64 because the perf ring buffer has u64 alignment and it saves on compat crap etc.
So for the 32bit/compat case the high bits will always be 0 and truncating into an unsigned long is fine.
I see why it is fine to truncate the data field into an unsigned long.
Other than technical difficulties in extending siginfo_t is there any reason not to define data as a __u64?
Eric
Re: [PATCH 7/3] signal: Deliver all of the perf_data in si_perf
Quoted 24 lines · Eric W. Biederman
Quoted 22 lines · Peter Zijlstra
Quoted 10 lines · Eric W. Biederman
The one thing that this doesn't do is give you a 64bit field on 32bit architectures.
On 32bit builds the layout is:
int si_signo; int si_errno; int si_code; void __user *_addr;Quoted 5 lines
So I believe if the first 3 fields were moved into the
_sifieldsunionsi_perfcould define a 64bit field as it's first member and it would not break anything else.Given that the data field is 64bit that seems desirable.
The data field is fundamentally an address, it is internally a u64 because the perf ring buffer has u64 alignment and it saves on compat crap etc.
Quoted 7 lines
Quoted 2 lines
So for the 32bit/compat case the high bits will always be 0 and truncating into an unsigned long is fine.
I see why it is fine to truncate the data field into an unsigned long.
Other than technical difficulties in extending
siginfo_tis there any reason not to define data as a__u64?
No -- like I pointed at earlier, si_perf used to be __u64, but we can't because of the siginfo_t limitation. What we have now is fine, and not worth dwelling over given siginfo limitations.
Thanks,
-- Marco
Re: [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union
In reply to Eric W. BiedermanWell with 7 patches instead of 3 that was a little more than I thought I was going to send.
However that does demonstrate what I am thinking, and I think most of the changes are reasonable at this point.
I am very curious how synchronous this all is, because if this code is truly synchronous updating signalfd to handle this class of signal doesn't really make sense.
If the code is not synchronous using force_sig is questionable.
Eric W. Biederman (7):
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals with si_trapno set
signal: Remove __ARCH_SI_TRAPNO
signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
signal: Factor force_sig_perf out of perf_sigtrap
signal: Deliver all of the perf_data in si_perf
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++++---- arch/alpha/mm/fault.c | 4 +- arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 +++---- arch/sparc/kernel/traps_64.c | 44 ++++++-------- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- fs/signalfd.c | 13 ++-- include/linux/compat.h | 9 +-- include/linux/sched/signal.h | 13 ++-- include/linux/signal.h | 3 +- include/uapi/asm-generic/siginfo.h | 11 ++-- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +--- kernel/signal.c | 108 ++++++++++++++++++++++------------ 23 files changed, 149 insertions(+), 142 deletions(-)
Re: [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union
Quoted 13 lines · Eric W. Biederman
Well with 7 patches instead of 3 that was a little more than I thought I was going to send.
However that does demonstrate what I am thinking, and I think most of the changes are reasonable at this point.
I am very curious how synchronous this all is, because if this code is truly synchronous updating signalfd to handle this class of signal doesn't really make sense.
If the code is not synchronous using
force_sigis questionable.
Quoted 8 lines
Eric W. Biederman (7):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of theperf_datainsi_perf
Thank you for doing this so quickly -- it looks much cleaner. I'll have a more detailed look next week and also run some tests myself.
At a first glance, you've broken our tests intools/testing/selftests/perf_events/ -- needs a
s/si_perf/si_perf.data/, s/si_errno/si_perf.type/
Thanks!
-- Marco
Re: [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union
Quoted 23 lines · Marco Elver
Quoted 13 lines · Eric W. Biederman
Well with 7 patches instead of 3 that was a little more than I thought I was going to send.
However that does demonstrate what I am thinking, and I think most of the changes are reasonable at this point.
I am very curious how synchronous this all is, because if this code is truly synchronous updating signalfd to handle this class of signal doesn't really make sense.
If the code is not synchronous using
force_sigis questionable.Quoted 8 lines
Eric W. Biederman (7):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of theperf_datainsi_perf
Quoted 6 lines
Thank you for doing this so quickly -- it looks much cleaner. I'll have a more detailed look next week and also run some tests myself.
At a first glance, you've broken our tests in
tools/testing/selftests/perf_events/-- needs a
s/si_perf/si_perf.data/, s/si_errno/si_perf.type/
Yeah. I figured I did, but I couldn't figure out where the tests were and I didn't have a lot of time. I just wanted to get this out so we can do as much as reasonable before the ABI starts being actively used by userspace and we can't change it.
Eric
Re: [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union
Quoted 29 lines · Eric W. Biederman
Quoted 26 lines · Marco Elver
Quoted 13 lines · Eric W. Biederman
Well with 7 patches instead of 3 that was a little more than I thought I was going to send.
However that does demonstrate what I am thinking, and I think most of the changes are reasonable at this point.
I am very curious how synchronous this all is, because if this code is truly synchronous updating signalfd to handle this class of signal doesn't really make sense.
If the code is not synchronous using
force_sigis questionable.Quoted 8 lines
Eric W. Biederman (7):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of theperf_datainsi_perfThank you for doing this so quickly -- it looks much cleaner. I'll have a more detailed look next week and also run some tests myself.
Quoted 8 lines
Quoted 3 lines
At a first glance, you've broken our tests in
tools/testing/selftests/perf_events/-- needs a
s/si_perf/si_perf.data/, s/si_errno/si_perf.type/Yeah. I figured I did, but I couldn't figure out where the tests were and I didn't have a lot of time. I just wanted to get this out so we can do as much as reasonable before the ABI starts being actively used by userspace and we can't change it.
No worries, and agreed. I've run tools/testing/selftests/perf_events tests on x86-64 (native + 32-bit compat), and compile-tested x86-32, arm64, arm (with my static asserts), m68k, and sparc64. Some trivial breakages, note comments in other patches.
With the trivial fixes this looks good to me. I'll happily retest v2 when you send it.
Thanks,
-- Marco
cover signal: sort out si_trapno and si_perf
This is my attempt to sort out the ABI issues with SIGTRAP TRAP_PERF before any userspace code starts using the new ABI.
The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
- si_trapno can become an ordinary fault subfield.
- Reworking siginfo so that si_perf_data can be a 64bit field.
- struct signalfd_siginfo is almost full
Marco I have incorporated your static_assert changes and built on them to prevent having unexpected ABI changes.
The field si_trapno is changed to become an ordinary extension of the _sigfault member of siginfo.
The code is refactored a bit and then si_perf_data is made a 64bit, and si_perf_type is made distinct from si_errno.
Finally the signalfd_siginfo fields are removed as they appear to be filling up the structure without userspace actually being able to use them.
v1: https://lkml.kernel.org/r/[email protected]
Eric W. Biederman (9):
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals with si_trapno set
signal: Remove __ARCH_SI_TRAPNO
signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
signal: Factor force_sig_perf out of perf_sigtrap
signal: Redefine signinfo so 64bit fields are possible
signal: Deliver all of the siginfo perf data in _perf
signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
Marco Elver (3):
sparc64: Add compile-time asserts for siginfo_t offsets
arm: Add compile-time asserts for siginfo_t offsets
arm64: Add compile-time asserts for siginfo_t offsets
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 37 +++++++ arch/arm64/kernel/signal.c | 37 +++++++ arch/arm64/kernel/signal32.c | 37 +++++++ arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 35 +++++++ arch/sparc/kernel/signal_64.c | 34 +++++++ arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 20 ++-- fs/signalfd.c | 23 ++--- include/linux/compat.h | 38 ++++--- include/linux/sched/signal.h | 13 +-- include/linux/signal.h | 3 +- include/uapi/asm-generic/siginfo.h | 57 +++++++---- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +- kernel/signal.c | 113 +++++++++++++-------- .../selftests/perf_events/sigtrap_threads.c | 12 +-- 30 files changed, 402 insertions(+), 191 deletions(-)
PATCH 1/12 sparc64: Add compile-time asserts for siginfo_t offsets
From: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout. Unlike other architectures, sparc64 is special, because it is one of few architectures requiring si_trapno. ABI breaks around that field would only be caught here.
--- arch/sparc/kernel/signal32.c | 34 ++++++++++++++++++++++++++++++++++ arch/sparc/kernel/signal_64.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
arch/sparc/kernel/signal32.c +34 -0
@@ -745,3 +745,37 @@ asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp) out:return ret; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_trapno) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +33 -0
@@ -556,3 +556,36 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_trapno) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x20 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x28 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x30 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x28 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x20 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
Signature · 1 line
2.30.1
PATCH 2/12 arm: Add compile-time asserts for siginfo_t offsets
From: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
This could have caught that we cannot portably add 64-bit integers to siginfo_t on 32-bit architectures like Arm before reaching -next:
https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/arm/kernel/signal.c +36 -0
@@ -725,3 +725,39 @@ asmlinkage void do_rseq_syscall(struct pt_regs *regs)rseq_syscall (regs); }#endif + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.30.1
PATCH 3/12 arm64: Add compile-time asserts for siginfo_t offsets
In reply to Eric W. BeidermanFrom: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
--- arch/arm64/kernel/signal.c | 36 ++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/signal32.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
arch/arm64/kernel/signal.c +36 -0
@@ -973,3 +973,39 @@ void __init minsigstksz_setup(void)round_up (sizeof (struct frame_record ),16 ) +16 ;/* max alignment padding */ } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x18 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x18 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x1c );
arch/arm64/kernel/signal32.c +36 -0
@@ -457,3 +457,39 @@ void compat_setup_restart_syscall(struct pt_regs *regs) { regs->regs[7 ] = __NR_compat_restart_syscall; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.30.1
PATCH 4/12 siginfo: Move si_trapno inside the union inside _si_fault
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
It turns out that linux uses si_trapno very sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.
As such move si_trapno inside the union inside of _si_fault. This results in no change in placement, and makes it eaiser
to extend _si_fault in the future as this reduces the number of special cases. In particular with si_trapno included in the union it is no longer a concern that the union must be pointer alligned on most architectures because the union followes immediately after si_addr which is a pointer.
This change results in a difference in siginfo field placement on sparc and alpha for the fields si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. These architectures do not implement the signals that would use si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. Further these architecture have not yet implemented the userspace that would use si_perf.
The point of this change is in fact to correct these placement issues before sparc or alpha grow userspace that cares. This change was discussed[1] and the agreement is that this change is currently safe.
[1]: https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com
v1: https://lkml.kernel.org/r/[email protected]
--- arch/sparc/kernel/signal32.c | 10 +++++----- arch/sparc/kernel/signal_64.c | 10 +++++----- arch/x86/kernel/signal_compat.c | 3 +++ include/linux/compat.h | 5 ++--- include/uapi/asm-generic/siginfo.h | 7 ++----- kernel/signal.c | 1 + 6 files changed, 18 insertions(+), 18 deletions(-)
arch/sparc/kernel/signal32.c +5 -5
@@ -772,10 +772,10 @@ static_assert(offsetof(compat_siginfo_t, si_int) == 0x14);static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_trapno) ==0x10 ); -static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_lower) ==0x18 ); -static_assert (offsetof(compat_siginfo_t , si_upper) ==0x1c ); -static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x18 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +5 -5
@@ -582,10 +582,10 @@ static_assert(offsetof(siginfo_t, si_int) == 0x18);static_assert (offsetof(siginfo_t , si_ptr) ==0x18 );static_assert (offsetof(siginfo_t , si_addr) ==0x10 );static_assert (offsetof(siginfo_t , si_trapno) ==0x18 ); -static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x20 ); -static_assert (offsetof(siginfo_t , si_lower) ==0x28 ); -static_assert (offsetof(siginfo_t , si_upper) ==0x30 ); -static_assert (offsetof(siginfo_t , si_pkey) ==0x28 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x20 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x18 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
arch/x86/kernel/signal_compat.c +3 -0
@@ -127,6 +127,9 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_addr) !=0x10 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr) !=0x0C ); +BUILD_BUG_ON (offsetof(siginfo_t , si_trapno) !=0x18 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_trapno) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_addr_lsb) !=0x18 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr_lsb) !=0x10 );
include/linux/compat.h +2 -3
@@ -214,12 +214,11 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {compat_uptr_t _addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
include/uapi/asm-generic/siginfo.h +2 -5
@@ -63,9 +63,6 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {void __user *_addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #ifdef __ia64__int _imm;/* immediate value for "break" */ unsigned int _flags;/* see ia64 si_flags */
@@ -75,6 +72,8 @@ union __sifields {#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \ sizeof(short) : __alignof__(void *))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
@@ -150,9 +149,7 @@ typedef struct siginfo {#define si_int _sifields._rt._sigval.sival_int#define si_ptr _sifields._rt._sigval.sival_ptr#define si_addr _sifields._sigfault._addr -#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno -#endif #define si_addr_lsb _sifields._sigfault._addr_lsb#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper
kernel/signal.c +1 -0
@@ -4607,6 +4607,7 @@ static inline void siginfo_buildtime_checks(void)/* sigfault */ CHECK_OFFSET (si_addr); +CHECK_OFFSET (si_trapno);CHECK_OFFSET (si_addr_lsb);CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);
Signature · 1 line
2.30.1
PATCH 5/12 signal: Implement SIL_FAULT_TRAPNO
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that si_trapno is part of the union in _si_fault and available on all architectures, add SIL_FAULT_TRAPNO and update siginfo_layout to return SIL_FAULT_TRAPNO when si_trapno is actually used.
Update the code that uses siginfo_layout to deal with SIL_FAULT_TRAPNO and have the same code ignore si_trapno in in all other cases.
v1: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 8 +++----- include/linux/signal.h | 1 + kernel/signal.c | 37 +++++++++++++++---------------------- 3 files changed, 19 insertions(+), 27 deletions(-)
fs/signalfd.c +3 -5
@@ -123,15 +123,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :
include/linux/signal.h +1 -0
@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,
kernel/signal.c +15 -22
@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -3206,6 +3208,13 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (CONFIG_ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (CONFIG_SPARC ) && + (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR
@@ -3317,30 +3326,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
@@ -3401,30 +3402,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
Signature · 1 line
2.30.1
PATCH 6/12 signal: Use dedicated helpers to send signals with si_trapno set
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that si_trapno is no longer expected to be present for every fault reported using siginfo on alpha and sparc remove the trapno parameter from force_sig_fault, force_sig_fault_to_task and send_sig_fault.
Add two new helpers force_sig_fault_trapno and send_sig_fautl_trapno for those signals where trapno is expected to be set.
v1: https://lkml.kernel.org/r/[email protected]
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 24 ++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++++++++-------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++++------------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 12 +++------ kernel/signal.c | 41 +++++++++++++++++++++-------- 14 files changed, 88 insertions(+), 77 deletions(-)
arch/alpha/kernel/osf_sys.c +1 -1
@@ -878,7 +878,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,send_sig_fault (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ -0 , current); + current); }return 0 ; }
arch/alpha/kernel/signal.c +2 -2
@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
arch/alpha/kernel/traps.c +12 -12
@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void
@@ -268,12 +268,12 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc, current);return ;
@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */
@@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }
@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a
@@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }
@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }
arch/alpha/mm/fault.c +2 -2
@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC
arch/sparc/kernel/process_64.c +1 -1
@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \
arch/sparc/kernel/sys_sparc_32.c +1 -1
@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);
arch/sparc/kernel/sys_sparc_64.c +1 -1
@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif
arch/sparc/kernel/traps_32.c +11 -11
@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */
@@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;
@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif
@@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE
arch/sparc/kernel/traps_64.c +19 -25
144 lines not on this page · raw message
arch/sparc/kernel/unaligned_32.c +1 -1
@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }
arch/sparc/mm/fault_32.c +1 -1
@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)
arch/sparc/mm/fault_64.c +1 -1
@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)
include/linux/sched/signal.h +4 -8
@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else
@@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);
@@ -327,6 +319,10 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *task); +int force_sig_ptrace_errno_trap (int errno,void __user *addr);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);
kernel/signal.c +31 -10
78 lines not on this page · raw message
Signature · 1 line
2.30.1
PATCH 7/12 signal: Remove __ARCH_SI_TRAPNO
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that this define is no longer used remove it from the kernel.
v1: https://lkml.kernel.org/r/[email protected]
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/mips/include/uapi/asm/siginfo.h | 2 -- arch/sparc/include/uapi/asm/siginfo.h | 3 --- 3 files changed, 7 deletions(-)
arch/alpha/include/uapi/asm/siginfo.h +0 -2
@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif
arch/mips/include/uapi/asm/siginfo.h +0 -2
@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFO
arch/sparc/include/uapi/asm/siginfo.h +0 -3
@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h>
Signature · 1 line
2.30.1
PATCH 8/12 signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
It helps to know which part of the siginfo structure the siginfo_layout value is talking about.
v1: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 2 +- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/signalfd.c +1 -1
@@ -132,7 +132,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; new.ssi_perf = kinfo->si_perf;break ;
include/linux/signal.h +1 -1
@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,
kernel/signal.c +5 -5
@@ -1198,7 +1198,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;
@@ -2553,7 +2553,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;
@@ -3243,7 +3243,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;
@@ -3365,7 +3365,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf = from->si_perf;break ;
@@ -3441,7 +3441,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf = from->si_perf;break ;
Signature · 1 line
2.30.1
PATCH 9/12 signal: Factor force_sig_perf out of perf_sigtrap
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Separate generating the signal from deciding it needs to be sent.
v1: https://lkml.kernel.org/r/[email protected]
--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)
include/linux/sched/signal.h +1 -0
@@ -318,6 +318,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
kernel/events/core.c +2 -9
@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
@@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)
kernel/signal.c +13 -0
@@ -1753,6 +1753,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *addr,u32 type,u64 sig_data) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +#if IS_ENABLED (CONFIG_SPARC )int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) {
Signature · 1 line
2.30.1
PATCH 10/12 signal: Redefine signinfo so 64bit fields are possible
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
The si_perf code really wants to add a u64 field. This change enables that by reorganizing the definition of siginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.
--- arch/x86/kernel/signal_compat.c | 9 +++---- include/linux/compat.h | 28 +++++++++++++------- include/uapi/asm-generic/siginfo.h | 42 ++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 30 deletions(-)
arch/x86/kernel/signal_compat.c +3 -6
@@ -17,8 +17,6 @@*/ static inline void signal_compat_build_tests (void ) { -int _sifields_offset = offsetof(compat_siginfo_t , _sifields); -/* * If adding a new si_code, there is probably new data in * the siginfo. Make sure folks bumping the si_code
@@ -40,8 +38,7 @@ static inline void signal_compat_build_tests(void)* in the ABI, of course. Make sure none of them ever * move and are always at the beginning: */ -BUILD_BUG_ON (offsetof(compat_siginfo_t , _sifields) !=3 *sizeof (int )); -#define CHECK_CSI_OFFSET (name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name)) +#define CHECK_CSI_OFFSET (name) BUILD_BUG_ON(0 != offsetof(compat_siginfo_t, _sifields.name))BUILD_BUG_ON (offsetof(siginfo_t , si_signo) !=0 );BUILD_BUG_ON (offsetof(siginfo_t , si_errno) !=4 );
@@ -63,8 +60,8 @@ static inline void signal_compat_build_tests(void)* structure stays within the padding size (checked * above). */ -#define CHECK_CSI_SIZE (name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name)) -#define CHECK_SI_SIZE (name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name)) +#define CHECK_CSI_SIZE (name, size) BUILD_BUG_ON(((3*sizeof(int))+(size)) != sizeof(((compat_siginfo_t *)0)->_sifields.name)) +#define CHECK_SI_SIZE (name, size) BUILD_BUG_ON(((4*sizeof(int))+(size)) != sizeof(((siginfo_t *)0)->_sifields.name))CHECK_CSI_OFFSET (_kill);CHECK_CSI_SIZE (_kill,2 *sizeof (int ));
include/linux/compat.h +18 -10
@@ -158,27 +158,28 @@ typedef union compat_sigval {compat_uptr_t sival_ptr; } compat_sigval_t; -typedef struct compat_siginfo { - int si_signo; -#ifndef __ARCH_HAS_SWAPPED_SIGINFO - int si_errno; - int si_code; -#else - int si_code; - int si_errno; -#endif +#define __COMPAT_SIGINFO_COMMON \ + ___SIGINFO_COMMON; \ + int _common_pad[__alignof__(compat_uptr_t) != __alignof__(int)] +typedef struct compat_siginfo { + union { + struct { + __COMPAT_SIGINFO_COMMON; + }; union { - int _pad[128/sizeof(int) - 3]; + int _pad[128/sizeof(int)]; /* kill() */ struct { + __COMPAT_SIGINFO_COMMON; compat_pid_t _pid; /* sender's pid */ __compat_uid32_t _uid; /* sender's uid */ } _kill; /* POSIX.1b timers */ struct { + __COMPAT_SIGINFO_COMMON; compat_timer_t _tid; /* timer id */ int _overrun; /* overrun count */ compat_sigval_t _sigval; /* same as below */
@@ -186,6 +187,7 @@ typedef struct compat_siginfo {/* POSIX.1b signals */ struct { +__COMPAT_SIGINFO_COMMON ;compat_pid_t _pid;/* sender's pid */ __compat_uid32_t _uid;/* sender's uid */ compat_sigval_t _sigval;
@@ -193,6 +195,7 @@ typedef struct compat_siginfo {/* SIGCHLD */ struct { +__COMPAT_SIGINFO_COMMON ;compat_pid_t _pid;/* which child */ __compat_uid32_t _uid;/* sender's uid */ int _status;/* exit code */
@@ -203,6 +206,7 @@ typedef struct compat_siginfo { #ifdef CONFIG_X86_X32_ABI /* SIGCHLD (x32 version) */ struct { + __COMPAT_SIGINFO_COMMON; compat_pid_t _pid; /* which child */ __compat_uid32_t _uid; /* sender's uid */ int _status; /* exit code */
@@ -213,6 +217,7 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct { +__COMPAT_SIGINFO_COMMON ;compat_uptr_t _addr;/* faulting insn/memory ref. */ #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))
@@ -242,16 +247,19 @@ typedef struct compat_siginfo {/* SIGPOLL */ struct { +__COMPAT_SIGINFO_COMMON ;compat_long_t _band;/* POLL_IN, POLL_OUT, POLL_MSG */ int _fd; } _sigpoll;struct { +__COMPAT_SIGINFO_COMMON ;compat_uptr_t _call_addr;/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys; } _sifields; + }; } compat_siginfo_t;struct compat_rlimit {
include/uapi/asm-generic/siginfo.h +28 -14
96 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.
I decided to include this change because it is not that complicated, and it allows si_perf_data to have the definition that was originally desired.
If this looks difficult to make in the userspace definitions, or is otherwise a problem I don't mind dropping this change. I just figured since it was not too difficult and we are changing things anyway I should try for everything.
Eric
Quoted 241 lines
Signed-off-by "Eric W. Biederman" <[email protected]>--- arch/x86/kernel/signal_compat.c | 9 +++---- include/linux/compat.h | 28 +++++++++++++------- include/uapi/asm-generic/siginfo.h | 42 ++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 30 deletions(-)arch/x86/kernel/signal_compat.c +3
-6@@ -17,8 +17,6 @@*/ static inline void signal_compat_build_tests (void ) { -int _sifields_offset = offsetof(compat_siginfo_t , _sifields); -/* * If adding a new si_code, there is probably new data in * the siginfo. Make sure folks bumping the si_code @@ -40,8 +38,7 @@ static inline void signal_compat_build_tests(void)* in the ABI, of course. Make sure none of them ever * move and are always at the beginning: */ -BUILD_BUG_ON (offsetof(compat_siginfo_t , _sifields) !=3 *sizeof (int )); -#define CHECK_CSI_OFFSET (name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name)) +#define CHECK_CSI_OFFSET (name) BUILD_BUG_ON(0 != offsetof(compat_siginfo_t, _sifields.name))BUILD_BUG_ON (offsetof(siginfo_t , si_signo) !=0 );BUILD_BUG_ON (offsetof(siginfo_t , si_errno) !=4 );@@ -63,8 +60,8 @@ static inline void signal_compat_build_tests(void)* structure stays within the padding size (checked * above). */ -#define CHECK_CSI_SIZE (name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name)) -#define CHECK_SI_SIZE (name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name)) +#define CHECK_CSI_SIZE (name, size) BUILD_BUG_ON(((3*sizeof(int))+(size)) != sizeof(((compat_siginfo_t *)0)->_sifields.name)) +#define CHECK_SI_SIZE (name, size) BUILD_BUG_ON(((4*sizeof(int))+(size)) != sizeof(((siginfo_t *)0)->_sifields.name))CHECK_CSI_OFFSET (_kill);CHECK_CSI_SIZE (_kill,2 *sizeof (int ));include/linux/compat.h +18
-10@@ -158,27 +158,28 @@ typedef union compat_sigval {compat_uptr_t sival_ptr; } compat_sigval_t; -typedef struct compat_siginfo { - int si_signo; -#ifndef __ARCH_HAS_SWAPPED_SIGINFO - int si_errno; - int si_code; -#else - int si_code; - int si_errno; -#endif +#define __COMPAT_SIGINFO_COMMON \ + ___SIGINFO_COMMON; \ + int _common_pad[__alignof__(compat_uptr_t) != __alignof__(int)] +typedef struct compat_siginfo { + union { + struct { + __COMPAT_SIGINFO_COMMON; + }; union { - int _pad[128/sizeof(int) - 3]; + int _pad[128/sizeof(int)]; /* kill() */ struct { + __COMPAT_SIGINFO_COMMON; compat_pid_t _pid; /* sender's pid */ __compat_uid32_t _uid; /* sender's uid */ } _kill; /* POSIX.1b timers */ struct { + __COMPAT_SIGINFO_COMMON; compat_timer_t _tid; /* timer id */ int _overrun; /* overrun count */ compat_sigval_t _sigval; /* same as below */@@ -186,6 +187,7 @@ typedef struct compat_siginfo {/* POSIX.1b signals */ struct { +__COMPAT_SIGINFO_COMMON ;compat_pid_t _pid;/* sender's pid */ __compat_uid32_t _uid;/* sender's uid */ compat_sigval_t _sigval;@@ -193,6 +195,7 @@ typedef struct compat_siginfo {/* SIGCHLD */ struct { +__COMPAT_SIGINFO_COMMON ;compat_pid_t _pid;/* which child */ __compat_uid32_t _uid;/* sender's uid */ int _status;/* exit code */ @@ -203,6 +206,7 @@ typedef struct compat_siginfo { #ifdef CONFIG_X86_X32_ABI /* SIGCHLD (x32 version) */ struct { + __COMPAT_SIGINFO_COMMON; compat_pid_t _pid; /* which child */ __compat_uid32_t _uid; /* sender's uid */ int _status; /* exit code */@@ -213,6 +217,7 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct { +__COMPAT_SIGINFO_COMMON ;compat_uptr_t _addr;/* faulting insn/memory ref. */ #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))@@ -242,16 +247,19 @@ typedef struct compat_siginfo {/* SIGPOLL */ struct { +__COMPAT_SIGINFO_COMMON ;compat_long_t _band;/* POLL_IN, POLL_OUT, POLL_MSG */ int _fd; } _sigpoll;struct { +__COMPAT_SIGINFO_COMMON ;compat_uptr_t _call_addr;/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys; } _sifields; + }; } compat_siginfo_t;struct compat_rlimit {include/uapi/asm-generic/siginfo.h +28
-14@@ -29,15 +29,33 @@ typedef union sigval {#define __ARCH_SI_ATTRIBUTES#endif +#ifndef __ARCH_HAS_SWAPPED_SIGINFO +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_errno; \ + int si_code +#else +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_code; \ + int si_errno +#endif /* __ARCH_HAS_SWAPPED_SIGINFO */ + +#define __SIGINFO_COMMON \ + ___SIGINFO_COMMON; \ + int _common_pad[__alignof__(void *) != __alignof(int)] +union __sifields {/* kill() */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* sender's pid */ __kernel_uid32_t _uid;/* sender's uid */ } _kill;/* POSIX.1b timers */ struct { +__SIGINFO_COMMON ;__kernel_timer_t _tid;/* timer id */ int _overrun;/* overrun count */ sigval_t _sigval;/* same as below */ @@ -46,6 +64,7 @@ union __sifields {/* POSIX.1b signals */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* sender's pid */ __kernel_uid32_t _uid;/* sender's uid */ sigval_t _sigval;@@ -53,6 +72,7 @@ union __sifields {/* SIGCHLD */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* which child */ __kernel_uid32_t _uid;/* sender's uid */ int _status;/* exit code */ @@ -62,6 +82,7 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct { +__SIGINFO_COMMON ;void __user *_addr;/* faulting insn/memory ref. */ #ifdef __ia64__int _imm;/* immediate value for "break" */ @@ -97,35 +118,28 @@ union __sifields {/* SIGPOLL */ struct { +__SIGINFO_COMMON ;__ARCH_SI_BAND_T _band;/* POLL_IN, POLL_OUT, POLL_MSG */ int _fd; } _sigpoll;/* SIGSYS */ struct { +__SIGINFO_COMMON ;void __user *_call_addr;/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys; }; -#ifndef __ARCH_HAS_SWAPPED_SIGINFO -#define __SIGINFO \ -struct { \ - int si_signo; \ - int si_errno; \ - int si_code; \ - union __sifields _sifields; \ -} -#else +#define __SIGINFO \ -struct { \ - int si_signo; \ - int si_code; \ - int si_errno; \ +union { \ + struct { \ + __SIGINFO_COMMON; \ + }; \ union __sifields _sifields; \ } -#endif /* __ARCH_HAS_SWAPPED_SIGINFO */ typedef struct siginfo { union {
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.
If you can, it'd be good to have an explanation for this, because it's not at all obvious -- some future archeologist will wonder how we ever came up with this definition of siginfo...
(I see the trick here is that before the union would have changed alignment, introducing padding after the 3 ints -- but now because the 3 ints are inside the union the union's padding no longer adds padding for these ints. Perhaps you can explain it better than I can. Also see below.)
Quoted 3 lines
I decided to include this change because it is not that complicated, and it allows
si_perf_datato have the definition that was originally desired.
Neat, and long-term I think this seems to be worth having. Sooner or later something else might want __u64, too.
But right now, due to the slight increase in complexity, we need to take extra care ensuring nothing broke -- at a high-level I see why this seems to be safe.
Quoted 4 lines
If this looks difficult to make in the userspace definitions, or is otherwise a problem I don't mind dropping this change. I just figured since it was not too difficult and we are changing things anyway I should try for everything.
Languages that support inheritance might end up with the simpler definition here (and depending on which fields they want to access, they'd have to cast the base siginfo into the one they want). What will become annoying is trying to describe siginfo_t.
I will run some tests in the morning.
Thanks,
-- Marco
[...]
Quoted 8 lines
Quoted 8 lines
include/uapi/asm-generic/siginfo.h +0
-0@@ -29,15 +29,33 @@ typedef union sigval {#define __ARCH_SI_ATTRIBUTES#endif
Quoted 15 lines
Quoted 5 lines
include/uapi/asm-generic/siginfo.h +5
-0+#ifndef __ARCH_HAS_SWAPPED_SIGINFO +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_errno; \ + int si_codeinclude/uapi/asm-generic/siginfo.h typedef union sigval { · line 46
Quoted 10 lines
include/uapi/asm-generic/siginfo.h +10
-0+#else +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_code; \ + int si_errno +#endif /* __ARCH_HAS_SWAPPED_SIGINFO */ + +#define __SIGINFO_COMMON \ + ___SIGINFO_COMMON; \ + int _common_pad[__alignof__(void *) != __alignof(int)]
Just to verify my understanding of _common_pad: this is again a legacy problem, right? I.e. if siginfo was designed from the start like this, we wouldn't need the _common_pad.
While this looks quite daunting, this is effectively turning siginfo from a struct with a giant union, into lots of smaller structs, each of which share a common header a'la inheritance -- until now the distinction didn't matter, but it starts to matter as soon as alignment of one child-struct would affect the offsets of another child-struct (i.e. the old version). Right?
I was wondering if it would make things look cleaner if the above was encapsulated in a struct, say __sicommon? Then the outermost union would use 'struct __sicommon _sicommon' and we need #defines for si_signo, si_code, and si_errno.
Or would it break alignment somewhere?
I leave it to your judgement -- just an idea.
Quoted 81 lines
Quoted 81 lines
include/uapi/asm-generic/siginfo.h +12
-14union __sifields {/* kill() */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* sender's pid */ __kernel_uid32_t _uid;/* sender's uid */ } _kill;/* POSIX.1b timers */ struct { +__SIGINFO_COMMON ;__kernel_timer_t _tid;/* timer id */ int _overrun;/* overrun count */ sigval_t _sigval;/* same as below */ @@ -46,6 +64,7 @@ union __sifields {/* POSIX.1b signals */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* sender's pid */ __kernel_uid32_t _uid;/* sender's uid */ sigval_t _sigval;@@ -53,6 +72,7 @@ union __sifields {/* SIGCHLD */ struct { +__SIGINFO_COMMON ;__kernel_pid_t _pid;/* which child */ __kernel_uid32_t _uid;/* sender's uid */ int _status;/* exit code */ @@ -62,6 +82,7 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct { +__SIGINFO_COMMON ;void __user *_addr;/* faulting insn/memory ref. */ #ifdef __ia64__int _imm;/* immediate value for "break" */ @@ -97,35 +118,28 @@ union __sifields {/* SIGPOLL */ struct { +__SIGINFO_COMMON ;__ARCH_SI_BAND_T _band;/* POLL_IN, POLL_OUT, POLL_MSG */ int _fd; } _sigpoll;/* SIGSYS */ struct { +__SIGINFO_COMMON ;void __user *_call_addr;/* calling user insn */ int _syscall;/* triggering system call number */ unsigned int _arch;/* AUDIT_ARCH_* of syscall */ } _sigsys; }; -#ifndef __ARCH_HAS_SWAPPED_SIGINFO -#define __SIGINFO \ -struct { \ - int si_signo; \ - int si_errno; \ - int si_code; \ - union __sifields _sifields; \ -} -#else +#define __SIGINFO \ -struct { \ - int si_signo; \ - int si_code; \ - int si_errno; \ +union { \ + struct { \ + __SIGINFO_COMMON; \ + }; \ union __sifields _sifields; \ } -#endif /* __ARCH_HAS_SWAPPED_SIGINFO */ typedef struct siginfo { union {
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 12 lines · Marco Elver
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.If you can, it'd be good to have an explanation for this, because it's not at all obvious -- some future archeologist will wonder how we ever came up with this definition of siginfo...
Quoted 5 lines
(I see the trick here is that before the union would have changed alignment, introducing padding after the 3 ints -- but now because the 3 ints are inside the union the union's padding no longer adds padding for these ints. Perhaps you can explain it better than I can. Also see below.)
Yes. The big idea is adding a 64bit field into the second union in the _sigfault case will increase the alignment of that second union to 64bit.
In the 64bit case the alignment is already 64bit so it is not an issue.
In the 32bit case there are 3 ints followed by a pointer. When the 64bit member is added the alignment of _segfault becomes 64bit. That 64bit alignment after 3 ints changes the location of the 32bit pointer.
By moving the 3 preceding ints into _segfault that does not happen.
There remains one very subtle issue that I think isn't a problem but I would appreciate someone else double checking me.
The old definition of siginfo_t on 32bit almost certainly had 32bit alignment. With the addition of a 64bit member siginfo_t gains 64bit alignment. This difference only matters if the 64bit field is accessed. Accessing a 64bit field with 32bit alignment will cause unaligned access exceptions on some (most?) architectures.
For the 64bit field to be accessed the code needs to be recompiled with the new headers. Which implies that when everything is recompiled siginfo_t will become 64bit aligned.
So the change should be safe unless someone is casting something with 32bit alignment into siginfo_t.
Quoted 11 lines
Quoted 4 lines
I decided to include this change because it is not that complicated, and it allows
si_perf_datato have the definition that was originally desired.Neat, and long-term I think this seems to be worth having. Sooner or later something else might want
__u64, too.But right now, due to the slight increase in complexity, we need to take extra care ensuring nothing broke -- at a high-level I see why this seems to be safe.
Absolutely.
Quoted 35 lines
Quoted 4 lines
If this looks difficult to make in the userspace definitions, or is otherwise a problem I don't mind dropping this change. I just figured since it was not too difficult and we are changing things anyway I should try for everything.
Languages that support inheritance might end up with the simpler definition here (and depending on which fields they want to access, they'd have to cast the base siginfo into the one they want). What will become annoying is trying to describe
siginfo_t.I will run some tests in the morning.
Thanks,
-- Marco[...]
Quoted 19 lines
Quoted 19 lines
include/uapi/asm-generic/siginfo.h +11
-0@@ -29,15 +29,33 @@ typedef union sigval {#define __ARCH_SI_ATTRIBUTES#endif +#ifndef __ARCH_HAS_SWAPPED_SIGINFO +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_errno; \ + int si_code +#else +#define ___SIGINFO_COMMON \ + int si_signo; \ + int si_code; \ + int si_errno +#endif /* __ARCH_HAS_SWAPPED_SIGINFO */
Quoted 8 lines
Quoted 4 lines
include/uapi/asm-generic/siginfo.h typedef union sigval { · line 46
Quoted 4 lines
include/uapi/asm-generic/siginfo.h +4
-0+ +#define __SIGINFO_COMMON \ + ___SIGINFO_COMMON; \ + int _common_pad[__alignof__(void *) != __alignof(int)]Just to verify my understanding of
_common_pad: this is again a legacy problem, right? I.e. if siginfo was designed from the start like this, we wouldn't need the_common_pad.
Correct.
If we are designing things carefully from the start the code could have had a 64bit or a 128bit header that was common to all siginfo instances. Then the trick of moving the header into each union member would not have been necessary.
Unfortunately no one noticed until it was much too late to do anything about it.
Quoted 6 lines
While this looks quite daunting, this is effectively turning siginfo from a struct with a giant union, into lots of smaller structs, each of which share a common header a'la inheritance -- until now the distinction didn't matter, but it starts to matter as soon as alignment of one child-struct would affect the offsets of another child-struct (i.e. the old version). Right?
Correct.
Quoted 8 lines
I was wondering if it would make things look cleaner if the above was encapsulated in a struct, say
__sicommon? Then the outermost union would use 'struct__sicommon_sicommon' and we need #defines forsi_signo,si_code, andsi_errno.Or would it break alignment somewhere?
I leave it to your judgement -- just an idea.
I tried it and kernel/signal.c would not compile because a few functions have a parameter named si_code. The kernel I could fix but there is a chance some user space application has similar issues.
So to be safe si_signo, si_code, si_errno have to be available without having a define.
Eric
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 46 lines · Eric W. Biederman
Quoted 12 lines · Marco Elver
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.If you can, it'd be good to have an explanation for this, because it's not at all obvious -- some future archeologist will wonder how we ever came up with this definition of siginfo...
Quoted 5 lines
(I see the trick here is that before the union would have changed alignment, introducing padding after the 3 ints -- but now because the 3 ints are inside the union the union's padding no longer adds padding for these ints. Perhaps you can explain it better than I can. Also see below.)
Yes. The big idea is adding a 64bit field into the second union in the
_sigfaultcase will increase the alignment of that second union to 64bit.In the 64bit case the alignment is already 64bit so it is not an issue.
In the 32bit case there are 3 ints followed by a pointer. When the 64bit member is added the alignment of
_segfaultbecomes 64bit. That 64bit alignment after 3 ints changes the location of the 32bit pointer.By moving the 3 preceding ints into
_segfaultthat does not happen.There remains one very subtle issue that I think isn't a problem but I would appreciate someone else double checking me.
The old definition of
siginfo_ton 32bit almost certainly had 32bit alignment. With the addition of a 64bit membersiginfo_tgains 64bit alignment. This difference only matters if the 64bit field is accessed. Accessing a 64bit field with 32bit alignment will cause unaligned access exceptions on some (most?) architectures.
Quoted 7 lines
For the 64bit field to be accessed the code needs to be recompiled with the new headers. Which implies that when everything is recompiled
siginfo_twill become 64bit aligned.So the change should be safe unless someone is casting something with 32bit alignment into
siginfo_t.
How about if someone has a field of type siginfo_t as an element of a struct? For example:
struct foo {
int x;
siginfo_t y;
};
With this change wouldn't the y field move from offset 4 to offset 8?
Peter
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 56 lines · Peter Collingbourne
Quoted 44 lines · Eric W. Biederman
Quoted 12 lines · Marco Elver
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.If you can, it'd be good to have an explanation for this, because it's not at all obvious -- some future archeologist will wonder how we ever came up with this definition of siginfo...
Quoted 5 lines
(I see the trick here is that before the union would have changed alignment, introducing padding after the 3 ints -- but now because the 3 ints are inside the union the union's padding no longer adds padding for these ints. Perhaps you can explain it better than I can. Also see below.)
Yes. The big idea is adding a 64bit field into the second union in the
_sigfaultcase will increase the alignment of that second union to 64bit.In the 64bit case the alignment is already 64bit so it is not an issue.
In the 32bit case there are 3 ints followed by a pointer. When the 64bit member is added the alignment of
_segfaultbecomes 64bit. That 64bit alignment after 3 ints changes the location of the 32bit pointer.By moving the 3 preceding ints into
_segfaultthat does not happen.There remains one very subtle issue that I think isn't a problem but I would appreciate someone else double checking me.
The old definition of
siginfo_ton 32bit almost certainly had 32bit alignment. With the addition of a 64bit membersiginfo_tgains 64bit alignment. This difference only matters if the 64bit field is accessed. Accessing a 64bit field with 32bit alignment will cause unaligned access exceptions on some (most?) architectures.Quoted 7 lines
For the 64bit field to be accessed the code needs to be recompiled with the new headers. Which implies that when everything is recompiled
siginfo_twill become 64bit aligned.So the change should be safe unless someone is casting something with 32bit alignment into
siginfo_t.How about if someone has a field of type
siginfo_tas an element of a struct? For example:
Quoted 6 lines
struct foo {
int x;
siginfo_ty;
};With this change wouldn't the y field move from offset 4 to offset 8?
This is a problem if such a struct is part of the ABI -- in the kernel I found these that might be problematic:
| arch/csky/kernel/signal.c:struct rt_sigframe {
| arch/csky/kernel/signal.c- /*
| arch/csky/kernel/signal.c- * pad[3] is compatible with the same struct defined in
| arch/csky/kernel/signal.c- * gcc/libgcc/config/csky/linux-unwind.h
| arch/csky/kernel/signal.c- */
| arch/csky/kernel/signal.c- int pad[3];
| arch/csky/kernel/signal.c- struct siginfo info;
| arch/csky/kernel/signal.c- struct ucontext uc;
| arch/csky/kernel/signal.c-};
| [...]
| arch/parisc/include/asm/rt_sigframe.h-#define SIGRETURN_TRAMP 4
| arch/parisc/include/asm/rt_sigframe.h-#define SIGRESTARTBLOCK_TRAMP 5
| arch/parisc/include/asm/rt_sigframe.h-#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP)
| arch/parisc/include/asm/rt_sigframe.h-
| arch/parisc/include/asm/rt_sigframe.h:struct rt_sigframe {
| arch/parisc/include/asm/rt_sigframe.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c
| arch/parisc/include/asm/rt_sigframe.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK
| arch/parisc/include/asm/rt_sigframe.h- trampoline we left on the stack (we were bad and didn't
| arch/parisc/include/asm/rt_sigframe.h- change sp so we could run really fast.) */
| arch/parisc/include/asm/rt_sigframe.h- unsigned int tramp[TRAMP_SIZE];
| arch/parisc/include/asm/rt_sigframe.h- struct siginfo info;
| [..]
| arch/parisc/kernel/signal32.h-#define COMPAT_SIGRETURN_TRAMP 4
| arch/parisc/kernel/signal32.h-#define COMPAT_SIGRESTARTBLOCK_TRAMP 5
| arch/parisc/kernel/signal32.h-#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \
| arch/parisc/kernel/signal32.h- COMPAT_SIGRESTARTBLOCK_TRAMP)
| arch/parisc/kernel/signal32.h-
| arch/parisc/kernel/signal32.h:struct compat_rt_sigframe {
| arch/parisc/kernel/signal32.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c
| arch/parisc/kernel/signal32.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK
| arch/parisc/kernel/signal32.h- trampoline we left on the stack (we were bad and didn't
| arch/parisc/kernel/signal32.h- change sp so we could run really fast.) */
| arch/parisc/kernel/signal32.h- compat_uint_t tramp[COMPAT_TRAMP_SIZE];
| arch/parisc/kernel/signal32.h- compat_siginfo_t info;Adding these static asserts to parisc shows the problem:
| diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c | index fb1e94a3982b..0be582fb81be 100644 | --- a/arch/parisc/kernel/signal.c | +++ b/arch/parisc/kernel/signal.c | @@ -610,3 +610,6 @@ void do_notify_resume(struct pt_regs *regs, long in_syscall) | if (test_thread_flag(TIF_NOTIFY_RESUME)) | tracehook_notify_resume(regs); | } | + | +static_assert(sizeof(unsigned long) == 4); // 32 bit build | +static_assert(offsetof(struct rt_sigframe, info) == 9 * 4);
This passes without the siginfo rework in this patch. With it:
| ./include/linux/build_bug.h:78:41: error: static assertion failed: "offsetof(struct rt_sigframe, info) == 9 * 4"
As sad as it is, I don't think we can have our cake and eat it, too. :-(
Unless you see why this is fine, I think we need to drop this patch and go back to the simpler version you had.
Thanks,
-- Marco
Re: [PATCH 10/12] signal: Redefine signinfo so 64bit fields are possible
Quoted 116 lines · Marco Elver
Quoted 56 lines · Peter Collingbourne
Quoted 44 lines · Eric W. Biederman
Quoted 12 lines · Marco Elver
Quoted 6 lines · Eric W. Biederman
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
The
si_perfcode really wants to add a u64 field. This change enables that by reorganizing the definition ofsiginfo_t, so that a 64bit field can be added without increasing the alignment of other fields.If you can, it'd be good to have an explanation for this, because it's not at all obvious -- some future archeologist will wonder how we ever came up with this definition of siginfo...
Quoted 5 lines
(I see the trick here is that before the union would have changed alignment, introducing padding after the 3 ints -- but now because the 3 ints are inside the union the union's padding no longer adds padding for these ints. Perhaps you can explain it better than I can. Also see below.)
Yes. The big idea is adding a 64bit field into the second union in the
_sigfaultcase will increase the alignment of that second union to 64bit.In the 64bit case the alignment is already 64bit so it is not an issue.
In the 32bit case there are 3 ints followed by a pointer. When the 64bit member is added the alignment of
_segfaultbecomes 64bit. That 64bit alignment after 3 ints changes the location of the 32bit pointer.By moving the 3 preceding ints into
_segfaultthat does not happen.There remains one very subtle issue that I think isn't a problem but I would appreciate someone else double checking me.
The old definition of
siginfo_ton 32bit almost certainly had 32bit alignment. With the addition of a 64bit membersiginfo_tgains 64bit alignment. This difference only matters if the 64bit field is accessed. Accessing a 64bit field with 32bit alignment will cause unaligned access exceptions on some (most?) architectures.Quoted 7 lines
For the 64bit field to be accessed the code needs to be recompiled with the new headers. Which implies that when everything is recompiled
siginfo_twill become 64bit aligned.So the change should be safe unless someone is casting something with 32bit alignment into
siginfo_t.How about if someone has a field of type
siginfo_tas an element of a struct? For example:Quoted 6 lines
struct foo {
int x;
siginfo_ty;
};With this change wouldn't the y field move from offset 4 to offset 8?
This is a problem if such a struct is part of the ABI -- in the kernel I found these that might be problematic:
| arch/csky/kernel/signal.c:struct rt_sigframe { | arch/csky/kernel/signal.c- /* | arch/csky/kernel/signal.c- * pad[3] is compatible with the same struct defined in | arch/csky/kernel/signal.c- * gcc/libgcc/config/csky/linux-unwind.h | arch/csky/kernel/signal.c- */ | arch/csky/kernel/signal.c- int pad[3]; | arch/csky/kernel/signal.c- struct siginfo info; | arch/csky/kernel/signal.c- struct ucontext uc; | arch/csky/kernel/signal.c-}; | [...] | arch/parisc/include/asm/rt_sigframe.h-#define SIGRETURN_TRAMP 4 | arch/parisc/include/asm/rt_sigframe.h-#define SIGRESTARTBLOCK_TRAMP 5 | arch/parisc/include/asm/rt_sigframe.h-#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP) | arch/parisc/include/asm/rt_sigframe.h- | arch/parisc/include/asm/rt_sigframe.h:struct rt_sigframe { | arch/parisc/include/asm/rt_sigframe.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c | arch/parisc/include/asm/rt_sigframe.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK | arch/parisc/include/asm/rt_sigframe.h- trampoline we left on the stack (we were bad and didn't | arch/parisc/include/asm/rt_sigframe.h- change sp so we could run really fast.) */ | arch/parisc/include/asm/rt_sigframe.h- unsigned int tramp[TRAMP_SIZE]; | arch/parisc/include/asm/rt_sigframe.h- struct siginfo info; | [..] | arch/parisc/kernel/signal32.h-#define COMPAT_SIGRETURN_TRAMP 4 | arch/parisc/kernel/signal32.h-#define COMPAT_SIGRESTARTBLOCK_TRAMP 5 | arch/parisc/kernel/signal32.h-#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ | arch/parisc/kernel/signal32.h- COMPAT_SIGRESTARTBLOCK_TRAMP) | arch/parisc/kernel/signal32.h- | arch/parisc/kernel/signal32.h:struct compat_rt_sigframe { | arch/parisc/kernel/signal32.h- /* XXX: Must match trampoline size in arch/parisc/kernel/signal.c | arch/parisc/kernel/signal32.h- Secondary to that it must protect the ERESTART_RESTARTBLOCK | arch/parisc/kernel/signal32.h- trampoline we left on the stack (we were bad and didn't | arch/parisc/kernel/signal32.h- change sp so we could run really fast.) */ | arch/parisc/kernel/signal32.h- compat_uint_t tramp[COMPAT_TRAMP_SIZE]; | arch/parisc/kernel/signal32.h- compat_siginfo_t info;Adding these static asserts to parisc shows the problem:
| diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c | index fb1e94a3982b..0be582fb81be 100644 | --- a/arch/parisc/kernel/signal.c | +++ b/arch/parisc/kernel/signal.c | @@ -610,3 +610,6 @@ void do_notify_resume(struct pt_regs *regs, long in_syscall) | if (test_thread_flag(TIF_NOTIFY_RESUME)) | tracehook_notify_resume(regs); | } | + | +static_assert(sizeof(unsigned long) == 4); // 32 bit build | +static_assert(offsetof(struct rt_sigframe, info) == 9 * 4);
Quoted 8 lines
This passes without the siginfo rework in this patch. With it:
|
./include/linux/build_bug.h:78:41: error: static assertion failed: "offsetof(struct rt_sigframe, info)== 9 * 4"As sad as it is, I don't think we can have our cake and eat it, too. :-(
Unless you see why this is fine, I think we need to drop this patch and go back to the simpler version you had.
No. I really can't. I think we are stuck with 32bit alignment on 32bit architectures at this point. Which precludes 32bit architectures from including a 64bit field.
The variant of this that concerns me the most is siginfo_t embedded in a structure in a library combined with code that is compiled with new headers. The offset of the embedded siginfo_t could very easily change and break things.
That makes the alignment an ABI property we can't mess with. Shame.
I will figure out some static asserts to verify this property remains on 32bit and respin this series.
Eric
PATCH 11/12 signal: Deliver all of the siginfo perf data in _perf
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Don't abuse si_errno and deliver all of the perf data in _perf member of siginfo_t.
Because it is possible increase the size of perf_data to 64bits.
v1: https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 3 ++- arch/arm64/kernel/signal.c | 3 ++- arch/arm64/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal_64.c | 3 ++- arch/x86/kernel/signal_compat.c | 8 ++++--- fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 8 +++++-- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 21 ++++++++++++------- .../selftests/perf_events/sigtrap_threads.c | 12 +++++------ 12 files changed, 48 insertions(+), 28 deletions(-)
arch/arm/kernel/signal.c +2 -1
@@ -755,7 +755,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(siginfo_t , si_lower) ==0x14 );static_assert (offsetof(siginfo_t , si_upper) ==0x18 );static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x18 );static_assert (offsetof(siginfo_t , si_band) ==0x0c );static_assert (offsetof(siginfo_t , si_fd) ==0x10 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c );
arch/arm64/kernel/signal.c +2 -1
@@ -1003,7 +1003,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x18 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 );
arch/arm64/kernel/signal32.c +2 -1
@@ -487,7 +487,8 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c );
arch/sparc/kernel/signal32.c +2 -1
@@ -776,6 +776,7 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +2 -1
@@ -586,6 +586,7 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
arch/x86/kernel/signal_compat.c +5 -3
@@ -118,7 +118,7 @@ static inline void signal_compat_build_tests(void)#endif CHECK_CSI_OFFSET (_sigfault); -CHECK_CSI_SIZE (_sigfault,4 *sizeof (int )); +CHECK_CSI_SIZE (_sigfault,5 *sizeof (int ));CHECK_SI_SIZE (_sigfault,8 *sizeof (int ));BUILD_BUG_ON (offsetof(siginfo_t , si_addr) !=0x10 );
@@ -138,8 +138,10 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x20 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_pkey) !=0x14 ); -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x18 ); -BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x18 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x20 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_type) !=0x18 );CHECK_CSI_OFFSET (_sigpoll);CHECK_CSI_SIZE (_sigpoll,2 *sizeof (int ));
fs/signalfd.c +2 -1
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf_type; + new.ssi_perf_data = kinfo->si_perf_data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;
include/linux/compat.h +4 -1
@@ -241,7 +241,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +u64 _data; +u32 _type; + } _perf; }; } _sigfault;
include/uapi/asm-generic/siginfo.h +6 -2
@@ -112,7 +112,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +__u64 _data; +__u32 _type; + } _perf; }; } _sigfault;
@@ -168,7 +171,8 @@ typedef struct siginfo {#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper#define si_pkey _sifields._sigfault._addr_pkey._pkey -#define si_perf _sifields._sigfault._perf +#define si_perf_data _sifields._sigfault._perf._data +#define si_perf_type _sifields._sigfault._perf._type#define si_band _sifields._sigpoll._band#define si_fd _sifields._sigpoll._fd#define si_call_addr _sifields._sigsys._call_addr
include/uapi/linux/signalfd.h +2 -2
@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
kernel/signal.c +13 -8
@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf_data = sig_data; + info.si_perf_type = type; +return force_sig_info (&info); }
@@ -3380,7 +3382,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -3456,7 +3459,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -4639,7 +4643,8 @@ static inline void siginfo_buildtime_checks(void)CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);CHECK_OFFSET (si_pkey); -CHECK_OFFSET (si_perf); +CHECK_OFFSET (si_perf_data); +CHECK_OFFSET (si_perf_type);/* sigpoll */ CHECK_OFFSET (si_band);
tools/testing/selftests/perf_events/sigtrap_threads.c +6 -6
@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)EXPECT_EQ (ctx.signal_count,NUM_THREADS * ctx.iterate_on);EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on)); }TEST_HARNESS_MAIN
Signature · 1 line
2.30.1
PATCH 12/12 signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
With the addition of ssi_perf_data and ssi_perf_type struct signalfd_siginfo is dangerously close to running out of space. All that remains is just enough space for two additional 64bit fields. A practice of adding all possible siginfo_t fields into struct singalfd_siginfo can not be supported as adding the missing fields ssi_lower, ssi_upper, and ssi_pkey would require two 64bit fields and one 32bit fields. In practice the fields ssi_perf_data and ssi_perf_type can never be used by signalfd as the signal that generates them always delivers them synchronously to the thread that triggers them.
Therefore until someone actually needs the fields ssi_perf_data and ssi_perf_type in signalfd_siginfo remove them. This leaves a bit more room for future expansion.
--- fs/signalfd.c | 16 ++++++---------- include/uapi/linux/signalfd.h | 4 +--- 2 files changed, 7 insertions(+), 13 deletions(-)
fs/signalfd.c +6 -10
@@ -114,12 +114,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : +case SIL_FAULT_PERF_EVENT :/* -* Fall through to the SIL_FAULT case. Both SIL_FAULT_BNDERR -* and SIL_FAULT_PKUERR are only generated by faults that -* deliver them synchronously to userspace. In case someone -* injects one of these signals and signalfd catches it treat -* it as SIL_FAULT. +* Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR, +* SIL_FAULT_PKUERR, and SIL_FAULT_PERF_EVENT are only +* generated by faults that deliver them synchronously to +* userspace. In case someone injects one of these signals +* and signalfd catches it treat it as SIL_FAULT. */ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr;
@@ -132,11 +133,6 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_FAULT_PERF_EVENT : - new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf_type = kinfo->si_perf_type; - new.ssi_perf_data = kinfo->si_perf_data; -break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid;
include/uapi/linux/signalfd.h +1 -3
@@ -39,8 +39,6 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 ssi_perf_type; -__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
@@ -51,7 +49,7 @@ struct signalfd_siginfo {* comes out of a read(2) and we really don't want to have * a compat on read(2). */ -__u8 __pad[16 ]; +__u8 __pad[28 ]; };
Signature · 1 line
2.30.1
v3 cover signal: sort out si_trapno and si_perf
In reply to Eric W. BiedermanThis set of changes sorts out the ABI issues with SIGTRAP TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.
The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
- si_trapno becomming ordinary fault subfield.
- struct signalfd_siginfo is almost full
This set of changes starts out with Marco's static_assert changes and additional one of my own that enforces the fact that the alignment of siginfo_t is also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.
The field si_trapno is changed to become an ordinary extension of the _sigfault member of siginfo.
The code is refactored a bit and then si_perf_type is added along side si_perf_data in the _perf subfield of _sigfault of siginfo_t.
Finally the signalfd_siginfo fields are removed as they appear to be filling up the structure without userspace actually being able to use them.
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
Eric W. Biederman (9):
signal: Verify the alignment and size of siginfo_t
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals with si_trapno set
signal: Remove __ARCH_SI_TRAPNO
signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
signal: Factor force_sig_perf out of perf_sigtrap
signal: Deliver all of the siginfo perf data in _perf
signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
Marco Elver (3):
sparc64: Add compile-time asserts for siginfo_t offsets
arm: Add compile-time asserts for siginfo_t offsets
arm64: Add compile-time asserts for siginfo_t offsets
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal32.c | 39 +++++++ arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 37 +++++++ arch/sparc/kernel/signal_64.c | 36 +++++++ arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 15 ++- fs/signalfd.c | 23 ++--- include/linux/compat.h | 10 +- include/linux/sched/signal.h | 13 +-- include/linux/signal.h | 3 +- include/uapi/asm-generic/siginfo.h | 20 ++-- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +- kernel/signal.c | 113 +++++++++++++-------- .../selftests/perf_events/sigtrap_threads.c | 12 +-- 30 files changed, 373 insertions(+), 160 deletions(-)
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
Quoted 40 lines · Eric W. Biederman
This set of changes sorts out the ABI issues with SIGTRAP
TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
-si_trapnobecomming ordinary fault subfield.
- structsignalfd_siginfois almost fullThis set of changes starts out with Marco's
static_assertchanges and additional one of my own that enforces the fact that the alignment ofsiginfo_tis also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.The field
si_trapnois changed to become an ordinary extension of the_sigfaultmember of siginfo.The code is refactored a bit and then
si_perf_typeis added along sidesi_perf_datain the_perfsubfield of_sigfaultofsiginfo_t.Finally the
signalfd_siginfofields are removed as they appear to be filling up the structure without userspace actually being able to use them.v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]Eric W. Biederman (9):
signal: Verify the alignment and size ofsiginfo_t
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_FAULT_PERF_EVENTfields fromsignalfd_siginfo
Quoted 4 lines
Marco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsets
I can't seem to see the rest of them in my inbox. LKML also is missing
them: https://lore.kernel.org/linux-api/[email protected]/
Something must have swallowed them. Could you resend? I'll then test in the morning.
Thanks,
-- Marco
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
Quoted 46 lines · Marco Elver
Quoted 40 lines · Eric W. Biederman
This set of changes sorts out the ABI issues with SIGTRAP
TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
-si_trapnobecomming ordinary fault subfield.
- structsignalfd_siginfois almost fullThis set of changes starts out with Marco's
static_assertchanges and additional one of my own that enforces the fact that the alignment ofsiginfo_tis also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.The field
si_trapnois changed to become an ordinary extension of the_sigfaultmember of siginfo.The code is refactored a bit and then
si_perf_typeis added along sidesi_perf_datain the_perfsubfield of_sigfaultofsiginfo_t.Finally the
signalfd_siginfofields are removed as they appear to be filling up the structure without userspace actually being able to use them.v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]Eric W. Biederman (9):
signal: Verify the alignment and size ofsiginfo_t
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_FAULT_PERF_EVENTfields fromsignalfd_siginfoQuoted 4 lines
Marco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsets
Quoted 5 lines
I can't seem to see the rest of them in my inbox. LKML also is missing
them: https://lore.kernel.org/linux-api/[email protected]/Something must have swallowed them. Could you resend? I'll then test in the morning.
They got stuck going out you should see them any time now. Sorry about that.
Eric
PATCH v3 1/12 sparc64: Add compile-time asserts for siginfo_t offsets
In reply to Eric W. BiedermanFrom: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout. Unlike other architectures, sparc64 is special, because it is one of few architectures requiring si_trapno. ABI breaks around that field would only be caught here.
--- arch/sparc/kernel/signal32.c | 34 ++++++++++++++++++++++++++++++++++ arch/sparc/kernel/signal_64.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
arch/sparc/kernel/signal32.c +34 -0
@@ -745,3 +745,37 @@ asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp) out:return ret; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_trapno) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +33 -0
@@ -556,3 +556,36 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_trapno) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x20 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x28 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x30 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x28 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x20 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
Signature · 1 line
2.30.1
PATCH v3 2/12 arm: Add compile-time asserts for siginfo_t offsets
From: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
This could have caught that we cannot portably add 64-bit integers to siginfo_t on 32-bit architectures like Arm before reaching -next:
https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/arm/kernel/signal.c +36 -0
@@ -725,3 +725,39 @@ asmlinkage void do_rseq_syscall(struct pt_regs *regs)rseq_syscall (regs); }#endif + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.30.1
PATCH v3 3/12 arm64: Add compile-time asserts for siginfo_t offsets
In reply to Eric W. BeidermanFrom: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
--- arch/arm64/kernel/signal.c | 36 ++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/signal32.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
arch/arm64/kernel/signal.c +36 -0
@@ -973,3 +973,39 @@ void __init minsigstksz_setup(void)round_up (sizeof (struct frame_record ),16 ) +16 ;/* max alignment padding */ } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x18 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x18 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x1c );
arch/arm64/kernel/signal32.c +36 -0
@@ -457,3 +457,39 @@ void compat_setup_restart_syscall(struct pt_regs *regs) { regs->regs[7 ] = __NR_compat_restart_syscall; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.30.1
PATCH v3 4/12 signal: Verify the alignment and size of siginfo_t
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Update the static assertions about siginfo_t to also describe it's alignment and size.
While investigating if it was possible to add a 64bit field into siginfo_t[1] it became apparent that the alignment of siginfo_t is as much a part of the ABI as the size of the structure.
If the alignment changes siginfo_t when embedded in another structure can move to a different offset. Which is not acceptable from an ABI structure.
So document that fact and add static assertions to notify developers if they change change the alignment by accident.
[1] https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 2 ++ arch/arm64/kernel/signal.c | 2 ++ arch/arm64/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal_64.c | 2 ++ arch/x86/kernel/signal_compat.c | 6 ++++++ include/uapi/asm-generic/siginfo.h | 5 +++++ 7 files changed, 21 insertions(+)
arch/arm/kernel/signal.c +2 -0
@@ -737,6 +737,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 ); +static_assert (__alignof__(siginfo_t ) ==4 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );
arch/arm64/kernel/signal.c +2 -0
@@ -985,6 +985,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 ); +static_assert (__alignof__(siginfo_t ) ==8 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );
arch/arm64/kernel/signal32.c +2 -0
@@ -469,6 +469,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (compat_siginfo_t) ==128 ); +static_assert (__alignof__(compat_siginfo_t ) ==4 );static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 );static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 );static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 );
arch/sparc/kernel/signal32.c +2 -0
@@ -757,6 +757,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (compat_siginfo_t) ==128 ); +static_assert (__alignof__(compat_siginfo_t ) ==4 );static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 );static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 );static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 );
arch/sparc/kernel/signal_64.c +2 -0
@@ -567,6 +567,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 ); +static_assert (__alignof__(siginfo_t ) ==8 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );
arch/x86/kernel/signal_compat.c +6 -0
@@ -34,7 +34,13 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (NSIGSYS !=2 );/* This is part of the ABI and can never change in size: */ +BUILD_BUG_ON (sizeof (siginfo_t) !=128 );BUILD_BUG_ON (sizeof (compat_siginfo_t) !=128 ); + +/* This is a part of the ABI and can never change in alignment */ +BUILD_BUG_ON (__alignof__(siginfo_t ) !=8 ); +BUILD_BUG_ON (__alignof__(compat_siginfo_t ) !=4 ); +/* * The offsets of all the (unioned) si_fields are fixed * in the ABI, of course. Make sure none of them ever
include/uapi/asm-generic/siginfo.h +5 -0
@@ -29,6 +29,11 @@ typedef union sigval {#define __ARCH_SI_ATTRIBUTES#endif +/* +* Be careful when extending this union. On 32bit siginfo_t is 32bit +* aligned. Which means that a 64bit field or any other field that +* would increase the alignment of siginfo_t will break the ABI. +*/ union __sifields { /* kill() */ struct {
Signature · 1 line
2.30.1
Re: [PATCH v3 04/12] signal: Verify the alignment and size of siginfo_t
Quoted 13 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Update the static assertions about
siginfo_tto also describe it's alignment and size.While investigating if it was possible to add a 64bit field into siginfo_t[1] it became apparent that the alignment of
siginfo_tis as much a part of the ABI as the size of the structure.If the alignment changes
siginfo_twhen embedded in another structure can move to a different offset. Which is not acceptable from an ABI structure.
Quoted 5 lines
So document that fact and add static assertions to notify developers if they change change the alignment by accident.
[1] https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 28 lines
--- arch/arm/kernel/signal.c | 2 ++ arch/arm64/kernel/signal.c | 2 ++ arch/arm64/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal32.c | 2 ++ arch/sparc/kernel/signal_64.c | 2 ++ arch/x86/kernel/signal_compat.c | 6 ++++++ include/uapi/asm-generic/siginfo.h | 5 +++++ 7 files changed, 21 insertions(+)arch/arm/kernel/signal.c +2
-0@@ -737,6 +737,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 ); +static_assert (__alignof__(siginfo_t ) ==4 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );arch/arm64/kernel/signal.c +0
-0
arch/arm64/kernel/signal.c static_assert(NSIGBUS == 5); · line 988
Quoted 4 lines
arch/arm64/kernel/signal.c +1
-0@@ -985,6 +985,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 );
Would using SI_MAX_SIZE be appropriate? Perhaps not.. in case somebody changes it, given these static asserts are meant to double-check.
I leave it to you to decide what makes more sense.
Quoted 80 lines
arch/arm64/kernel/signal.c +1
-0+static_assert (__alignof__(siginfo_t ) ==8 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );arch/arm64/kernel/signal32.c +2
-0@@ -469,6 +469,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (compat_siginfo_t) ==128 ); +static_assert (__alignof__(compat_siginfo_t ) ==4 );static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 );static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 );static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 );arch/sparc/kernel/signal32.c +2
-0@@ -757,6 +757,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (compat_siginfo_t) ==128 ); +static_assert (__alignof__(compat_siginfo_t ) ==4 );static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 );static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 );static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 );arch/sparc/kernel/signal_64.c +2
-0@@ -567,6 +567,8 @@ static_assert(NSIGBUS == 5);static_assert (NSIGTRAP ==6 );static_assert (NSIGCHLD ==6 );static_assert (NSIGSYS ==2 ); +static_assert (sizeof (siginfo_t) ==128 ); +static_assert (__alignof__(siginfo_t ) ==8 );static_assert (offsetof(siginfo_t , si_signo) ==0x00 );static_assert (offsetof(siginfo_t , si_errno) ==0x04 );static_assert (offsetof(siginfo_t , si_code) ==0x08 );arch/x86/kernel/signal_compat.c +6
-0@@ -34,7 +34,13 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (NSIGSYS !=2 );/* This is part of the ABI and can never change in size: */ +BUILD_BUG_ON (sizeof (siginfo_t) !=128 );BUILD_BUG_ON (sizeof (compat_siginfo_t) !=128 ); + +/* This is a part of the ABI and can never change in alignment */ +BUILD_BUG_ON (__alignof__(siginfo_t ) !=8 ); +BUILD_BUG_ON (__alignof__(compat_siginfo_t ) !=4 ); +/* * The offsets of all the (unioned) si_fields are fixed * in the ABI, of course. Make sure none of them ever include/uapi/asm-generic/siginfo.h +5
-1@@ -29,6 +29,11 @@ typedef union sigval {#define __ARCH_SI_ATTRIBUTES#endif +/* +* Be careful when extending this union. On 32bit siginfo_t is 32bit +* aligned. Which means that a 64bit field or any other field that +* would increase the alignment of siginfo_t will break the ABI. +*/ union __sifields { /* kill() */ struct { --2.30.1
PATCH v3 5/12 siginfo: Move si_trapno inside the union inside _si_fault
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
It turns out that linux uses si_trapno very sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.
As such move si_trapno inside the union inside of _si_fault. This results in no change in placement, and makes it eaiser
to extend _si_fault in the future as this reduces the number of special cases. In particular with si_trapno included in the union it is no longer a concern that the union must be pointer alligned on most architectures because the union followes immediately after si_addr which is a pointer.
This change results in a difference in siginfo field placement on sparc and alpha for the fields si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. These architectures do not implement the signals that would use si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. Further these architecture have not yet implemented the userspace that would use si_perf.
The point of this change is in fact to correct these placement issues before sparc or alpha grow userspace that cares. This change was discussed[1] and the agreement is that this change is currently safe.
[1]: https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com
v1: https://lkml.kernel.org/r/[email protected]
--- arch/sparc/kernel/signal32.c | 10 +++++----- arch/sparc/kernel/signal_64.c | 10 +++++----- arch/x86/kernel/signal_compat.c | 3 +++ include/linux/compat.h | 5 ++--- include/uapi/asm-generic/siginfo.h | 7 ++----- kernel/signal.c | 1 + 6 files changed, 18 insertions(+), 18 deletions(-)
arch/sparc/kernel/signal32.c +5 -5
@@ -774,10 +774,10 @@ static_assert(offsetof(compat_siginfo_t, si_int) == 0x14);static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_trapno) ==0x10 ); -static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_lower) ==0x18 ); -static_assert (offsetof(compat_siginfo_t , si_upper) ==0x1c ); -static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x18 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +5 -5
@@ -584,10 +584,10 @@ static_assert(offsetof(siginfo_t, si_int) == 0x18);static_assert (offsetof(siginfo_t , si_ptr) ==0x18 );static_assert (offsetof(siginfo_t , si_addr) ==0x10 );static_assert (offsetof(siginfo_t , si_trapno) ==0x18 ); -static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x20 ); -static_assert (offsetof(siginfo_t , si_lower) ==0x28 ); -static_assert (offsetof(siginfo_t , si_upper) ==0x30 ); -static_assert (offsetof(siginfo_t , si_pkey) ==0x28 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x20 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf) ==0x18 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
arch/x86/kernel/signal_compat.c +3 -0
@@ -133,6 +133,9 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_addr) !=0x10 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr) !=0x0C ); +BUILD_BUG_ON (offsetof(siginfo_t , si_trapno) !=0x18 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_trapno) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_addr_lsb) !=0x18 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr_lsb) !=0x10 );
include/linux/compat.h +2 -3
@@ -214,12 +214,11 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {compat_uptr_t _addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
include/uapi/asm-generic/siginfo.h +2 -5
@@ -68,9 +68,6 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {void __user *_addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #ifdef __ia64__int _imm;/* immediate value for "break" */ unsigned int _flags;/* see ia64 si_flags */
@@ -80,6 +77,8 @@ union __sifields {#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \ sizeof(short) : __alignof__(void *))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
@@ -155,9 +154,7 @@ typedef struct siginfo {#define si_int _sifields._rt._sigval.sival_int#define si_ptr _sifields._rt._sigval.sival_ptr#define si_addr _sifields._sigfault._addr -#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno -#endif #define si_addr_lsb _sifields._sigfault._addr_lsb#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper
kernel/signal.c +1 -0
@@ -4607,6 +4607,7 @@ static inline void siginfo_buildtime_checks(void)/* sigfault */ CHECK_OFFSET (si_addr); +CHECK_OFFSET (si_trapno);CHECK_OFFSET (si_addr_lsb);CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);
Signature · 1 line
2.30.1
PATCH v3 6/12 signal: Implement SIL_FAULT_TRAPNO
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that si_trapno is part of the union in _si_fault and available on all architectures, add SIL_FAULT_TRAPNO and update siginfo_layout to return SIL_FAULT_TRAPNO when si_trapno is actually used.
Update the code that uses siginfo_layout to deal with SIL_FAULT_TRAPNO and have the same code ignore si_trapno in in all other cases.
v1: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 8 +++----- include/linux/signal.h | 1 + kernel/signal.c | 37 +++++++++++++++---------------------- 3 files changed, 19 insertions(+), 27 deletions(-)
fs/signalfd.c +3 -5
@@ -123,15 +123,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :
include/linux/signal.h +1 -0
@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,
kernel/signal.c +15 -22
@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -3206,6 +3208,13 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (CONFIG_ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (CONFIG_SPARC ) && + (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR
@@ -3317,30 +3326,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
@@ -3401,30 +3402,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
Signature · 1 line
2.30.1
Re: [PATCH v3 06/12] signal: Implement SIL_FAULT_TRAPNO
Quoted 11 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Now that
si_trapnois part of the union in_si_faultand available on all architectures, addSIL_FAULT_TRAPNOand updatesiginfo_layoutto returnSIL_FAULT_TRAPNOwhensi_trapnois actually used.Update the code that uses
siginfo_layoutto deal withSIL_FAULT_TRAPNOand have the same code ignoresi_trapnoin in all other cases.v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 145 lines
--- fs/signalfd.c | 8 +++----- include/linux/signal.h | 1 + kernel/signal.c | 37 +++++++++++++++---------------------- 3 files changed, 19 insertions(+), 27 deletions(-)fs/signalfd.c +3
-5@@ -123,15 +123,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :include/linux/signal.h +1
-0@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,kernel/signal.c +15
-23@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :@@ -3206,6 +3208,13 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)if ((sig ==SIGBUS ) && (si_code >=BUS_MCEERR_AR ) && (si_code <=BUS_MCEERR_AO )) layout =SIL_FAULT_MCEERR ; +else if (IS_ENABLED (CONFIG_ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (CONFIG_SPARC ) && + (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) + layout =SIL_FAULT_TRAPNO ;else if ((sig ==SIGSEGV ) && (si_code ==SEGV_BNDERR )) layout =SIL_FAULT_BNDERR ;#ifdef SEGV_PKUERR @@ -3317,30 +3326,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :@@ -3401,30 +3402,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT : --2.30.1
PATCH v3 7/12 signal: Use dedicated helpers to send signals with si_trapno set
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that si_trapno is no longer expected to be present for every fault reported using siginfo on alpha and sparc remove the trapno parameter from force_sig_fault, force_sig_fault_to_task and send_sig_fault.
Add two new helpers force_sig_fault_trapno and send_sig_fautl_trapno for those signals where trapno is expected to be set.
v1: https://lkml.kernel.org/r/[email protected]
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 24 ++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++++++++-------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++++------------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 12 +++------ kernel/signal.c | 41 +++++++++++++++++++++-------- 14 files changed, 88 insertions(+), 77 deletions(-)
arch/alpha/kernel/osf_sys.c +1 -1
@@ -878,7 +878,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,send_sig_fault (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ -0 , current); + current); }return 0 ; }
arch/alpha/kernel/signal.c +2 -2
@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
arch/alpha/kernel/traps.c +12 -12
@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void
@@ -268,12 +268,12 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc, current);return ;
@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */
@@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }
@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a
@@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }
@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }
arch/alpha/mm/fault.c +2 -2
@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC
arch/sparc/kernel/process_64.c +1 -1
@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \
arch/sparc/kernel/sys_sparc_32.c +1 -1
@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);
arch/sparc/kernel/sys_sparc_64.c +1 -1
@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif
arch/sparc/kernel/traps_32.c +11 -11
@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */
@@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;
@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif
@@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE
arch/sparc/kernel/traps_64.c +19 -25
144 lines not on this page · raw message
arch/sparc/kernel/unaligned_32.c +1 -1
@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }
arch/sparc/mm/fault_32.c +1 -1
@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)
arch/sparc/mm/fault_64.c +1 -1
@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)
include/linux/sched/signal.h +4 -8
@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else
@@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);
@@ -327,6 +319,10 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *task); +int force_sig_ptrace_errno_trap (int errno,void __user *addr);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);
kernel/signal.c +31 -10
78 lines not on this page · raw message
Signature · 1 line
2.30.1
Re: [PATCH v3 07/12] signal: Use dedicated helpers to send signals with si_trapno set
Quoted 11 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Now that
si_trapnois no longer expected to be present for every fault reported using siginfo on alpha and sparc remove the trapno parameter fromforce_sig_fault,force_sig_fault_to_taskandsend_sig_fault.Add two new helpers
force_sig_fault_trapnoandsend_sig_fautl_trapnofor those signals where trapno is expected to be set.v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 620 lines
--- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 24 ++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++++++++-------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++++------------------ arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 12 +++------ kernel/signal.c | 41 +++++++++++++++++++++-------- 14 files changed, 88 insertions(+), 77 deletions(-)arch/alpha/kernel/osf_sys.c +1
-1@@ -878,7 +878,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,send_sig_fault (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ -0 , current); + current); }return 0 ; }arch/alpha/kernel/signal.c +2
-2@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;arch/alpha/kernel/traps.c +12
-12@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void@@ -268,12 +268,12 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc, current);return ;@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */ @@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a @@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }arch/alpha/mm/fault.c +2
-2@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC arch/sparc/kernel/process_64.c +1
-1@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \arch/sparc/kernel/sys_sparc_32.c +1
-1@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);arch/sparc/kernel/sys_sparc_64.c +1
-1@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif arch/sparc/kernel/traps_32.c +11
-11@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */ @@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif @@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE arch/sparc/kernel/traps_64.c +19
-25@@ -107,8 +107,8 @@ void bad_trap(struct pt_regs *regs, long lvl) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->tpc, lvl); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->tpc, lvl); }void bad_trap_tl1 (struct pt_regs *regs,long lvl)@@ -201,8 +201,7 @@ void spitfire_insn_access_exception(struct pt_regs *regs, unsigned long sfsr, un regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_MAPERR , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -237,7 +236,7 @@ void sun4v_insn_access_exception(struct pt_regs *regs, unsigned long addr, unsig regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *) addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *) addr); }void sun4v_insn_access_exception_tl1 (struct pt_regs *regs,unsigned long addr,unsigned long type_ctx)@@ -321,7 +320,7 @@ void spitfire_data_access_exception(struct pt_regs *regs, unsigned long sfsr, unif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)sfar,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)sfar); out:exception_exit (prev_state); }@@ -385,13 +384,13 @@ void sun4v_data_access_exception(struct pt_regs *regs, unsigned long addr, unsig*/ switch (type) {case HV_FAULT_TYPE_INV_ASI : -force_sig_fault (SIGILL ,ILL_ILLADR , (void __user *)addr,0 ); +force_sig_fault (SIGILL ,ILL_ILLADR , (void __user *)addr);break ;case HV_FAULT_TYPE_MCD_DIS : -force_sig_fault (SIGSEGV ,SEGV_ACCADI , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_ACCADI , (void __user *)addr);break ;default : -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)addr);break ; } }@@ -568,7 +567,7 @@ static void spitfire_ue_log(unsigned long afsr, unsigned long afar, unsigned lon regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGBUS ,BUS_OBJERR , (void *)0 ,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void *)0 ); }void spitfire_access_error (struct pt_regs *regs,unsigned long status_encoded,unsigned long afar)@@ -2069,8 +2068,7 @@ void do_mcd_err(struct pt_regs *regs, struct sun4v_error_entry ent)/* Send SIGSEGV to the userspace process with the right signal * code */ -force_sig_fault (SIGSEGV ,SEGV_ADIDERR , (void __user *)ent.err_raddr, -0 ); +force_sig_fault (SIGSEGV ,SEGV_ADIDERR , (void __user *)ent.err_raddr); }/* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate. @@ -2184,7 +2182,7 @@ bool sun4v_nonresum_error_user_handled(struct pt_regs *regs, }if (attrs &SUN4V_ERR_ATTRS_PIO ) {force_sig_fault (SIGBUS ,BUS_ADRERR , - (void __user *)sun4v_get_vaddr (regs),0 ); + (void __user *)sun4v_get_vaddr (regs));return true; }@@ -2340,8 +2338,7 @@ static void do_fpe_common(struct pt_regs *regs)else if (fsr &0x01 ) code =FPE_FLTRES ; } -force_sig_fault (SIGFPE , code, - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGFPE , code, (void __user *)regs->tpc); } }@@ -2395,8 +2392,7 @@ void do_tof(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGEMT ,EMT_TAGOVF , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -2415,8 +2411,7 @@ void do_div0(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGFPE ,FPE_INTDIV , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -2612,7 +2607,7 @@ void do_illegal_instruction(struct pt_regs *regs) } } } -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc); out:exception_exit (prev_state); }@@ -2632,7 +2627,7 @@ void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned loif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)sfar,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)sfar); out:exception_exit (prev_state); }@@ -2650,7 +2645,7 @@ void sun4v_do_mna(struct pt_regs *regs, unsigned long addr, unsigned long type_cif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) addr,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) addr); }/* sun4v_mem_corrupt_detect_precise() - Handle precise exception on an ADI @@ -2697,7 +2692,7 @@ void sun4v_mem_corrupt_detect_precise(struct pt_regs *regs, unsigned long addr, regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_ADIPERR , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_ADIPERR , (void __user *)addr); }void do_privop (struct pt_regs *regs)@@ -2712,8 +2707,7 @@ void do_privop(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGILL ,ILL_PRVOPC , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)regs->tpc); out:exception_exit (prev_state); }arch/sparc/kernel/unaligned_32.c +1
-1@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }arch/sparc/mm/fault_32.c +1
-1@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)arch/sparc/mm/fault_64.c +1
-1@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)include/linux/sched/signal.h +4
-8@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else @@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);@@ -327,6 +319,10 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *task); +int force_sig_ptrace_errno_trap (int errno,void __user *addr);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);kernel/signal.c +31
-11@@ -1651,7 +1651,6 @@ void force_sigsegv(int sig) } int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {@@ -1662,9 +1661,6 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;@@ -1674,16 +1670,13 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr } int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)) { return force_sig_fault_to_task(sig, code, addr - ___ARCH_SI_TRAPNO(trapno)___ARCH_SI_IA64 (imm, flags, isr), current); } int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {@@ -1694,9 +1687,6 @@ int send_sig_fault(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;@@ -1763,6 +1753,37 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +#if IS_ENABLED (CONFIG_SPARC ) +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return force_sig_info (&info); +} +#endif + +#if IS_ENABLED (CONFIG_ALPHA ) +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return send_sig_info (info.si_signo, &info, t); +} +#endif +/* For the crazy architectures that include trap information in * the errno field, instead of an actual errno value. */ --2.30.1
PATCH v3 8/12 signal: Remove __ARCH_SI_TRAPNO
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Now that this define is no longer used remove it from the kernel.
v1: https://lkml.kernel.org/r/[email protected]
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/mips/include/uapi/asm/siginfo.h | 2 -- arch/sparc/include/uapi/asm/siginfo.h | 3 --- 3 files changed, 7 deletions(-)
arch/alpha/include/uapi/asm/siginfo.h +0 -2
@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif
arch/mips/include/uapi/asm/siginfo.h +0 -2
@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFO
arch/sparc/include/uapi/asm/siginfo.h +0 -3
@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h>
Signature · 1 line
2.30.1
Re: [PATCH v3 08/12] signal: Remove __ARCH_SI_TRAPNO
Quoted 6 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Now that this define is no longer used remove it from the kernel.
v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 49 lines
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/mips/include/uapi/asm/siginfo.h | 2 -- arch/sparc/include/uapi/asm/siginfo.h | 3 --- 3 files changed, 7 deletions(-)arch/alpha/include/uapi/asm/siginfo.h +0
-2@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif arch/mips/include/uapi/asm/siginfo.h +0
-2@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFOarch/sparc/include/uapi/asm/siginfo.h +0
-4@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> --2.30.1
PATCH v3 9/12 signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
It helps to know which part of the siginfo structure the siginfo_layout value is talking about.
v1: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 2 +- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/signalfd.c +1 -1
@@ -132,7 +132,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; new.ssi_perf = kinfo->si_perf;break ;
include/linux/signal.h +1 -1
@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,
kernel/signal.c +5 -5
@@ -1198,7 +1198,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;
@@ -2553,7 +2553,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;
@@ -3243,7 +3243,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;
@@ -3365,7 +3365,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf = from->si_perf;break ;
@@ -3441,7 +3441,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf = from->si_perf;break ;
Signature · 1 line
2.30.1
Re: [PATCH v3 09/12] signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
Quoted 8 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
It helps to know which part of the siginfo structure the
siginfo_layoutvalue is talking about.v1: https://lkml.kernel.org/r/[email protected]
Acked-by Marco Elver <[email protected]>Signed-off-by Eric W. Biederman <[email protected]>
Quoted 88 lines
--- fs/signalfd.c | 2 +- include/linux/signal.h | 2 +- kernel/signal.c | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-)fs/signalfd.c +1
-1@@ -132,7 +132,7 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; new.ssi_perf = kinfo->si_perf;break ;include/linux/signal.h +1
-1@@ -44,7 +44,7 @@ enum siginfo_layout {SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR ,SIL_FAULT_PKUERR , -SIL_PERF_EVENT , +SIL_FAULT_PERF_EVENT ,SIL_CHLD ,SIL_RT , SIL_SYS,kernel/signal.c +5
-6@@ -1198,7 +1198,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT :case SIL_SYS : ret = false;break ;@@ -2553,7 +2553,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig)case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : ksig->info.si_addr =arch_untagged_si_addr ( ksig->info.si_addr, ksig->sig, ksig->info.si_code);break ;@@ -3243,7 +3243,7 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) layout =SIL_FAULT_PKUERR ;#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) - layout =SIL_PERF_EVENT ; + layout =SIL_FAULT_PERF_EVENT ; }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;@@ -3365,7 +3365,7 @@ void copy_siginfo_to_external32(struct compat_siginfo *to, to->si_addr =ptr_to_compat (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); to->si_perf = from->si_perf;break ;@@ -3441,7 +3441,7 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to, to->si_addr =compat_ptr (from->si_addr); to->si_pkey = from->si_pkey;break ; -case SIL_PERF_EVENT : +case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); to->si_perf = from->si_perf;break ; --2.30.1
--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20210505141101.11519-9-ebiederm%40xmission.com.
PATCH v3 10/12 signal: Factor force_sig_perf out of perf_sigtrap
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Separate generating the signal from deciding it needs to be sent.
v1: https://lkml.kernel.org/r/[email protected]
--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)
include/linux/sched/signal.h +1 -0
@@ -318,6 +318,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
kernel/events/core.c +2 -9
@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
@@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)
kernel/signal.c +13 -0
@@ -1753,6 +1753,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *addr,u32 type,u64 sig_data) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +#if IS_ENABLED (CONFIG_SPARC )int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) {
Signature · 1 line
2.30.1
Re: [PATCH v3 10/12] signal: Factor force_sig_perf out of perf_sigtrap
Quoted 6 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Separate generating the signal from deciding it needs to be sent.
v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 74 lines
--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)include/linux/sched/signal.h +1
-0@@ -318,6 +318,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,kernel/events/core.c +2
-9@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the @@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)kernel/signal.c +13
-1@@ -1753,6 +1753,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *addr,u32 type,u64 sig_data) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +#if IS_ENABLED (CONFIG_SPARC )int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) { --2.30.1
Re: [PATCH v3 10/12] signal: Factor force_sig_perf out of perf_sigtrap
In reply to Eric W. BeidermanQuoted 6 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Separate generating the signal from deciding it needs to be sent.
v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Thanks for cleaning all that up.
PATCH v3 11/12 signal: Deliver all of the siginfo perf data in _perf
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Don't abuse si_errno and deliver all of the perf data in _perf member of siginfo_t.
The data field in the perf data structures in a u64 to allow a pointer to be encoded without needed to implement a 32bit and 64bit version of the same structure. There already exists a 32bit and 64bit versions siginfo_t, and the 32bit version can not include a 64bit member as it only has 32bit alignment. So unsigned long is used in siginfo_t instead of a u64 as unsigned long can encode a pointer on all architectures linux supports.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 3 ++- arch/arm64/kernel/signal.c | 3 ++- arch/arm64/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal_64.c | 3 ++- arch/x86/kernel/signal_compat.c | 6 ++++-- fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 8 +++++-- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 21 ++++++++++++------- .../selftests/perf_events/sigtrap_threads.c | 12 +++++------ 12 files changed, 47 insertions(+), 27 deletions(-)
arch/arm/kernel/signal.c +2 -1
@@ -757,7 +757,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(siginfo_t , si_lower) ==0x14 );static_assert (offsetof(siginfo_t , si_upper) ==0x18 );static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(siginfo_t , si_band) ==0x0c );static_assert (offsetof(siginfo_t , si_fd) ==0x10 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c );
arch/arm64/kernel/signal.c +2 -1
@@ -1005,7 +1005,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x18 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 );
arch/arm64/kernel/signal32.c +2 -1
@@ -489,7 +489,8 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c );
arch/sparc/kernel/signal32.c +2 -1
@@ -778,6 +778,7 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +2 -1
@@ -588,6 +588,7 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
arch/x86/kernel/signal_compat.c +4 -2
@@ -147,8 +147,10 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x20 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_pkey) !=0x14 ); -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x18 ); -BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x18 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x20 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_type) !=0x14 );CHECK_CSI_OFFSET (_sigpoll);CHECK_CSI_SIZE (_sigpoll,2 *sizeof (int ));
fs/signalfd.c +2 -1
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf_type; + new.ssi_perf_data = kinfo->si_perf_data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;
include/linux/compat.h +4 -1
@@ -236,7 +236,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t _data; +u32 _type; + } _perf; }; } _sigfault;
include/uapi/asm-generic/siginfo.h +6 -2
@@ -96,7 +96,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long _data; +__u32 _type; + } _perf; }; } _sigfault;
@@ -159,7 +162,8 @@ typedef struct siginfo {#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper#define si_pkey _sifields._sigfault._addr_pkey._pkey -#define si_perf _sifields._sigfault._perf +#define si_perf_data _sifields._sigfault._perf._data +#define si_perf_type _sifields._sigfault._perf._type#define si_band _sifields._sigpoll._band#define si_fd _sifields._sigpoll._fd#define si_call_addr _sifields._sigsys._call_addr
include/uapi/linux/signalfd.h +2 -2
@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
kernel/signal.c +13 -8
@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf_data = sig_data; + info.si_perf_type = type; +return force_sig_info (&info); }
@@ -3380,7 +3382,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -3456,7 +3459,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -4639,7 +4643,8 @@ static inline void siginfo_buildtime_checks(void)CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);CHECK_OFFSET (si_pkey); -CHECK_OFFSET (si_perf); +CHECK_OFFSET (si_perf_data); +CHECK_OFFSET (si_perf_type);/* sigpoll */ CHECK_OFFSET (si_band);
tools/testing/selftests/perf_events/sigtrap_threads.c +6 -6
@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)EXPECT_EQ (ctx.signal_count,NUM_THREADS * ctx.iterate_on);EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on)); }TEST_HARNESS_MAIN
Signature · 1 line
2.30.1
Re: [PATCH v3 11/12] signal: Deliver all of the siginfo perf data in _perf
Quoted 5 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
Don't abuse
si_errnoand deliver all of the perf data in_perfmember ofsiginfo_t.
Quoted 7 lines
The data field in the perf data structures in a u64 to allow a pointer to be encoded without needed to implement a 32bit and 64bit version of the same structure. There already exists a 32bit and 64bit versions
siginfo_t, and the 32bit version can not include a 64bit member as it only has 32bit alignment. So unsigned long is used insiginfo_tinstead of a u64 as unsigned long can encode a pointer on all architectures linux supports.
Since there is no functional change (we already had the unsigned long here), the explanation made me think there was a change in that area (but there wasn't). (Can leave as-is, but a "Note: " or similar if you deem it appropriate.)
Quoted 3 lines
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]Signed-off-by "Eric W. Biederman" <[email protected]>
Thank you!
Quoted 264 lines
--- arch/arm/kernel/signal.c | 3 ++- arch/arm64/kernel/signal.c | 3 ++- arch/arm64/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal32.c | 3 ++- arch/sparc/kernel/signal_64.c | 3 ++- arch/x86/kernel/signal_compat.c | 6 ++++-- fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 8 +++++-- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 21 ++++++++++++------- .../selftests/perf_events/sigtrap_threads.c | 12 +++++------ 12 files changed, 47 insertions(+), 27 deletions(-)arch/arm/kernel/signal.c +2
-1@@ -757,7 +757,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(siginfo_t , si_lower) ==0x14 );static_assert (offsetof(siginfo_t , si_upper) ==0x18 );static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(siginfo_t , si_band) ==0x0c );static_assert (offsetof(siginfo_t , si_fd) ==0x10 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c );arch/arm64/kernel/signal.c +2
-1@@ -1005,7 +1005,8 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x18 );static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 );arch/arm64/kernel/signal32.c +2
-1@@ -489,7 +489,8 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c );arch/sparc/kernel/signal32.c +2
-1@@ -778,6 +778,7 @@ static_assert(offsetof(compat_siginfo_t, si_addr_lsb) == 0x10);static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 );static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); -static_assert (offsetof(compat_siginfo_t , si_perf) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 );static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c );static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );arch/sparc/kernel/signal_64.c +2
-1@@ -588,6 +588,7 @@ static_assert(offsetof(siginfo_t, si_addr_lsb) == 0x18);static_assert (offsetof(siginfo_t , si_lower) ==0x20 );static_assert (offsetof(siginfo_t , si_upper) ==0x28 );static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); -static_assert (offsetof(siginfo_t , si_perf) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 );static_assert (offsetof(siginfo_t , si_band) ==0x10 );static_assert (offsetof(siginfo_t , si_fd) ==0x14 );arch/x86/kernel/signal_compat.c +4
-2@@ -147,8 +147,10 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x20 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_pkey) !=0x14 ); -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x18 ); -BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x18 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x20 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_type) !=0x14 );CHECK_CSI_OFFSET (_sigpoll);CHECK_CSI_SIZE (_sigpoll,2 *sizeof (int ));fs/signalfd.c +2
-1@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf_type; + new.ssi_perf_data = kinfo->si_perf_data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;include/linux/compat.h +4
-1@@ -236,7 +236,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t _data; +u32 _type; + } _perf; }; } _sigfault;include/uapi/asm-generic/siginfo.h +6
-2@@ -96,7 +96,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long _data; +__u32 _type; + } _perf; }; } _sigfault;@@ -159,7 +162,8 @@ typedef struct siginfo {#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper#define si_pkey _sifields._sigfault._addr_pkey._pkey -#define si_perf _sifields._sigfault._perf +#define si_perf_data _sifields._sigfault._perf._data +#define si_perf_type _sifields._sigfault._perf._type#define si_band _sifields._sigpoll._band#define si_fd _sifields._sigpoll._fd#define si_call_addr _sifields._sigsys._call_addrinclude/uapi/linux/signalfd.h +2
-2@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the kernel/signal.c +13
-8@@ -1758,11 +1758,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf_data = sig_data; + info.si_perf_type = type; +return force_sig_info (&info); }@@ -3380,7 +3382,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;@@ -3456,7 +3459,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;@@ -4639,7 +4643,8 @@ static inline void siginfo_buildtime_checks(void)CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);CHECK_OFFSET (si_pkey); -CHECK_OFFSET (si_perf); +CHECK_OFFSET (si_perf_data); +CHECK_OFFSET (si_perf_type);/* sigpoll */ CHECK_OFFSET (si_band);tools/testing/selftests/perf_events/sigtrap_threads.c +6
-7@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)EXPECT_EQ (ctx.signal_count,NUM_THREADS * ctx.iterate_on);EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on)); }TEST_HARNESS_MAIN --2.30.1
PATCH v3 12/12 signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
With the addition of ssi_perf_data and ssi_perf_type struct signalfd_siginfo is dangerously close to running out of space. All that remains is just enough space for two additional 64bit fields. A practice of adding all possible siginfo_t fields into struct singalfd_siginfo can not be supported as adding the missing fields ssi_lower, ssi_upper, and ssi_pkey would require two 64bit fields and one 32bit fields. In practice the fields ssi_perf_data and ssi_perf_type can never be used by signalfd as the signal that generates them always delivers them synchronously to the thread that triggers them.
Therefore until someone actually needs the fields ssi_perf_data and ssi_perf_type in signalfd_siginfo remove them. This leaves a bit more room for future expansion.
v1: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 16 ++++++---------- include/uapi/linux/signalfd.h | 4 +--- 2 files changed, 7 insertions(+), 13 deletions(-)
fs/signalfd.c +6 -10
@@ -114,12 +114,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : +case SIL_FAULT_PERF_EVENT :/* -* Fall through to the SIL_FAULT case. Both SIL_FAULT_BNDERR -* and SIL_FAULT_PKUERR are only generated by faults that -* deliver them synchronously to userspace. In case someone -* injects one of these signals and signalfd catches it treat -* it as SIL_FAULT. +* Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR, +* SIL_FAULT_PKUERR, and SIL_FAULT_PERF_EVENT are only +* generated by faults that deliver them synchronously to +* userspace. In case someone injects one of these signals +* and signalfd catches it treat it as SIL_FAULT. */ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr;
@@ -132,11 +133,6 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_FAULT_PERF_EVENT : - new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf_type = kinfo->si_perf_type; - new.ssi_perf_data = kinfo->si_perf_data; -break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid;
include/uapi/linux/signalfd.h +1 -3
@@ -39,8 +39,6 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 ssi_perf_type; -__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
@@ -51,7 +49,7 @@ struct signalfd_siginfo {* comes out of a read(2) and we really don't want to have * a compat on read(2). */ -__u8 __pad[16 ]; +__u8 __pad[28 ]; };
Signature · 1 line
2.30.1
Re: [PATCH v3 12/12] signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
Quoted 12 lines · Eric W. Beiderman
From: "Eric W. Biederman" <[email protected]>
With the addition of
ssi_perf_dataandssi_perf_typestructsignalfd_siginfois dangerously close to running out of space. All that remains is just enough space for two additional 64bit fields. A practice of adding all possiblesiginfo_tfields into structsingalfd_siginfocan not be supported as adding the missing fieldsssi_lower,ssi_upper, andssi_pkeywould require two 64bit fields and one 32bit fields. In practice the fieldsssi_perf_dataandssi_perf_typecan never be used by signalfd as the signal that generates them always delivers them synchronously to the thread that triggers them.
Quoted 6 lines
Therefore until someone actually needs the fields
ssi_perf_dataandssi_perf_typeinsignalfd_siginforemove them. This leaves a bit more room for future expansion.v1: https://lkml.kernel.org/r/[email protected]
Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 64 lines
--- fs/signalfd.c | 16 ++++++---------- include/uapi/linux/signalfd.h | 4 +--- 2 files changed, 7 insertions(+), 13 deletions(-)fs/signalfd.c +6
-10@@ -114,12 +114,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : +case SIL_FAULT_PERF_EVENT :/* -* Fall through to the SIL_FAULT case. Both SIL_FAULT_BNDERR -* and SIL_FAULT_PKUERR are only generated by faults that -* deliver them synchronously to userspace. In case someone -* injects one of these signals and signalfd catches it treat -* it as SIL_FAULT. +* Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR, +* SIL_FAULT_PKUERR, and SIL_FAULT_PERF_EVENT are only +* generated by faults that deliver them synchronously to +* userspace. In case someone injects one of these signals +* and signalfd catches it treat it as SIL_FAULT. */ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr;@@ -132,11 +133,6 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_FAULT_PERF_EVENT : - new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf_type = kinfo->si_perf_type; - new.ssi_perf_data = kinfo->si_perf_data; -break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid;include/uapi/linux/signalfd.h +1
-4@@ -39,8 +39,6 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 ssi_perf_type; -__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the @@ -51,7 +49,7 @@ struct signalfd_siginfo {* comes out of a read(2) and we really don't want to have * a compat on read(2). */ -__u8 __pad[16 ]; +__u8 __pad[28 ]; }; --2.30.1
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
In reply to Eric W. BiedermanQuoted 67 lines · Eric W. Biederman
This set of changes sorts out the ABI issues with SIGTRAP
TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
-si_trapnobecomming ordinary fault subfield.
- structsignalfd_siginfois almost fullThis set of changes starts out with Marco's
static_assertchanges and additional one of my own that enforces the fact that the alignment ofsiginfo_tis also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.The field
si_trapnois changed to become an ordinary extension of the_sigfaultmember of siginfo.The code is refactored a bit and then
si_perf_typeis added along sidesi_perf_datain the_perfsubfield of_sigfaultofsiginfo_t.Finally the
signalfd_siginfofields are removed as they appear to be filling up the structure without userspace actually being able to use them.v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]Eric W. Biederman (9):
signal: Verify the alignment and size ofsiginfo_t
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals withsi_trapnoset
signal: Remove__ARCH_SI_TRAPNO
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistency
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_FAULT_PERF_EVENTfields fromsignalfd_siginfoMarco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsetsarch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal32.c | 39 +++++++ arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 37 +++++++ arch/sparc/kernel/signal_64.c | 36 +++++++ arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 15 ++- fs/signalfd.c | 23 ++--- include/linux/compat.h | 10 +-
Quoted 8 lines
include/linux/sched/signal.h | 13 +-- include/linux/signal.h | 3 +- include/uapi/asm-generic/siginfo.h | 20 ++-- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +- kernel/signal.c | 113 +++++++++++++-------- .../selftests/perf_events/sigtrap_threads.c | 12 +-- 30 files changed, 373 insertions(+), 160 deletions(-)
Looks good, thanks a lot! I ran selftests/perf_events on x86-64, and build-tested x86-32, arm, arm64, sparc, alpha.
I added my Reviewed/Acked-by to the various patches.
Thanks,
-- Marco
Geert Uytterhoeven
maintainerRe: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
In reply to Eric W. BiedermanHi Eric,
Quoted 18 lines · Eric W. Biederman
This set of changes sorts out the ABI issues with SIGTRAP
TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
-si_trapnobecomming ordinary fault subfield.
- structsignalfd_siginfois almost fullThis set of changes starts out with Marco's
static_assertchanges and additional one of my own that enforces the fact that the alignment ofsiginfo_tis also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.The field
si_trapnois changed to become an ordinary extension of the_sigfaultmember of siginfo.
Quoted 6 lines
The code is refactored a bit and then
si_perf_typeis added along sidesi_perf_datain the_perfsubfield of_sigfaultofsiginfo_t.Finally the
signalfd_siginfofields are removed as they appear to be filling up the structure without userspace actually being able to use them.
Thanks for your series, which is now in next-20210506.
Quoted 13 lines
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal32.c | 39 +++++++ arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 37 +++++++ arch/sparc/kernel/signal_64.c | 36 +++++++
Quoted 8 lines
arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 15 ++-
No changes needed for other architectures?
All m68k configs are broken with
arch/m68k/kernel/signal.c:626:35: error: 'siginfo_t' {aka 'struct siginfo'} has no member named 'si_perf'; did you mean 'si_errno'?
See e.g. http://kisskb.ellerman.id.au/kisskb/buildresult/14537820/
There are still a few more references left to si_perf:
$ git grep -n -w si_perf Next/merge.log:2902:Merging userns/for-next (4cf4e48fff05 signal: sort out si_trapno and si_perf) arch/m68k/kernel/signal.c:626: BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10); include/uapi/linux/perf_event.h:467: * siginfo_t::si_perf, e.g. to permit user to identify the event. tools/testing/selftests/perf_events/sigtrap_threads.c:46:/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
On Thu, May 06, 2021 at 09:00AM +0200, Geert Uytterhoeven wrote:
[...]
Quoted 10 lines
No changes needed for other architectures?
All m68k configs are broken with
arch/m68k/kernel/signal.c:626:35: error: 'siginfo_t' {aka 'struct siginfo'} has no member named 'si_perf'; did you mean 'si_errno'?See e.g. http://kisskb.ellerman.id.au/kisskb/buildresult/14537820/
There are still a few more references left to
si_perf:
Quoted 10 lines
$ git grep -n -w si_perf Next/merge.log:2902:Merging userns/for-next (4cf4e48fff05 signal: sort out si_trapno and si_perf) arch/m68k/kernel/signal.c:626: BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10); include/uapi/linux/perf_event.h:467: * siginfo_t::si_perf, e.g. to permit user to identify the event. tools/testing/selftests/perf_events/sigtrap_threads.c:46:/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */
I think we're missing the below in "signal: Deliver all of the siginfo perf data in _perf".
Thanks,
-- Marco
------ >8 ------
arch/m68k/kernel/signal.c +2 -1
@@ -623,7 +623,8 @@ static inline void siginfo_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x12 );/* _sigfault._perf */ -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x14 );/* _sigpoll */ BUILD_BUG_ON (offsetof(siginfo_t , si_band) !=0x0c );
include/uapi/linux/perf_event.h +1 -1
@@ -464,7 +464,7 @@ struct perf_event_attr {/* * User provided data if sigtrap=1, passed back to user via -* siginfo_t::si_perf, e.g. to permit user to identify the event. +* siginfo_t::si_perf_data, e.g. to permit user to identify the event. */ __u64 sig_data; };
tools/testing/selftests/perf_events/sigtrap_threads.c +1 -1
@@ -43,7 +43,7 @@ static struct {siginfo_t first_siginfo;/* First observed siginfo_t. */ } ctx; -/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */ +/* Unique value to check si_perf_data is correctly set from perf_event_attr::sig_data. */ #define TEST_SIG_DATA (addr) (~(unsigned long)(addr))static struct perf_event_attr make_event_attr (bool enabled,volatile void *addr)
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
For the moment I am adding this to my for-next branch. I plan to respin and fold this in but I am not certain what my schedule looks like today. So I figure making certain I have a fix out (so I stop breaking m68k) is more important than having a perfect patch.
Eric
From: "Eric W. Biederman" <[email protected]>
Date: Thu, 6 May 2021 10:17:10 -0500
Subject: [PATCH] signal: Remove the last few si_perf references
I accidentially overlooked a few references to si_perf when sorting out the ABI update those references now.
--- arch/m68k/kernel/signal.c | 3 ++- include/uapi/linux/perf_event.h | 2 +- tools/testing/selftests/perf_events/sigtrap_threads.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
arch/m68k/kernel/signal.c +2 -1
@@ -623,7 +623,8 @@ static inline void siginfo_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x12 );/* _sigfault._perf */ -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x14 );/* _sigpoll */ BUILD_BUG_ON (offsetof(siginfo_t , si_band) !=0x0c );
include/uapi/linux/perf_event.h +1 -1
@@ -464,7 +464,7 @@ struct perf_event_attr {/* * User provided data if sigtrap=1, passed back to user via -* siginfo_t::si_perf, e.g. to permit user to identify the event. +* siginfo_t::si_perf_data, e.g. to permit user to identify the event. */ __u64 sig_data; };
tools/testing/selftests/perf_events/sigtrap_threads.c +1 -1
@@ -43,7 +43,7 @@ static struct {siginfo_t first_siginfo;/* First observed siginfo_t. */ } ctx; -/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */ +/* Unique value to check si_perf_data is correctly set from perf_event_attr::sig_data. */ #define TEST_SIG_DATA (addr) (~(unsigned long)(addr))static struct perf_event_attr make_event_attr (bool enabled,volatile void *addr)
Signature · 1 line
2.30.1
Re: [PATCH v3 00/12] signal: sort out si_trapno and si_perf
In reply to Geert UytterhoevenQuoted 52 lines · Geert Uytterhoeven
Hi Eric,
Quoted 18 lines · Eric W. Biederman
This set of changes sorts out the ABI issues with SIGTRAP
TRAP_PERF, and hopefully will can get merged before any userspace code starts using the new ABI.The big ideas are:
- Placing the asserts first to prevent unexpected ABI changes
-si_trapnobecomming ordinary fault subfield.
- structsignalfd_siginfois almost fullThis set of changes starts out with Marco's
static_assertchanges and additional one of my own that enforces the fact that the alignment ofsiginfo_tis also part of the ABI. Together these build time checks verify there are no unexpected ABI changes in the changes that follow.The field
si_trapnois changed to become an ordinary extension of the_sigfaultmember of siginfo.Quoted 6 lines
The code is refactored a bit and then
si_perf_typeis added along sidesi_perf_datain the_perfsubfield of_sigfaultofsiginfo_t.Finally the
signalfd_siginfofields are removed as they appear to be filling up the structure without userspace actually being able to use them.Thanks for your series, which is now in next-20210506.
Quoted 13 lines
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal32.c | 39 +++++++ arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 37 +++++++ arch/sparc/kernel/signal_64.c | 36 +++++++Quoted 8 lines
arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 15 ++-
Quoted 2 lines
No changes needed for other architectures?
All m68k configs are broken with
Thanks. I hadn't realized that si_perf asserts existed on m68k. Thankfully linux-next caught this these.
Looking a little more deeply, it is strange that this is tested on m68k. The architecture does not implement HAVE_PERF_EVENTS so it is impossible for this signal to be generated.
On the off chance this these new signals will appear on m68k someday I will update the assertion.
Quoted 7 lines
arch/m68k/kernel/signal.c:626:35: error: 'siginfo_t' {aka 'struct siginfo'} has no member named 'si_perf'; did you mean 'si_errno'?See e.g. http://kisskb.ellerman.id.au/kisskb/buildresult/14537820/
There are still a few more references left to
si_perf:
Quoted 10 lines
$ git grep -n -w si_perf Next/merge.log:2902:Merging userns/for-next (4cf4e48fff05 signal: sort out si_trapno and si_perf) arch/m68k/kernel/signal.c:626: BUILD_BUG_ON(offsetof(siginfo_t, si_perf) != 0x10); include/uapi/linux/perf_event.h:467: * siginfo_t::si_perf, e.g. to permit user to identify the event. tools/testing/selftests/perf_events/sigtrap_threads.c:46:/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */
I will sweep them up as well.
Eric
[GIT PULL] siginfo: ABI fixes for v5.13-rc2
In reply to Eric W. BiedermanLinus,
Please pull the for-v5.13-rc2 branch from the git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git for-v5.13-rc2
HEAD: addd6821190ebf1e9fece0b7848db667fd280e2e signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
During the merge window an issue with si_perf and the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAP TRAP_PERF and the new field si_perf.
The reason only alpha and sparc were affected is that they are the only architectures that use si_trapno.
Looking deeper it was discovered that si_trapno is used for only a few select signals on alpha and sparc, and that none of the other _sigfault fields past si_addr are used at all. Which means technically no regression on alpha and sparc.
While the alignment concerns might be dismissed the abuse of si_errno by SIGTRAP TRAP_PERF does have the potential to cause regressions in existing userspace.
While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP TRAP_PERF this set of changes cleans up siginfo_t.
- The si_trapno field is demoted from magic alpha and sparc status and made an ordinary union member of the _sigfault member of siginfo_t. Without moving it of course.
- si_perf is replaced with si_perf_data and si_perf_type ending the abuse of si_errno.
- BUILD_BUG_ONs are added and various helpers are modified to accommodate this change.
- Unnecessary additions to signalfd_siginfo are removed.
v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
You might notice a recent rebase. This code has been sitting in linux-next as ef566ba2d7d9 ("signal: Remove the last few si_perf references"). Which results in the exact same code as the branch I am sending you but the commits differ to keep git bisect working.
The difference is that I squashed a fix for a mips BUILD_BUG_ON about si_perf into the commit that replaces si_perf with si_perf_data and si_perf_type. This keeps the kernel building on all architectures for all commits keeping git-bisect working for everyone.
Eric W. Biederman (9):
signal: Verify the alignment and size of siginfo_t
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Use dedicated helpers to send signals with si_trapno set
signal: Remove __ARCH_SI_TRAPNO
signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
signal: Factor force_sig_perf out of perf_sigtrap
signal: Deliver all of the siginfo perf data in _perf
signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
Marco Elver (3):
sparc64: Add compile-time asserts for siginfo_t offsets
arm: Add compile-time asserts for siginfo_t offsets
arm64: Add compile-time asserts for siginfo_t offsets
arch/alpha/include/uapi/asm/siginfo.h | 2 - arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +- arch/alpha/kernel/traps.c | 24 ++--- arch/alpha/mm/fault.c | 4 +- arch/arm/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal.c | 39 +++++++ arch/arm64/kernel/signal32.c | 39 +++++++ arch/m68k/kernel/signal.c | 3 +- arch/mips/include/uapi/asm/siginfo.h | 2 - arch/sparc/include/uapi/asm/siginfo.h | 3 - arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 37 +++++++ arch/sparc/kernel/signal_64.c | 36 +++++++ arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 ++-- arch/sparc/kernel/traps_64.c | 44 ++++---- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- arch/x86/kernel/signal_compat.c | 15 ++- fs/signalfd.c | 23 ++--- include/linux/compat.h | 10 +- include/linux/sched/signal.h | 13 +-- include/linux/signal.h | 3 +- include/uapi/asm-generic/siginfo.h | 20 ++-- include/uapi/linux/perf_event.h | 2 +- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +- kernel/signal.c | 113 +++++++++++++-------- .../selftests/perf_events/sigtrap_threads.c | 14 +-- 32 files changed, 377 insertions(+), 163 deletions(-)
Eric
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc2
Quoted 2 lines · Eric W. Biederman
Please pull the for-v5.13-rc2 branch from the git tree:
I really don't like this tree.
The immediate cause for "no" is the silly
#if IS_ENABLED(CONFIG_SPARC)
and
#if IS_ENABLED(CONFIG_ALPHA)
code in kernel/signal.c. It has absolutely zero business being there, when those architectures have a perfectly fine arch/*/kernel/signal.c file where that code would make much more sense *WITHOUT* any odd preprocessor games.
But there are other oddities too, like the new
send_sig_fault_trapno(SIGFPE, si_code, (void __user *) regs->pc,
0, current);
in the alpha code, which fundamentally seems bogus: using send_sig_fault_trapno() with a '0' for trapno seems entirely incorrect, since the *ONLY* point of that function is to set si_trapno to something non-zero.
So it would seem that a plain send_sig_fault() without that 0 would be the right thing to do.
This also mixes in a lot of other stuff than just the fixes. Which would have been ok during the merge window, but I'm definitely not happy about it now.
Linus
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc2
Quoted 10 lines · Linus Torvalds
Quoted 2 lines · Eric W. Biederman
Please pull the for-v5.13-rc2 branch from the git tree:
I really don't like this tree.
The immediate cause for "no" is the silly
#if
IS_ENABLED(CONFIG_SPARC)
Quoted 8 lines
and
#if
IS_ENABLED(CONFIG_ALPHA)code in
kernel/signal.c. It has absolutely zero business being there, when those architectures have a perfectly finearch/*/kernel/signal.cfile where that code would make much more sense *WITHOUT* any odd preprocessor games.
The code is generic it just happens those functions are only used on sparc and alpha. Further I really want to make filling out siginfo_t happen in dedicated functions as much as possible in kernel/signal.c. The probably of getting it wrong without a helper functions is very strong. As the code I am fixing demonstrates.
The IS_ENABLED(arch) is mostly there so we can delete the code if/when the architectures are retired in another decade or so.
Quoted 5 lines
But there are other oddities too, like the new
send_sig_fault_trapno(SIGFPE, si_code, (void __user *) regs->pc,0, current);
Quoted 7 lines
in the alpha code, which fundamentally seems bogus: using
send_sig_fault_trapno()with a '0' for trapno seems entirely incorrect, since the *ONLY* point of that function is to setsi_trapnoto something non-zero.So it would seem that a plain
send_sig_fault()without that 0 would be the right thing to do.
As it happens the floating point emulation code on alpha is inconsistent with the non floating point emulation code. When using real floating point hardware SIGFPE on alpha always set si_trapno. The floating point emulation code does not look like it has ever set si_trapno.
I continued to used send_sig_fault_trapno to point out that inconsistency.
If alpha floating point emulation was in active use I expect we would care enough to put something other than 0 in there.
Quoted 3 lines
This also mixes in a lot of other stuff than just the fixes. Which would have been ok during the merge window, but I'm definitely not happy about it now.
If the breakage that came with SIGTRAP TRAP_PERF had not been discovered during the merge window I would not be sending this now. It took a little time to dig to the bottom, then the code needed just a little extra time to sit, so there were not surprises.
As for mixing things, I am not quite certain what you are referring to. All of the changes relate to keeping people from shooting themselves in the foot with when using siginfo.
The most noise comes from send_sig_fault vs send_sig_fault_trapno, and force_sig_fault vs force_sig_fault_trapno. That is fundamental to the siginfo fix as it is there to ensure that is safe to treat si_trapno as an ordinary _sigfault union member. Which in turns makes alpha and sparc no longer special with respect to _sigfault, just a little eccentric.
I will concede that renaming SIL_PERF_EVENT to SIL_FAULT_PERF_EVENT is unnecessary, but it certainly makes it clear that we are dealing with _sigfault and not some other part of siginfo_t.
Eric
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc2
Quoted 21 lines · [email protected] (Eric W. Biederman) writes:
Quoted 10 lines · Linus Torvalds
Quoted 2 lines · Eric W. Biederman
Please pull the for-v5.13-rc2 branch from the git tree:
I really don't like this tree.
The immediate cause for "no" is the silly
#if
IS_ENABLED(CONFIG_SPARC)Quoted 8 lines
and
#if
IS_ENABLED(CONFIG_ALPHA)code in
kernel/signal.c. It has absolutely zero business being there, when those architectures have a perfectly finearch/*/kernel/signal.cfile where that code would make much more sense *WITHOUT* any odd preprocessor games.
Quoted 8 lines
The code is generic it just happens those functions are only used on sparc and alpha. Further I really want to make filling out
siginfo_thappen in dedicated functions as much as possible inkernel/signal.c. The probably of getting it wrong without a helper functions is very strong. As the code I am fixing demonstrates.The
IS_ENABLED(arch)is mostly there so we can delete the code if/when the architectures are retired in another decade or so.
There is also the question of why alpha allows userspace to block SIGFPE.
If it turns out that alpha is just silly by allowing synchronous exceptions to be blocked, then the code really becomes generic and shared shared between sparc and alpha.
Which is really why the code does not make sense in some architecture specific version of signal.c. That and the fact the two functions are almost identical.
If you want I can remove the #ifdefs and we can take up slightly more space until someone implements -ffunction-sections.
Do you know if alpha will be stuck triggering the same floating point error if the SIGFPE is blocked or can alpha somehow continue past it?
If alpha using send_sig instead of force_sig is historical and does not reflect the reality of the hardware alpha can be converted and several of the send_sig variants can be removed. Otherwise alpha remains the odd man out, and the code can remain until all of the alpha hardware dies. (I don't think anyone is manufacturing alpha hardware anymore).
I would look it up but I have lost access to whatever alpha documentation I had.
Eric
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc2
In reply to Eric W. BiedermanQuoted 4 lines · Eric W. Biederman
Looking deeper it was discovered that
si_trapnois used for only a few select signals on alpha and sparc, and that none of the other_sigfaultfields pastsi_addrare used at all. Which means technically no regression on alpha and sparc.
If there's no functional regression on any platform, could much of this wait until v5.14, or do we want some of these cleanups right now?
The fixes seem to be for long-existing bugs, not fresh regressions, AFAICS. The asserts & cleanups are useful, but not regression fixes.
I.e. this is a bit scary:
Quoted 1 line
32 files changed, 377 insertions(+), 163 deletions(-)
at -rc2 time.
Thanks,
Ingo
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc2
Quoted 7 lines · Ingo Molnar
Quoted 4 lines · Eric W. Biederman
Looking deeper it was discovered that
si_trapnois used for only a few select signals on alpha and sparc, and that none of the other_sigfaultfields pastsi_addrare used at all. Which means technically no regression on alpha and sparc.
Quoted 7 lines
If there's no functional regression on any platform, could much of this wait until v5.14, or do we want some of these cleanups right now?
The fixes seem to be for long-existing bugs, not fresh regressions, AFAICS. The asserts & cleanups are useful, but not regression fixes.
I.e. this is a bit scary:
The new ABI for SIGTRAP TRAP perf that came in the merge window is broken and wrong. We need to revert/disable the new SIGTRAP TRAP_PERF or have a fix before v5.13.
The issue is old crap getting in the way of a new addition. I think I might see a smaller code change on how to get to something compatible with this.
Quoted 3 lines
Quoted 1 line
32 files changed, 377 insertions(+), 163 deletions(-)at -rc2 time.
The additions are all tests to make certain everything is fine. The actual code change without the assertions (tests) is essentially a wash.
Eric
Eric W. Biederman
Tested-by Marco Elver[GIT PULL] siginfo: ABI fixes for v5.13-rc3
In reply to Eric W. BiedermanLinus,
Please pull the for-v5.13-rc3 branch from the git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git for-v5.13-rc3
HEAD: 922e3013046b79b444c87eda5baf43afae1326a8 signalfd: Remove SIL_FAULT_PERF_EVENT fields from signalfd_siginfo
During the merge window an issue with si_perf and the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAP TRAP_PERF and the new field si_perf.
The reason only alpha and sparc were affected is that they are the only architectures that use si_trapno.
Looking deeper it was discovered that si_trapno is used for only a few select signals on alpha and sparc, and that none of the other _sigfault fields past si_addr are used at all. Which means technically no regression on alpha and sparc.
While the alignment concerns might be dismissed the abuse of si_errno by SIGTRAP TRAP_PERF does have the potential to cause regressions in existing userspace.
While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP TRAP_PERF this set of changes cleans up siginfo_t.
- The si_trapno field is demoted from magic alpha and sparc status and made an ordinary union member of the _sigfault member of siginfo_t. Without moving it of course.
- si_perf is replaced with si_perf_data and si_perf_type ending the abuse of si_errno.
- Unnecessary additions to signalfd_siginfo are removed.
v4: https://lkml.kernel.org/r/[email protected]
v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
This version drops the tests and fine grained handling of si_trapno on alpha and sparc (replaced assuming si_trapno is valid for all but the faults that defined different data).
Hopefully this is enough to not be scary as a fix for the ABI issues.
Eric W. Biederman (5):
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Factor force_sig_perf out of perf_sigtrap
signal: Deliver all of the siginfo perf data in _perf
signalfd: Remove SIL_PERF_EVENT fields from signalfd_siginfo
arch/m68k/kernel/signal.c | 3 +- arch/x86/kernel/signal_compat.c | 9 +++- fs/signalfd.c | 23 ++++----- include/linux/compat.h | 10 ++-- include/linux/sched/signal.h | 1 + include/linux/signal.h | 1 + include/uapi/asm-generic/siginfo.h | 15 +++--- include/uapi/linux/perf_event.h | 2 +- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +--- kernel/signal.c | 59 +++++++++++++--------- .../selftests/perf_events/sigtrap_threads.c | 14 ++--- 12 files changed, 79 insertions(+), 73 deletions(-)
Eric
Re: [GIT PULL] siginfo: ABI fixes for v5.13-rc3
The pull request you sent on Fri, 21 May 2021 09:59:53 -0500:
The pull request you sent on Fri, 21 May 2021 09:59:53 -0500:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.gitfor-v5.13-rc3
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/a0e31f3a38e77612ed8967aaad28db6d3ee674b5
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
v4 cover siginfo: ABI fixes for TRAP_PERF
In reply to Eric W. BiedermanDuring the merge window an issue with si_perf and the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAP TRAP_PERF and the new field si_perf.
The reason only alpha and sparc were affected is that they are the only architectures that use si_trapno.
Looking deeper it was discovered that si_trapno is used for only a few select signals on alpha and sparc, and that none of the other _sigfault fields past si_addr are used at all. Which means technically no regression on alpha and sparc.
While the alignment concerns might be dismissed the abuse of si_errno by SIGTRAP TRAP_PERF does have the potential to cause regressions in existing userspace.
While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP TRAP_PERF this set of changes cleans up siginfo_t.
- The si_trapno field is demoted from magic alpha and sparc status and made an ordinary union member of the _sigfault member of siginfo_t. Without moving it of course.
- si_perf is replaced with si_perf_data and si_perf_type ending the abuse of si_errno.
- Unnecessary additions to signalfd_siginfo are removed.
v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
This version drops the tests and fine grained handling of si_trapno on alpha and sparc (replaced assuming si_trapno is valid for all but the faults that defined different data).
Eric W. Biederman (5):
siginfo: Move si_trapno inside the union inside _si_fault
signal: Implement SIL_FAULT_TRAPNO
signal: Factor force_sig_perf out of perf_sigtrap
signal: Deliver all of the siginfo perf data in _perf
signalfd: Remove SIL_PERF_EVENT fields from signalfd_siginfo
arch/m68k/kernel/signal.c | 3 +- arch/x86/kernel/signal_compat.c | 9 +++- fs/signalfd.c | 23 ++++----- include/linux/compat.h | 10 ++-- include/linux/sched/signal.h | 1 + include/linux/signal.h | 1 + include/uapi/asm-generic/siginfo.h | 15 +++--- include/uapi/linux/perf_event.h | 2 +- include/uapi/linux/signalfd.h | 4 +- kernel/events/core.c | 11 +--- kernel/signal.c | 59 +++++++++++++--------- .../selftests/perf_events/sigtrap_threads.c | 14 ++--- 12 files changed, 79 insertions(+), 73 deletions(-)
PATCH v4 1/5 siginfo: Move si_trapno inside the union inside _si_fault
From: "Eric W. Biederman" <[email protected]>
It turns out that linux uses si_trapno very sparingly, and as such it can be considered extra information for a very narrow selection of signals, rather than information that is present with every fault reported in siginfo.
As such move si_trapno inside the union inside of _si_fault. This results in no change in placement, and makes it eaiser
to extend _si_fault in the future as this reduces the number of special cases. In particular with si_trapno included in the union it is no longer a concern that the union must be pointer aligned on most architectures because the union follows immediately after si_addr which is a pointer.
This change results in a difference in siginfo field placement on sparc and alpha for the fields si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. These architectures do not implement the signals that would use si_addr_lsb, si_lower, si_upper, si_pkey, and si_perf. Further these architecture have not yet implemented the userspace that would use si_perf.
The point of this change is in fact to correct these placement issues before sparc or alpha grow userspace that cares. This change was discussed[1] and the agreement is that this change is currently safe.
[1]: https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- arch/x86/kernel/signal_compat.c | 3 +++ include/linux/compat.h | 5 ++--- include/uapi/asm-generic/siginfo.h | 7 ++----- kernel/signal.c | 1 + 4 files changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/signal_compat.c +3 -0
@@ -127,6 +127,9 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_addr) !=0x10 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr) !=0x0C ); +BUILD_BUG_ON (offsetof(siginfo_t , si_trapno) !=0x18 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_trapno) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_addr_lsb) !=0x18 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_addr_lsb) !=0x10 );
include/linux/compat.h +2 -3
@@ -214,12 +214,11 @@ typedef struct compat_siginfo {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {compat_uptr_t _addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \ sizeof(short) : __alignof__(compat_uptr_t))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
include/uapi/asm-generic/siginfo.h +2 -5
@@ -63,9 +63,6 @@ union __sifields {/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ struct {void __user *_addr;/* faulting insn/memory ref. */ -#ifdef __ARCH_SI_TRAPNO -int _trapno;/* TRAP # which caused the signal */ -#endif #ifdef __ia64__int _imm;/* immediate value for "break" */ unsigned int _flags;/* see ia64 si_flags */
@@ -75,6 +72,8 @@ union __sifields {#define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \ sizeof(short) : __alignof__(void *))union { +/* used on alpha and sparc */ +int _trapno;/* TRAP # which caused the signal */ /* * used when si_code=BUS_MCEERR_AR or * used when si_code=BUS_MCEERR_AO
@@ -150,9 +149,7 @@ typedef struct siginfo {#define si_int _sifields._rt._sigval.sival_int#define si_ptr _sifields._rt._sigval.sival_ptr#define si_addr _sifields._sigfault._addr -#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno -#endif #define si_addr_lsb _sifields._sigfault._addr_lsb#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper
kernel/signal.c +1 -0
@@ -4607,6 +4607,7 @@ static inline void siginfo_buildtime_checks(void)/* sigfault */ CHECK_OFFSET (si_addr); +CHECK_OFFSET (si_trapno);CHECK_OFFSET (si_addr_lsb);CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);
Signature · 1 line
2.30.1
PATCH v4 2/5 signal: Implement SIL_FAULT_TRAPNO
From: "Eric W. Biederman" <[email protected]>
Now that si_trapno is part of the union in _si_fault and available on all architectures, add SIL_FAULT_TRAPNO and update siginfo_layout to return SIL_FAULT_TRAPNO when the code assumes si_trapno is valid.
There is room for future changes to reduce when si_trapno is valid but this is all that is needed to make si_trapno and the other members of the the union in _sigfault mutually exclusive.
Update the code that uses siginfo_layout to deal with SIL_FAULT_TRAPNO and have the same code ignore si_trapno in in all other cases.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 8 +++----- include/linux/signal.h | 1 + kernel/signal.c | 34 ++++++++++++---------------------- 3 files changed, 16 insertions(+), 27 deletions(-)
fs/signalfd.c +3 -5
@@ -123,15 +123,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,*/ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + new.ssi_addr = (long ) kinfo->si_addr; new.ssi_trapno = kinfo->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : new.ssi_addr = (long ) kinfo->si_addr; -#ifdef __ARCH_SI_TRAPNO - new.ssi_trapno = kinfo->si_trapno; -#endif new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ;case SIL_PERF_EVENT :
include/linux/signal.h +1 -0
@@ -40,6 +40,7 @@ enum siginfo_layout {SIL_TIMER ,SIL_POLL ,SIL_FAULT , +SIL_FAULT_TRAPNO ,SIL_FAULT_MCEERR ,SIL_FAULT_BNDERR , SIL_FAULT_PKUERR,
kernel/signal.c +12 -22
@@ -1194,6 +1194,7 @@ static inline bool has_si_pid_and_uid(struct kernel_siginfo *info)case SIL_TIMER :case SIL_POLL :case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -2527,6 +2528,7 @@ static void hide_si_addr_tag_bits(struct ksignal *ksig) {switch (siginfo_layout (ksig->sig, ksig->info.si_code)) {case SIL_FAULT : +case SIL_FAULT_TRAPNO :case SIL_FAULT_MCEERR :case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR :
@@ -3214,6 +3216,10 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) layout =SIL_PERF_EVENT ; +#ifdef __ARCH_SI_TRAPNO + else if (layout == SIL_FAULT) + layout =SIL_FAULT_TRAPNO ; +#endif }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;
@@ -3317,30 +3323,22 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_FAULT : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =ptr_to_compat (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =ptr_to_compat (from->si_lower); to->si_upper =ptr_to_compat (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =ptr_to_compat (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
@@ -3401,30 +3399,22 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_FAULT : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO +break ; +case SIL_FAULT_TRAPNO : + to->si_addr =compat_ptr (from->si_addr); to->si_trapno = from->si_trapno; -#endif break ;case SIL_FAULT_MCEERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_addr_lsb = from->si_addr_lsb;break ;case SIL_FAULT_BNDERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_lower =compat_ptr (from->si_lower); to->si_upper =compat_ptr (from->si_upper);break ;case SIL_FAULT_PKUERR : to->si_addr =compat_ptr (from->si_addr); -#ifdef __ARCH_SI_TRAPNO - to->si_trapno = from->si_trapno; -#endif to->si_pkey = from->si_pkey;break ;case SIL_PERF_EVENT :
Signature · 1 line
2.30.1
PATCH v4 3/5 signal: Factor force_sig_perf out of perf_sigtrap
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Separate filling in siginfo for TRAP_PERF from deciding that siginal needs to be sent.
There are enough little details that need to be correct when properly filling in siginfo_t that it is easy to make mistakes if filling in the siginfo_t is in the same function with other logic. So factor out force_sig_perf to reduce the cognative load of on reviewers, maintainers and implementors.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- include/linux/sched/signal.h | 1 + kernel/events/core.c | 11 ++--------- kernel/signal.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-)
include/linux/sched/signal.h +1 -0
@@ -326,6 +326,7 @@ int send_sig_mceerr(int code, void __user *, short, struct task_struct *);int force_sig_bnderr (void __user *addr,void __user *lower,void __user *upper);int force_sig_pkuerr (void __user *addr,u32 pkey); +int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_ptrace_errno_trap (int errno,void __user *addr);
kernel/events/core.c +2 -9
@@ -6394,8 +6394,6 @@ void perf_event_wakeup(struct perf_event *event)static void perf_sigtrap (struct perf_event *event) { -struct kernel_siginfo info; -/* * We'd expect this to only occur if the irq_work is delayed and either * ctx->task or current has changed in the meantime. This can be the
@@ -6410,13 +6408,8 @@ static void perf_sigtrap(struct perf_event *event)if (current->flags &PF_EXITING )return ; -clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_code =TRAP_PERF ; - info.si_errno = event->attr.type; - info.si_perf = event->attr.sig_data; - info.si_addr = (void __user *)event->pending_addr; -force_sig_info (&info); +force_sig_perf ((void __user *)event->pending_addr, + event->attr.type, event->attr.sig_data); }static void perf_pending_event_disable (struct perf_event *event)
kernel/signal.c +13 -0
@@ -1763,6 +1763,19 @@ int force_sig_pkuerr(void __user *addr, u32 pkey) }#endif +int force_sig_perf (void __user *addr,u32 type,u64 sig_data) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo =SIGTRAP ; + info.si_errno = type; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf = sig_data; +return force_sig_info (&info); +} +/* For the crazy architectures that include trap information in * the errno field, instead of an actual errno value. */
Signature · 1 line
2.30.1
PATCH v4 4/5 signal: Deliver all of the siginfo perf data in _perf
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
Don't abuse si_errno and deliver all of the perf data in _perf member of siginfo_t.
Note: The data field in the perf data structures in a u64 to allow a pointer to be encoded without needed to implement a 32bit and 64bit version of the same structure. There already exists a 32bit and 64bit versions siginfo_t, and the 32bit version can not include a 64bit member as it only has 32bit alignment. So unsigned long is used in siginfo_t instead of a u64 as unsigned long can encode a pointer on all architectures linux supports.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v3: https://lkml.kernel.org/r/[email protected]
--- arch/m68k/kernel/signal.c | 3 ++- arch/x86/kernel/signal_compat.c | 6 ++++-- fs/signalfd.c | 3 ++- include/linux/compat.h | 5 ++++- include/uapi/asm-generic/siginfo.h | 8 +++++-- include/uapi/linux/perf_event.h | 2 +- include/uapi/linux/signalfd.h | 4 ++-- kernel/signal.c | 21 ++++++++++++------- .../selftests/perf_events/sigtrap_threads.c | 14 ++++++------- 9 files changed, 41 insertions(+), 25 deletions(-)
arch/m68k/kernel/signal.c +2 -1
@@ -623,7 +623,8 @@ static inline void siginfo_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x12 );/* _sigfault._perf */ -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x14 );/* _sigpoll */ BUILD_BUG_ON (offsetof(siginfo_t , si_band) !=0x0c );
arch/x86/kernel/signal_compat.c +4 -2
@@ -141,8 +141,10 @@ static inline void signal_compat_build_tests(void)BUILD_BUG_ON (offsetof(siginfo_t , si_pkey) !=0x20 );BUILD_BUG_ON (offsetof(compat_siginfo_t , si_pkey) !=0x14 ); -BUILD_BUG_ON (offsetof(siginfo_t , si_perf) !=0x18 ); -BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf) !=0x10 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_data) !=0x18 ); +BUILD_BUG_ON (offsetof(siginfo_t , si_perf_type) !=0x20 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_data) !=0x10 ); +BUILD_BUG_ON (offsetof(compat_siginfo_t , si_perf_type) !=0x14 );CHECK_CSI_OFFSET (_sigpoll);CHECK_CSI_SIZE (_sigpoll,2 *sizeof (int ));
fs/signalfd.c +2 -1
@@ -134,7 +134,8 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_PERF_EVENT : new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf = kinfo->si_perf; + new.ssi_perf_type = kinfo->si_perf_type; + new.ssi_perf_data = kinfo->si_perf_data;break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid;
include/linux/compat.h +4 -1
@@ -236,7 +236,10 @@ typedef struct compat_siginfo {u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -compat_ulong_t _perf; +struct { +compat_ulong_t _data; +u32 _type; + } _perf; }; } _sigfault;
include/uapi/asm-generic/siginfo.h +6 -2
@@ -91,7 +91,10 @@ union __sifields {__u32 _pkey; } _addr_pkey;/* used when si_code=TRAP_PERF */ -unsigned long _perf; +struct { +unsigned long _data; +__u32 _type; + } _perf; }; } _sigfault;
@@ -154,7 +157,8 @@ typedef struct siginfo {#define si_lower _sifields._sigfault._addr_bnd._lower#define si_upper _sifields._sigfault._addr_bnd._upper#define si_pkey _sifields._sigfault._addr_pkey._pkey -#define si_perf _sifields._sigfault._perf +#define si_perf_data _sifields._sigfault._perf._data +#define si_perf_type _sifields._sigfault._perf._type#define si_band _sifields._sigpoll._band#define si_fd _sifields._sigpoll._fd#define si_call_addr _sifields._sigsys._call_addr
include/uapi/linux/perf_event.h +1 -1
@@ -464,7 +464,7 @@ struct perf_event_attr {/* * User provided data if sigtrap=1, passed back to user via -* siginfo_t::si_perf, e.g. to permit user to identify the event. +* siginfo_t::si_perf_data, e.g. to permit user to identify the event. */ __u64 sig_data; };
include/uapi/linux/signalfd.h +2 -2
@@ -39,8 +39,8 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 __pad3; -__u64 ssi_perf; +__u32 ssi_perf_type; +__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
kernel/signal.c +13 -8
@@ -1768,11 +1768,13 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data)struct kernel_siginfo info;clear_siginfo (&info); - info.si_signo =SIGTRAP ; - info.si_errno = type; - info.si_code =TRAP_PERF ; - info.si_addr = addr; - info.si_perf = sig_data; + info.si_signo =SIGTRAP ; + info.si_errno =0 ; + info.si_code =TRAP_PERF ; + info.si_addr = addr; + info.si_perf_data = sig_data; + info.si_perf_type = type; +return force_sig_info (&info); }
@@ -3356,7 +3358,8 @@ void copy_siginfo_to_external32(struct compat_siginfo *to,break ;case SIL_PERF_EVENT : to->si_addr =ptr_to_compat (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -3432,7 +3435,8 @@ static int post_copy_siginfo_from_user32(kernel_siginfo_t *to,break ;case SIL_PERF_EVENT : to->si_addr =compat_ptr (from->si_addr); - to->si_perf = from->si_perf; + to->si_perf_data = from->si_perf_data; + to->si_perf_type = from->si_perf_type;break ;case SIL_CHLD : to->si_pid = from->si_pid;
@@ -4615,7 +4619,8 @@ static inline void siginfo_buildtime_checks(void)CHECK_OFFSET (si_lower);CHECK_OFFSET (si_upper);CHECK_OFFSET (si_pkey); -CHECK_OFFSET (si_perf); +CHECK_OFFSET (si_perf_data); +CHECK_OFFSET (si_perf_type);/* sigpoll */ CHECK_OFFSET (si_band);
tools/testing/selftests/perf_events/sigtrap_threads.c +7 -7
@@ -43,7 +43,7 @@ static struct {siginfo_t first_siginfo;/* First observed siginfo_t. */ } ctx; -/* Unique value to check si_perf is correctly set from perf_event_attr::sig_data. */ +/* Unique value to check si_perf_data is correctly set from perf_event_attr::sig_data. */ #define TEST_SIG_DATA (addr) (~(unsigned long)(addr))static struct perf_event_attr make_event_attr (bool enabled,volatile void *addr)
@@ -164,8 +164,8 @@ TEST_F(sigtrap_threads, enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -183,8 +183,8 @@ TEST_F(sigtrap_threads, modify_and_enable_event)EXPECT_EQ (ctx.signal_count,NUM_THREADS );EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on));/* Check enabled for parent. */ ctx.iterate_on =0 ;
@@ -203,8 +203,8 @@ TEST_F(sigtrap_threads, signal_stress)EXPECT_EQ (ctx.signal_count,NUM_THREADS * ctx.iterate_on);EXPECT_EQ (ctx.tids_want_signal,0 );EXPECT_EQ (ctx.first_siginfo.si_addr, &ctx.iterate_on); -EXPECT_EQ (ctx.first_siginfo.si_errno,PERF_TYPE_BREAKPOINT ); -EXPECT_EQ (ctx.first_siginfo.si_perf,TEST_SIG_DATA (&ctx.iterate_on)); +EXPECT_EQ (ctx.first_siginfo.si_perf_type,PERF_TYPE_BREAKPOINT ); +EXPECT_EQ (ctx.first_siginfo.si_perf_data,TEST_SIG_DATA (&ctx.iterate_on)); }TEST_HARNESS_MAIN
Signature · 1 line
2.30.1
PATCH v4 5/5 signalfd: Remove SIL_PERF_EVENT fields from signalfd_siginfo
In reply to Eric W. BeidermanFrom: "Eric W. Biederman" <[email protected]>
With the addition of ssi_perf_data and ssi_perf_type struct signalfd_siginfo is dangerously close to running out of space. All that remains is just enough space for two additional 64bit fields. A practice of adding all possible siginfo_t fields into struct singalfd_siginfo can not be supported as adding the missing fields ssi_lower, ssi_upper, and ssi_pkey would require two 64bit fields and one 32bit fields. In practice the fields ssi_perf_data and ssi_perf_type can never be used by signalfd as the signal that generates them always delivers them synchronously to the thread that triggers them.
Therefore until someone actually needs the fields ssi_perf_data and ssi_perf_type in signalfd_siginfo remove them. This leaves a bit more room for future expansion.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- fs/signalfd.c | 16 ++++++---------- include/uapi/linux/signalfd.h | 4 +--- 2 files changed, 7 insertions(+), 13 deletions(-)
fs/signalfd.c +6 -10
@@ -114,12 +114,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,break ;case SIL_FAULT_BNDERR :case SIL_FAULT_PKUERR : +case SIL_PERF_EVENT :/* -* Fall through to the SIL_FAULT case. Both SIL_FAULT_BNDERR -* and SIL_FAULT_PKUERR are only generated by faults that -* deliver them synchronously to userspace. In case someone -* injects one of these signals and signalfd catches it treat -* it as SIL_FAULT. +* Fall through to the SIL_FAULT case. SIL_FAULT_BNDERR, +* SIL_FAULT_PKUERR, and SIL_PERF_EVENT are only +* generated by faults that deliver them synchronously to +* userspace. In case someone injects one of these signals +* and signalfd catches it treat it as SIL_FAULT. */ case SIL_FAULT : new.ssi_addr = (long ) kinfo->si_addr;
@@ -132,11 +133,6 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo, new.ssi_addr = (long ) kinfo->si_addr; new.ssi_addr_lsb = (short ) kinfo->si_addr_lsb;break ; -case SIL_PERF_EVENT : - new.ssi_addr = (long ) kinfo->si_addr; - new.ssi_perf_type = kinfo->si_perf_type; - new.ssi_perf_data = kinfo->si_perf_data; -break ;case SIL_CHLD : new.ssi_pid = kinfo->si_pid; new.ssi_uid = kinfo->si_uid;
include/uapi/linux/signalfd.h +1 -3
@@ -39,8 +39,6 @@ struct signalfd_siginfo {__s32 ssi_syscall;__u64 ssi_call_addr;__u32 ssi_arch; -__u32 ssi_perf_type; -__u64 ssi_perf_data;/* * Pad strcture to 128 bytes. Remember to update the
@@ -51,7 +49,7 @@ struct signalfd_siginfo {* comes out of a read(2) and we really don't want to have * a compat on read(2). */ -__u8 __pad[16 ]; +__u8 __pad[28 ]; };
Signature · 1 line
2.30.1
Re: [PATCH v4 0/5] siginfo: ABI fixes for TRAP_PERF
In reply to Eric W. BiedermanQuoted 30 lines · Eric W. Biederman
During the merge window an issue with
si_perfand the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAPTRAP_PERFand the new fieldsi_perf.The reason only alpha and sparc were affected is that they are the only architectures that use
si_trapno.Looking deeper it was discovered that
si_trapnois used for only a few select signals on alpha and sparc, and that none of the other_sigfaultfields pastsi_addrare used at all. Which means technically no regression on alpha and sparc.While the alignment concerns might be dismissed the abuse of
si_errnoby SIGTRAPTRAP_PERFdoes have the potential to cause regressions in existing userspace.While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP
TRAP_PERFthis set of changes cleans upsiginfo_t.- The
si_trapnofield is demoted from magic alpha and sparc status and made an ordinary union member of the_sigfaultmember ofsiginfo_t. Without moving it of course.-
si_perfis replaced withsi_perf_dataandsi_perf_typeending the abuse ofsi_errno.- Unnecessary additions to
signalfd_siginfoare removed.
Quoted 7 lines
v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]This version drops the tests and fine grained handling of
si_trapnoon alpha and sparc (replaced assumingsi_trapnois valid for all but the faults that defined different data).
And just to clarify, the rest of the series (including static-asserts) for the next merge-window will be sent once this series is all sorted, correct?
Quoted 6 lines
Eric W. Biederman (5):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_PERF_EVENTfields fromsignalfd_siginfo
Looks good, thank you! I build-tested (defconfig -- x86_64, i386, arm, arm64, m68k, sparc, alpha) this series together with a local patch to pull in the static asserts from v3. Also re-ran perf_events kselftests on x86_64 (native and 32bit compat).
Thanks,
-- Marco
Re: [PATCH v4 0/5] siginfo: ABI fixes for TRAP_PERF
Quoted 35 lines · Marco Elver
Quoted 34 lines · Eric W. Biederman
During the merge window an issue with
si_perfand the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAPTRAP_PERFand the new fieldsi_perf.The reason only alpha and sparc were affected is that they are the only architectures that use
si_trapno.Looking deeper it was discovered that
si_trapnois used for only a few select signals on alpha and sparc, and that none of the other_sigfaultfields pastsi_addrare used at all. Which means technically no regression on alpha and sparc.While the alignment concerns might be dismissed the abuse of
si_errnoby SIGTRAPTRAP_PERFdoes have the potential to cause regressions in existing userspace.While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP
TRAP_PERFthis set of changes cleans upsiginfo_t.- The
si_trapnofield is demoted from magic alpha and sparc status and made an ordinary union member of the_sigfaultmember ofsiginfo_t. Without moving it of course.-
si_perfis replaced withsi_perf_dataandsi_perf_typeending the abuse ofsi_errno.- Unnecessary additions to
signalfd_siginfoare removed.v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]
Quoted 7 lines
Quoted 3 lines
This version drops the tests and fine grained handling of
si_trapnoon alpha and sparc (replaced assumingsi_trapnois valid for all but the faults that defined different data).And just to clarify, the rest of the series (including static-asserts) for the next merge-window will be sent once this series is all sorted, correct?
That is the plan.
I really wonder about alphas use of si_trapno, and alphas use send_sig instead of force_sig. It could be worth looking into those as it has the potential to simplify the code.
Quoted 11 lines
Quoted 6 lines
Eric W. Biederman (5):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_PERF_EVENTfields fromsignalfd_siginfoLooks good, thank you! I build-tested (defconfig --
x86_64, i386, arm, arm64, m68k, sparc, alpha) this series together with a local patch to pull in the static asserts from v3. Also re-ranperf_eventskselftests onx86_64(native and 32bit compat).
Thanks,
Can I have your Tested-by?
Eric
Marco Elver
Tested-byRe: [PATCH v4 0/5] siginfo: ABI fixes for TRAP_PERF
Quoted 59 lines · Eric W. Biederman
Quoted 35 lines · Marco Elver
Quoted 34 lines · Eric W. Biederman
During the merge window an issue with
si_perfand the siginfo ABI came up. The alpha and sparc siginfo structure layout had changed with the addition of SIGTRAPTRAP_PERFand the new fieldsi_perf.The reason only alpha and sparc were affected is that they are the only architectures that use
si_trapno.Looking deeper it was discovered that
si_trapnois used for only a few select signals on alpha and sparc, and that none of the other_sigfaultfields pastsi_addrare used at all. Which means technically no regression on alpha and sparc.While the alignment concerns might be dismissed the abuse of
si_errnoby SIGTRAPTRAP_PERFdoes have the potential to cause regressions in existing userspace.While we still have time before userspace starts using and depending on the new definition siginfo for SIGTRAP
TRAP_PERFthis set of changes cleans upsiginfo_t.- The
si_trapnofield is demoted from magic alpha and sparc status and made an ordinary union member of the_sigfaultmember ofsiginfo_t. Without moving it of course.-
si_perfis replaced withsi_perf_dataandsi_perf_typeending the abuse ofsi_errno.- Unnecessary additions to
signalfd_siginfoare removed.v3: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
v1: https://lkml.kernel.org/r/[email protected]Quoted 7 lines
Quoted 3 lines
This version drops the tests and fine grained handling of
si_trapnoon alpha and sparc (replaced assumingsi_trapnois valid for all but the faults that defined different data).And just to clarify, the rest of the series (including static-asserts) for the next merge-window will be sent once this series is all sorted, correct?
That is the plan.
I really wonder about alphas use of
si_trapno, and alphas usesend_siginstead offorce_sig. It could be worth looking into those as it has the potential to simplify the code.Quoted 7 lines
Quoted 6 lines
Eric W. Biederman (5):
siginfo: Movesi_trapnoinside the union inside_si_fault
signal: ImplementSIL_FAULT_TRAPNO
signal: Factorforce_sig_perfout ofperf_sigtrap
signal: Deliver all of the siginfo perf data in_perf
signalfd: RemoveSIL_PERF_EVENTfields fromsignalfd_siginfo
Quoted 8 lines
Quoted 4 lines
Looks good, thank you! I build-tested (defconfig --
x86_64, i386, arm, arm64, m68k, sparc, alpha) this series together with a local patch to pull in the static asserts from v3. Also re-ranperf_eventskselftests onx86_64(native and 32bit compat).Thanks,
Can I have your Tested-by?
Of course,
Thanks,
-- Marco
Re: [RFC][PATCH 0/3] signal: Move si_trapno into the _si_fault union
In reply to Marco ElverQuoted 11 lines · Marco Elver
Quoted 10 lines · Eric W. Biederman
Well with 7 patches instead of 3 that was a little more than I thought I was going to send.
However that does demonstrate what I am thinking, and I think most of the changes are reasonable at this point.
I am very curious how synchronous this all is, because if this code is truly synchronous updating signalfd to handle this class of signal doesn't really make sense.
Just a note on this: the reason for adding signalfd support was based on the comment at SIL_FAULT_PKUERR:
Quoted 7 lines
/*
* Fall through to theSIL_FAULTcase. BothSIL_FAULT_BNDERR
* andSIL_FAULT_PKUERRare only generated by faults that
* deliver them synchronously to userspace. In case someone
* injects one of these signals and signalfd catches it treat
* it asSIL_FAULT.
*/
The same would hold for SIL_FAULT_PERF_EVENT, where somebody injects (re-injects perhaps?) such an event. But otherwise, yes, non-synchronous handling of SIGTRAP/TRAP_PERF is pretty useless for almost all usecases I can think of.
Thanks,
-- Marco
cover Final si_trapno bits
In reply to Eric W. BiedermanAs a part of a fix for the ABI of the newly added SIGTRAP TRAP_PERF a si_trapno was reduced to an ordinary extention of the _sigfault case of struct siginfo.
When Linus saw the complete set of changes come in as a fix he requested that the set of changes be trimmed down to just what was necessary to fix the SIGTRAP TRAP_PERF ABI.
I had intended to get the rest of the changes into the merge window for v5.14 but I dropped the ball.
I have made the changes to stop using __ARCH_SI_TRAPNO be per architecture so they are easier to review. In doing so I found one place on alpha where I used send_sig_fault instead of send_sig_fault_trapno(... si_trapno = 0). That would not have changed the userspace behavior but it did make the kernel code less clear.
My rule in these patches is everywhere that siginfo layout calls for SIL_FAULT_TRAPNO the code uses either force_sig_fault_trapno or send_sig_fault_trapno.
And of course I have rebased and compile tested Marco's compile time assert patches.
Eric
Eric W. Biederman (3):
signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP signal/alpha: si_trapno is only used with SIGFPE and SIGTRAP TRAP_UNK
signal: Remove the generic __ARCH_SI_TRAPNO support
Marco Elver (3):
sparc64: Add compile-time asserts for siginfo_t offsets
arm: Add compile-time asserts for siginfo_t offsets
arm64: Add compile-time asserts for siginfo_t offsets
arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 +-- arch/alpha/kernel/traps.c | 26 +++++++++--------- arch/alpha/mm/fault.c | 4 +-- arch/arm/kernel/signal.c | 37 +++++++++++++++++++++++++ arch/arm64/kernel/signal.c | 37 +++++++++++++++++++++++++ arch/arm64/kernel/signal32.c | 37 +++++++++++++++++++++++++ arch/mips/include/uapi/asm/siginfo.h | 2 -- arch/sparc/include/uapi/asm/siginfo.h | 3 -- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/signal32.c | 35 +++++++++++++++++++++++ arch/sparc/kernel/signal_64.c | 34 +++++++++++++++++++++++ arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 +++++++-------- arch/sparc/kernel/traps_64.c | 44 +++++++++++++---------------- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 11 ++------ kernel/signal.c | 52 ++++++++++++++++++++++++++--------- 22 files changed, 276 insertions(+), 88 deletions(-)
PATCH 1/6 sparc64: Add compile-time asserts for siginfo_t offsets
From: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout. Unlike other architectures, sparc64 is special, because it is one of few architectures requiring si_trapno. ABI breaks around that field would only be caught here.
--- arch/sparc/kernel/signal32.c | 35 +++++++++++++++++++++++++++++++++++ arch/sparc/kernel/signal_64.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
arch/sparc/kernel/signal32.c +35 -0
@@ -745,3 +745,38 @@ asmlinkage int do_sys32_sigstack(u32 u_ssptr, u32 u_ossptr, unsigned long sp) out:return ret; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_trapno) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 );
arch/sparc/kernel/signal_64.c +34 -0
@@ -556,3 +556,37 @@ void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned longuser_enter (); } +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_trapno) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x14 );
Signature · 1 line
2.20.1
PATCH 2/6 arm: Add compile-time asserts for siginfo_t offsets
In reply to Eric W. BiedermanFrom: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
This could have caught that we cannot portably add 64-bit integers to siginfo_t on 32-bit architectures like Arm before reaching -next:
https://lkml.kernel.org/r/[email protected]
--- arch/arm/kernel/signal.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
arch/arm/kernel/signal.c +37 -0
@@ -725,3 +725,40 @@ asmlinkage void do_rseq_syscall(struct pt_regs *regs)rseq_syscall (regs); }#endif + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x14 ); +static_assert (offsetof(siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.20.1
PATCH 3/6 arm64: Add compile-time asserts for siginfo_t offsets
In reply to Eric W. BiedermanFrom: Marco Elver <[email protected]>
To help catch ABI breaks at compile-time, add compile-time assertions to verify the siginfo_t layout.
--- arch/arm64/kernel/signal.c | 37 ++++++++++++++++++++++++++++++++++++ arch/arm64/kernel/signal32.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
arch/arm64/kernel/signal.c +37 -0
@@ -999,3 +999,40 @@ void __init minsigstksz_setup(void)round_up (sizeof (struct frame_record ),16 ) +16 ;/* max alignment padding */ } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(siginfo_t , si_pid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_uid) ==0x14 ); +static_assert (offsetof(siginfo_t , si_tid) ==0x10 ); +static_assert (offsetof(siginfo_t , si_overrun) ==0x14 ); +static_assert (offsetof(siginfo_t , si_status) ==0x18 ); +static_assert (offsetof(siginfo_t , si_utime) ==0x20 ); +static_assert (offsetof(siginfo_t , si_stime) ==0x28 ); +static_assert (offsetof(siginfo_t , si_value) ==0x18 ); +static_assert (offsetof(siginfo_t , si_int) ==0x18 ); +static_assert (offsetof(siginfo_t , si_ptr) ==0x18 ); +static_assert (offsetof(siginfo_t , si_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_addr_lsb) ==0x18 ); +static_assert (offsetof(siginfo_t , si_lower) ==0x20 ); +static_assert (offsetof(siginfo_t , si_upper) ==0x28 ); +static_assert (offsetof(siginfo_t , si_pkey) ==0x20 ); +static_assert (offsetof(siginfo_t , si_perf_data) ==0x18 ); +static_assert (offsetof(siginfo_t , si_perf_type) ==0x20 ); +static_assert (offsetof(siginfo_t , si_band) ==0x10 ); +static_assert (offsetof(siginfo_t , si_fd) ==0x18 ); +static_assert (offsetof(siginfo_t , si_call_addr) ==0x10 ); +static_assert (offsetof(siginfo_t , si_syscall) ==0x18 ); +static_assert (offsetof(siginfo_t , si_arch) ==0x1c );
arch/arm64/kernel/signal32.c +37 -0
@@ -457,3 +457,40 @@ void compat_setup_restart_syscall(struct pt_regs *regs) { regs->regs[7 ] = __NR_compat_restart_syscall; } + +/* +* Compile-time assertions for siginfo_t offsets. Check NSIG* as well, as +* changes likely come with new fields that should be added below. +*/ +static_assert (NSIGILL ==11 ); +static_assert (NSIGFPE ==15 ); +static_assert (NSIGSEGV ==9 ); +static_assert (NSIGBUS ==5 ); +static_assert (NSIGTRAP ==6 ); +static_assert (NSIGCHLD ==6 ); +static_assert (NSIGSYS ==2 ); +static_assert (offsetof(compat_siginfo_t , si_signo) ==0x00 ); +static_assert (offsetof(compat_siginfo_t , si_errno) ==0x04 ); +static_assert (offsetof(compat_siginfo_t , si_code) ==0x08 ); +static_assert (offsetof(compat_siginfo_t , si_pid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_uid) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_tid) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_overrun) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_status) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_utime) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_stime) ==0x1c ); +static_assert (offsetof(compat_siginfo_t , si_value) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_int) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_ptr) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_addr_lsb) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_lower) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_upper) ==0x18 ); +static_assert (offsetof(compat_siginfo_t , si_pkey) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_perf_data) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_perf_type) ==0x14 ); +static_assert (offsetof(compat_siginfo_t , si_band) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_fd) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_call_addr) ==0x0c ); +static_assert (offsetof(compat_siginfo_t , si_syscall) ==0x10 ); +static_assert (offsetof(compat_siginfo_t , si_arch) ==0x14 );
Signature · 1 line
2.20.1
PATCH 4/6 signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP
In reply to Eric W. BiedermanWhile reviewing the signal handlers on sparc it became clear that si_trapno is only set to a non-zero value when sending SIGILL with si_code ILL_ILLTRP.
Add force_sig_fault_trapno and send SIGILL ILL_ILLTRP with it.
Remove the define of __ARCH_SI_TRAPNO and remove the always zero si_trapno parameter from send_sig_fault and force_sig_fault.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- arch/sparc/include/uapi/asm/siginfo.h | 3 -- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 +++++++------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++--------------- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 1 + kernel/signal.c | 19 ++++++++++++ 11 files changed, 56 insertions(+), 45 deletions(-)
arch/sparc/include/uapi/asm/siginfo.h +0 -3
@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h>
arch/sparc/kernel/process_64.c +1 -1
@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \
arch/sparc/kernel/sys_sparc_32.c +1 -1
@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);
arch/sparc/kernel/sys_sparc_64.c +1 -1
@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif
arch/sparc/kernel/traps_32.c +11 -11
@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */
@@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;
@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif
@@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE
arch/sparc/kernel/traps_64.c +19 -25
144 lines not on this page · raw message
arch/sparc/kernel/unaligned_32.c +1 -1
@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }
arch/sparc/mm/fault_32.c +1 -1
@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)
arch/sparc/mm/fault_64.c +1 -1
@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)
include/linux/sched/signal.h +1 -0
@@ -329,6 +329,7 @@ int force_sig_pkuerr(void __user *addr, u32 pkey);int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_ptrace_errno_trap (int errno,void __user *addr); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);extern void force_sigsegv (int sig);
kernel/signal.c +19 -0
@@ -1808,6 +1808,22 @@ int force_sig_ptrace_errno_trap(int errno, void __user *addr)return force_sig_info (&info); } +/* For the rare architectures that include trap information using +* si_trapno. +*/ +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return force_sig_info (&info); +} +int kill_pgrp (struct pid *pid,int sig,int priv) {int ret;
@@ -3243,6 +3259,9 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) layout =SIL_PERF_EVENT ; + else if (IS_ENABLED(CONFIG_SPARC) && + (sig == SIGILL) && (si_code == ILL_ILLTRP)) + layout =SIL_FAULT_TRAPNO ;#ifdef __ARCH_SI_TRAPNO else if (layout == SIL_FAULT) layout =SIL_FAULT_TRAPNO ;
Signature · 1 line
2.20.1
Re: [PATCH 4/6] signal/sparc: si_trapno is only used with SIGILL ILL_ILLTRP
Quoted 4 lines · Eric W. Biederman
While reviewing the signal handlers on sparc it became clear that
si_trapnois only set to a non-zero value when sending SIGILL withsi_codeILL_ILLTRP.
Quoted 8 lines
Add
force_sig_fault_trapnoand send SIGILLILL_ILLTRPwith it.Remove the define of
__ARCH_SI_TRAPNOand remove the always zerosi_trapnoparameter fromsend_sig_faultandforce_sig_fault.v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 416 lines
--- arch/sparc/include/uapi/asm/siginfo.h | 3 -- arch/sparc/kernel/process_64.c | 2 +- arch/sparc/kernel/sys_sparc_32.c | 2 +- arch/sparc/kernel/sys_sparc_64.c | 2 +- arch/sparc/kernel/traps_32.c | 22 +++++++------- arch/sparc/kernel/traps_64.c | 44 ++++++++++++--------------- arch/sparc/kernel/unaligned_32.c | 2 +- arch/sparc/mm/fault_32.c | 2 +- arch/sparc/mm/fault_64.c | 2 +- include/linux/sched/signal.h | 1 + kernel/signal.c | 19 ++++++++++++ 11 files changed, 56 insertions(+), 45 deletions(-)arch/sparc/include/uapi/asm/siginfo.h +0
-3@@ -8,9 +8,6 @@#endif /* defined(__sparc__) && defined(__arch64__) */ - -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> arch/sparc/kernel/process_64.c +1
-1@@ -518,7 +518,7 @@ void synchronize_user_stack(void)static void stack_unaligned (unsigned long sp) { -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) sp); }static const char uwfault32[] =KERN_INFO \arch/sparc/kernel/sys_sparc_32.c +1
-1@@ -151,7 +151,7 @@ sparc_breakpoint (struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%x, nPC=%x\n" , regs->pc, regs->npc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%x nPC=%x\n" , regs->pc, regs->npc);arch/sparc/kernel/sys_sparc_64.c +1
-1@@ -514,7 +514,7 @@ asmlinkage void sparc_breakpoint(struct pt_regs *regs)#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Entering kernel PC=%lx, nPC=%lx\n" , regs->tpc, regs->tnpc);#endif -force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc,0 ); +force_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->tpc);#ifdef DEBUG_SPARC_BREAKPOINT printk ("TRAP: Returning to space: PC=%lx nPC=%lx\n" , regs->tpc, regs->tnpc);#endif arch/sparc/kernel/traps_32.c +11
-11@@ -102,8 +102,8 @@ void do_hw_interrupt(struct pt_regs *regs, unsigned long type)if (regs->psr &PSR_PS )die_if_kernel ("Kernel bad trap" , regs); -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->pc, type -0x80 ); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->pc, type -0x80 ); } void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -116,7 +116,7 @@ void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned lon regs->pc, *(unsigned long *)regs->pc);#endif -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc, current); } void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -124,7 +124,7 @@ void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin instruction from Penguin mode??!?!" , regs); -send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)pc, current); }/* XXX User may want to be allowed to do this. XXX */ @@ -145,7 +145,7 @@ void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned lon#endif send_sig_fault (SIGBUS ,BUS_ADRALN ,/* FIXME: Should dig out mna address */ (void *)0 , -0 , current); + current); }static unsigned long init_fsr =0x0UL ;@@ -291,7 +291,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,else if (fsr &0x01 ) code =FPE_FLTRES ; } -send_sig_fault (SIGFPE , code, (void __user *)pc,0 , fpt); +send_sig_fault (SIGFPE , code, (void __user *)pc, fpt);#ifndef CONFIG_SMP last_task_used_math =NULL ;#endif @@ -305,7 +305,7 @@ void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long n {if (psr &PSR_PS )die_if_kernel ("Penguin overflow trap from kernel mode" , regs); -send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc,0 , current); +send_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)pc, current); } void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -327,13 +327,13 @@ void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npcprintk ("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void __user *)pc); }void handle_cp_disabled (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); } void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,@@ -343,13 +343,13 @@ void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long nprintk ("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n" , pc, npc, psr);#endif -send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc,0 , current); +send_sig_fault (SIGILL ,ILL_COPROC , (void __user *)pc, current); }void handle_hw_divzero (struct pt_regs *regs,unsigned long pc,unsigned long npc,unsigned long psr) { -send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc,0 , current); +send_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)pc, current); }#ifdef CONFIG_DEBUG_BUGVERBOSE arch/sparc/kernel/traps_64.c +19
-25@@ -107,8 +107,8 @@ void bad_trap(struct pt_regs *regs, long lvl) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGILL ,ILL_ILLTRP , - (void __user *)regs->tpc, lvl); +force_sig_fault_trapno (SIGILL ,ILL_ILLTRP , + (void __user *)regs->tpc, lvl); }void bad_trap_tl1 (struct pt_regs *regs,long lvl)@@ -201,8 +201,7 @@ void spitfire_insn_access_exception(struct pt_regs *regs, unsigned long sfsr, un regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_MAPERR , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -237,7 +236,7 @@ void sun4v_insn_access_exception(struct pt_regs *regs, unsigned long addr, unsig regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *) addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *) addr); }void sun4v_insn_access_exception_tl1 (struct pt_regs *regs,unsigned long addr,unsigned long type_ctx)@@ -321,7 +320,7 @@ void spitfire_data_access_exception(struct pt_regs *regs, unsigned long sfsr, unif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)sfar,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)sfar); out:exception_exit (prev_state); }@@ -385,13 +384,13 @@ void sun4v_data_access_exception(struct pt_regs *regs, unsigned long addr, unsig*/ switch (type) {case HV_FAULT_TYPE_INV_ASI : -force_sig_fault (SIGILL ,ILL_ILLADR , (void __user *)addr,0 ); +force_sig_fault (SIGILL ,ILL_ILLADR , (void __user *)addr);break ;case HV_FAULT_TYPE_MCD_DIS : -force_sig_fault (SIGSEGV ,SEGV_ACCADI , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_ACCADI , (void __user *)addr);break ;default : -force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_MAPERR , (void __user *)addr);break ; } }@@ -568,7 +567,7 @@ static void spitfire_ue_log(unsigned long afsr, unsigned long afar, unsigned lon regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGBUS ,BUS_OBJERR , (void *)0 ,0 ); +force_sig_fault (SIGBUS ,BUS_OBJERR , (void *)0 ); }void spitfire_access_error (struct pt_regs *regs,unsigned long status_encoded,unsigned long afar)@@ -2069,8 +2068,7 @@ void do_mcd_err(struct pt_regs *regs, struct sun4v_error_entry ent)/* Send SIGSEGV to the userspace process with the right signal * code */ -force_sig_fault (SIGSEGV ,SEGV_ADIDERR , (void __user *)ent.err_raddr, -0 ); +force_sig_fault (SIGSEGV ,SEGV_ADIDERR , (void __user *)ent.err_raddr); }/* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate. @@ -2184,7 +2182,7 @@ bool sun4v_nonresum_error_user_handled(struct pt_regs *regs, }if (attrs &SUN4V_ERR_ATTRS_PIO ) {force_sig_fault (SIGBUS ,BUS_ADRERR , - (void __user *)sun4v_get_vaddr (regs),0 ); + (void __user *)sun4v_get_vaddr (regs));return true; }@@ -2340,8 +2338,7 @@ static void do_fpe_common(struct pt_regs *regs)else if (fsr &0x01 ) code =FPE_FLTRES ; } -force_sig_fault (SIGFPE , code, - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGFPE , code, (void __user *)regs->tpc); } }@@ -2395,8 +2392,7 @@ void do_tof(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGEMT ,EMT_TAGOVF , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGEMT ,EMT_TAGOVF , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -2415,8 +2411,7 @@ void do_div0(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGFPE ,FPE_INTDIV , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGFPE ,FPE_INTDIV , (void __user *)regs->tpc); out:exception_exit (prev_state); }@@ -2612,7 +2607,7 @@ void do_illegal_instruction(struct pt_regs *regs) } } } -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)pc); out:exception_exit (prev_state); }@@ -2632,7 +2627,7 @@ void mem_address_unaligned(struct pt_regs *regs, unsigned long sfar, unsigned loif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)sfar,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)sfar); out:exception_exit (prev_state); }@@ -2650,7 +2645,7 @@ void sun4v_do_mna(struct pt_regs *regs, unsigned long addr, unsigned long type_cif (is_no_fault_exception (regs))return ; -force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) addr,0 ); +force_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *) addr); }/* sun4v_mem_corrupt_detect_precise() - Handle precise exception on an ADI @@ -2697,7 +2692,7 @@ void sun4v_mem_corrupt_detect_precise(struct pt_regs *regs, unsigned long addr, regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGSEGV ,SEGV_ADIPERR , (void __user *)addr,0 ); +force_sig_fault (SIGSEGV ,SEGV_ADIPERR , (void __user *)addr); }void do_privop (struct pt_regs *regs)@@ -2712,8 +2707,7 @@ void do_privop(struct pt_regs *regs) regs->tpc &=0xffffffff ; regs->tnpc &=0xffffffff ; } -force_sig_fault (SIGILL ,ILL_PRVOPC , - (void __user *)regs->tpc,0 ); +force_sig_fault (SIGILL ,ILL_PRVOPC , (void __user *)regs->tpc); out:exception_exit (prev_state); }arch/sparc/kernel/unaligned_32.c +1
-1@@ -278,5 +278,5 @@ asmlinkage void user_unaligned_trap(struct pt_regs *regs, unsigned int insn) {send_sig_fault (SIGBUS ,BUS_ADRALN , (void __user *)safe_compute_effective_address (regs, insn), -0 , current); + current); }arch/sparc/mm/fault_32.c +1
-1@@ -83,7 +83,7 @@ static void __do_fault_siginfo(int code, int sig, struct pt_regs *regs,show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned long compute_si_addr (struct pt_regs *regs,int text_fault)arch/sparc/mm/fault_64.c +1
-1@@ -176,7 +176,7 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,if (unlikely (show_unhandled_signals))show_signal_msg (regs, sig, code, addr, current); -force_sig_fault (sig, code, (void __user *) addr,0 ); +force_sig_fault (sig, code, (void __user *) addr); }static unsigned int get_fault_insn (struct pt_regs *regs,unsigned int insn)include/linux/sched/signal.h +1
-0@@ -329,6 +329,7 @@ int force_sig_pkuerr(void __user *addr, u32 pkey);int force_sig_perf (void __user *addr,u32 type,u64 sig_data);int force_sig_ptrace_errno_trap (int errno,void __user *addr); +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);extern void force_sigsegv (int sig);kernel/signal.c +19
-1@@ -1808,6 +1808,22 @@ int force_sig_ptrace_errno_trap(int errno, void __user *addr)return force_sig_info (&info); } +/* For the rare architectures that include trap information using +* si_trapno. +*/ +int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return force_sig_info (&info); +} +int kill_pgrp (struct pid *pid,int sig,int priv) {int ret;@@ -3243,6 +3259,9 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)#endif else if ((sig == SIGTRAP) && (si_code == TRAP_PERF)) layout =SIL_PERF_EVENT ; + else if (IS_ENABLED(CONFIG_SPARC) && + (sig == SIGILL) && (si_code == ILL_ILLTRP)) + layout =SIL_FAULT_TRAPNO ;#ifdef __ARCH_SI_TRAPNO else if (layout == SIL_FAULT) layout =SIL_FAULT_TRAPNO ; --2.20.1
--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/87mtqnxx89.fsf_-_%40disp2133.
PATCH 5/6 signal/alpha: si_trapno is only used with SIGFPE and SIGTRAP TRAP_UNK
In reply to Eric W. BiedermanWhile reviewing the signal handlers on alpha it became clear that si_trapno is only set to a non-zero value when sending SIGFPE and when sending SITGRAP with si_code TRAP_UNK.
Add send_sig_fault_trapno and send SIGTRAP TRAP_UNK, and SIGFPE with it.
Remove the define of __ARCH_SI_TRAPNO and remove the always zero si_trapno parameter from send_sig_fault and force_sig_fault.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 ++-- arch/alpha/kernel/traps.c | 26 +++++++++++++------------- arch/alpha/mm/fault.c | 4 ++-- include/linux/sched/signal.h | 2 ++ kernel/signal.c | 21 +++++++++++++++++++++ 7 files changed, 41 insertions(+), 20 deletions(-)
arch/alpha/include/uapi/asm/siginfo.h +0 -2
@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif
arch/alpha/kernel/osf_sys.c +1 -1
@@ -876,7 +876,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,if (fex &IEEE_TRAP_ENABLE_DZE ) si_code =FPE_FLTDIV ;if (fex &IEEE_TRAP_ENABLE_INV ) si_code =FPE_FLTINV ; -send_sig_fault (SIGFPE , si_code, +send_sig_fault_trapno (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ 0 , current); }
arch/alpha/kernel/signal.c +2 -2
@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;
arch/alpha/kernel/traps.c +13 -13
@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void
@@ -268,13 +268,13 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGTRAP ,TRAP_UNK , + (void __user *) regs->pc,0 , current);return ;case 2 :/* gentrap */
@@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */
@@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }
@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a
@@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }
@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }
arch/alpha/mm/fault.c +2 -2
@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC
include/linux/sched/signal.h +2 -0
@@ -330,6 +330,8 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data);int force_sig_ptrace_errno_trap (int errno,void __user *addr);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);extern void force_sigsegv (int sig);
kernel/signal.c +21 -0
@@ -1824,6 +1824,23 @@ int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno)return force_sig_info (&info); } +/* For the rare architectures that include trap information using +* si_trapno. +*/ +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return send_sig_info (info.si_signo, &info, t); +} +int kill_pgrp (struct pid *pid,int sig,int priv) {int ret;
@@ -3262,6 +3279,10 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)else if (IS_ENABLED (CONFIG_SPARC ) && (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (CONFIG_ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ;#ifdef __ARCH_SI_TRAPNO else if (layout == SIL_FAULT) layout =SIL_FAULT_TRAPNO ;
Signature · 1 line
2.20.1
Re: [PATCH 5/6] signal/alpha: si_trapno is only used with SIGFPE and SIGTRAP TRAP_UNK
Quoted 4 lines · Eric W. Biederman
While reviewing the signal handlers on alpha it became clear that
si_trapnois only set to a non-zero value when sending SIGFPE and when sending SITGRAP withsi_codeTRAP_UNK.
Quoted 8 lines
Add
send_sig_fault_trapnoand send SIGTRAPTRAP_UNK, and SIGFPE with it.Remove the define of
__ARCH_SI_TRAPNOand remove the always zerosi_trapnoparameter fromsend_sig_faultandforce_sig_fault.v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 220 lines
--- arch/alpha/include/uapi/asm/siginfo.h | 2 -- arch/alpha/kernel/osf_sys.c | 2 +- arch/alpha/kernel/signal.c | 4 ++-- arch/alpha/kernel/traps.c | 26 +++++++++++++------------- arch/alpha/mm/fault.c | 4 ++-- include/linux/sched/signal.h | 2 ++ kernel/signal.c | 21 +++++++++++++++++++++ 7 files changed, 41 insertions(+), 20 deletions(-)arch/alpha/include/uapi/asm/siginfo.h +0
-2@@ -2,8 +2,6 @@#ifndef _ALPHA_SIGINFO_H#define _ALPHA_SIGINFO_H -#define __ARCH_SI_TRAPNO -#include <asm-generic/siginfo.h> #endif arch/alpha/kernel/osf_sys.c +1
-1@@ -876,7 +876,7 @@ SYSCALL_DEFINE5(osf_setsysinfo, unsigned long, op, void __user *, buffer,if (fex &IEEE_TRAP_ENABLE_DZE ) si_code =FPE_FLTDIV ;if (fex &IEEE_TRAP_ENABLE_INV ) si_code =FPE_FLTINV ; -send_sig_fault (SIGFPE , si_code, +send_sig_fault_trapno (SIGFPE , si_code, (void __user *)NULL ,/* FIXME */ 0 , current); }arch/alpha/kernel/signal.c +2
-2@@ -219,7 +219,7 @@ do_sigreturn(struct sigcontext __user *sc)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;@@ -247,7 +247,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame)/* Send SIGTRAP if we're single-stepping: */ if (ptrace_cancel_bpt (current)) { -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *) regs->pc, current); }return ;arch/alpha/kernel/traps.c +13
-13@@ -227,7 +227,7 @@ do_entArith(unsigned long summary, unsigned long write_mask, }die_if_kernel ("Arithmetic fault" , regs,0 ,NULL ); -send_sig_fault (SIGFPE , si_code, (void __user *) regs->pc,0 , current); +send_sig_fault_trapno (SIGFPE , si_code, (void __user *) regs->pc,0 , current); }asmlinkage void@@ -268,13 +268,13 @@ do_entIF(unsigned long type, struct pt_regs *regs) regs->pc -=4 ;/* make pc point to former bpt */ } -send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc,0 , +send_sig_fault (SIGTRAP ,TRAP_BRKPT , (void __user *)regs->pc, current);return ;case 1 :/* bugcheck */ -send_sig_fault (SIGTRAP ,TRAP_UNK , (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGTRAP ,TRAP_UNK , + (void __user *) regs->pc,0 , current);return ;case 2 :/* gentrap */ @@ -335,8 +335,8 @@ do_entIF(unsigned long type, struct pt_regs *regs)break ; } -send_sig_fault (signo, code, (void __user *) regs->pc, regs->r16, - current); +send_sig_fault_trapno (signo, code, (void __user *) regs->pc, + regs->r16, current);return ;case 4 :/* opDEC */ @@ -360,9 +360,9 @@ do_entIF(unsigned long type, struct pt_regs *regs)if (si_code ==0 )return ;if (si_code >0 ) { -send_sig_fault (SIGFPE , si_code, - (void __user *) regs->pc,0 , - current); +send_sig_fault_trapno (SIGFPE , si_code, + (void __user *) regs->pc, +0 , current);return ; } }@@ -387,7 +387,7 @@ do_entIF(unsigned long type, struct pt_regs *regs) ; } -send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 , current); +send_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc, current); }/* There is an ifdef in the PALcode in MILO that enables a @@ -402,7 +402,7 @@ do_entDbg(struct pt_regs *regs) {die_if_kernel ("Instruction fault" , regs,0 ,NULL ); -force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc,0 ); +force_sig_fault (SIGILL ,ILL_ILLOPC , (void __user *)regs->pc); }@@ -964,12 +964,12 @@ do_entUnaUser(void __user * va, unsigned long opcode, si_code =SEGV_MAPERR ;mmap_read_unlock (mm); } -send_sig_fault (SIGSEGV , si_code, va,0 , current); +send_sig_fault (SIGSEGV , si_code, va, current);return ; give_sigbus: regs->pc -=4 ; -send_sig_fault (SIGBUS ,BUS_ADRALN , va,0 , current); +send_sig_fault (SIGBUS ,BUS_ADRALN , va, current);return ; }arch/alpha/mm/fault.c +2
-2@@ -219,13 +219,13 @@ do_page_fault(unsigned long address, unsigned long mmcsr,mmap_read_unlock (mm);/* Send a sigbus, regardless of whether we were in kernel or user mode. */ -force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address,0 ); +force_sig_fault (SIGBUS ,BUS_ADRERR , (void __user *) address);if (!user_mode (regs)) goto no_context;return ; do_sigsegv: -force_sig_fault (SIGSEGV , si_code, (void __user *) address,0 ); +force_sig_fault (SIGSEGV , si_code, (void __user *) address);return ;#ifdef CONFIG_ALPHA_LARGE_VMALLOC include/linux/sched/signal.h +2
-0@@ -330,6 +330,8 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data);int force_sig_ptrace_errno_trap (int errno,void __user *addr);int force_sig_fault_trapno (int sig,int code,void __user *addr,int trapno); +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t);extern int send_sig_info (int ,struct kernel_siginfo *,struct task_struct *);extern void force_sigsegv (int sig);kernel/signal.c +21
-1@@ -1824,6 +1824,23 @@ int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno)return force_sig_info (&info); } +/* For the rare architectures that include trap information using +* si_trapno. +*/ +int send_sig_fault_trapno (int sig,int code,void __user *addr,int trapno, +struct task_struct *t) +{ +struct kernel_siginfo info; + +clear_siginfo (&info); + info.si_signo = sig; + info.si_errno =0 ; + info.si_code = code; + info.si_addr = addr; + info.si_trapno = trapno; +return send_sig_info (info.si_signo, &info, t); +} +int kill_pgrp (struct pid *pid,int sig,int priv) {int ret;@@ -3262,6 +3279,10 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code)else if (IS_ENABLED (CONFIG_SPARC ) && (sig ==SIGILL ) && (si_code ==ILL_ILLTRP )) layout =SIL_FAULT_TRAPNO ; +else if (IS_ENABLED (CONFIG_ALPHA ) && + ((sig ==SIGFPE ) || + ((sig ==SIGTRAP ) && (si_code ==TRAP_UNK )))) + layout =SIL_FAULT_TRAPNO ;#ifdef __ARCH_SI_TRAPNO else if (layout == SIL_FAULT) layout =SIL_FAULT_TRAPNO ; --2.20.1
PATCH 6/6 signal: Remove the generic __ARCH_SI_TRAPNO support
In reply to Eric W. BiedermanNow that __ARCH_SI_TRAPNO is no longer set by any architecture remove all of the code it enabled from the kernel.
On alpha and sparc a more explict approach of using send_sig_fault_trapno or force_sig_fault_trapno in the very limited circumstances where si_trapno was set to a non-zero value.
The generic support that is being removed always set si_trapno on all fault signals. With only SIGILL ILL_ILLTRAP on sparc and SIGFPE and SIGTRAP TRAP_UNK on alpla providing si_trapno values asking all senders of fault signals to provide an si_trapno value does not make sense.
Making si_trapno an ordinary extension of the fault siginfo layout has enabled the architecture generic implementation of SIGTRAP TRAP_PERF, and enables other faulting signals to grow architecture generic senders as well.
v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]
--- arch/mips/include/uapi/asm/siginfo.h | 2 -- include/linux/sched/signal.h | 8 -------- kernel/signal.c | 14 -------------- 3 files changed, 24 deletions(-)
arch/mips/include/uapi/asm/siginfo.h +0 -2
@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFO
include/linux/sched/signal.h +0 -8
@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else
@@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);
kernel/signal.c +0 -14
@@ -1666,7 +1666,6 @@ void force_sigsegv(int sig) } int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {
@@ -1677,9 +1676,6 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;
@@ -1689,16 +1685,13 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr } int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)) { return force_sig_fault_to_task(sig, code, addr - ___ARCH_SI_TRAPNO(trapno)___ARCH_SI_IA64 (imm, flags, isr), current); } int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {
@@ -1709,9 +1702,6 @@ int send_sig_fault(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;
@@ -3283,10 +3273,6 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) ((sig == SIGFPE) || ((sig == SIGTRAP) && (si_code == TRAP_UNK)))) layout =SIL_FAULT_TRAPNO ; -#ifdef __ARCH_SI_TRAPNO - else if (layout == SIL_FAULT) - layout =SIL_FAULT_TRAPNO ; -#endif }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ;
Signature · 1 line
2.20.1
Re: [PATCH 6/6] signal: Remove the generic __ARCH_SI_TRAPNO support
Quoted 12 lines · Eric W. Biederman
Now that
__ARCH_SI_TRAPNOis no longer set by any architecture remove all of the code it enabled from the kernel.On alpha and sparc a more explict approach of using
send_sig_fault_trapnoorforce_sig_fault_trapnoin the very limited circumstances wheresi_trapnowas set to a non-zero value.The generic support that is being removed always set
si_trapnoon all fault signals. With only SIGILLILL_ILLTRAPon sparc and SIGFPE and SIGTRAPTRAP_UNKon alpla providingsi_trapnovalues asking all senders of fault signals to provide ansi_trapnovalue does not make sense.
Quoted 8 lines
Making
si_trapnoan ordinary extension of the fault siginfo layout has enabled the architecture generic implementation of SIGTRAPTRAP_PERF, and enables other faulting signals to grow architecture generic senders as well.v1: https://lkml.kernel.org/r/[email protected]
v2: https://lkml.kernel.org/r/[email protected]Signed-off-by "Eric W. Biederman" <[email protected]>
Quoted 114 lines
--- arch/mips/include/uapi/asm/siginfo.h | 2 -- include/linux/sched/signal.h | 8 -------- kernel/signal.c | 14 -------------- 3 files changed, 24 deletions(-)arch/mips/include/uapi/asm/siginfo.h +0
-2@@ -10,9 +10,7 @@#ifndef _UAPI_ASM_SIGINFO_H#define _UAPI_ASM_SIGINFO_H -#define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(long) + 2*sizeof(int)) -#undef __ARCH_SI_TRAPNO/* exception code needs to fill this ... */ #define __ARCH_HAS_SWAPPED_SIGINFOinclude/linux/sched/signal.h +0
-8@@ -298,11 +298,6 @@ static inline void kernel_signal_stop(void)schedule (); } -#ifdef __ARCH_SI_TRAPNO -# define ___ARCH_SI_TRAPNO (_a1) , _a1 -#else -# define ___ARCH_SI_TRAPNO (_a1) -#endif #ifdef __ia64__# define ___ARCH_SI_IA64 (_a1, _a2, _a3) , _a1, _a2, _a3#else @@ -310,14 +305,11 @@ static inline void kernel_signal_stop(void)#endif int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t); int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)); int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t);kernel/signal.c +0
-15@@ -1666,7 +1666,6 @@ void force_sigsegv(int sig) } int force_sig_fault_to_task(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {@@ -1677,9 +1676,6 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;@@ -1689,16 +1685,13 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr } int force_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr)) { return force_sig_fault_to_task(sig, code, addr - ___ARCH_SI_TRAPNO(trapno)___ARCH_SI_IA64 (imm, flags, isr), current); } int send_sig_fault(int sig, int code, void __user *addr -___ARCH_SI_TRAPNO (int trapno)___ARCH_SI_IA64 (int imm,unsigned int flags,unsigned long isr) ,struct task_struct *t) {@@ -1709,9 +1702,6 @@ int send_sig_fault(int sig, int code, void __user *addr info.si_errno =0 ; info.si_code = code; info.si_addr = addr; -#ifdef __ARCH_SI_TRAPNO - info.si_trapno = trapno; -#endif #ifdef __ia64__ info.si_imm = imm; info.si_flags = flags;@@ -3283,10 +3273,6 @@ enum siginfo_layout siginfo_layout(unsigned sig, int si_code) ((sig == SIGFPE) || ((sig == SIGTRAP) && (si_code == TRAP_UNK)))) layout =SIL_FAULT_TRAPNO ; -#ifdef __ARCH_SI_TRAPNO - else if (layout == SIL_FAULT) - layout =SIL_FAULT_TRAPNO ; -#endif }else if (si_code <=NSIGPOLL ) layout =SIL_POLL ; --2.20.1
Re: [PATCH 0/6] Final si_trapno bits
In reply to Eric W. BiedermanQuoted 32 lines · Eric W. Biederman
As a part of a fix for the ABI of the newly added SIGTRAP
TRAP_PERFasi_trapnowas reduced to an ordinary extention of the_sigfaultcase of struct siginfo.When Linus saw the complete set of changes come in as a fix he requested that the set of changes be trimmed down to just what was necessary to fix the SIGTRAP
TRAP_PERFABI.I had intended to get the rest of the changes into the merge window for v5.14 but I dropped the ball.
I have made the changes to stop using
__ARCH_SI_TRAPNObe per architecture so they are easier to review. In doing so I found one place on alpha where I usedsend_sig_faultinstead of send_sig_fault_trapno(...si_trapno= 0). That would not have changed the userspace behavior but it did make the kernel code less clear.My rule in these patches is everywhere that siginfo layout calls for
SIL_FAULT_TRAPNOthe code uses eitherforce_sig_fault_trapnoorsend_sig_fault_trapno.And of course I have rebased and compile tested Marco's compile time assert patches.
Eric
Eric W. Biederman (3):
signal/sparc:si_trapnois only used with SIGILLILL_ILLTRPsignal/alpha:si_trapnois only used with SIGFPE and SIGTRAPTRAP_UNK
signal: Remove the generic__ARCH_SI_TRAPNOsupport
Quoted 4 lines
Marco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsets
Nice, thanks for the respin. If I diffed it right, I see this is almost (modulo what you mentioned above) equivalent to:
https://lore.kernel.org/linux-api/[email protected]/
+ what's already in mainline. It's only missing:
signal: Verify the alignment and size of siginfo_t
signal: Rename SIL_PERF_EVENT SIL_FAULT_PERF_EVENT for consistency
Would this be appropriate for this series, or rather separately, or dropped completely?
Thanks,
-- Marco
Re: [PATCH 0/6] Final si_trapno bits
Quoted 43 lines · Marco Elver
Quoted 32 lines · Eric W. Biederman
As a part of a fix for the ABI of the newly added SIGTRAP
TRAP_PERFasi_trapnowas reduced to an ordinary extention of the_sigfaultcase of struct siginfo.When Linus saw the complete set of changes come in as a fix he requested that the set of changes be trimmed down to just what was necessary to fix the SIGTRAP
TRAP_PERFABI.I had intended to get the rest of the changes into the merge window for v5.14 but I dropped the ball.
I have made the changes to stop using
__ARCH_SI_TRAPNObe per architecture so they are easier to review. In doing so I found one place on alpha where I usedsend_sig_faultinstead of send_sig_fault_trapno(...si_trapno= 0). That would not have changed the userspace behavior but it did make the kernel code less clear.My rule in these patches is everywhere that siginfo layout calls for
SIL_FAULT_TRAPNOthe code uses eitherforce_sig_fault_trapnoorsend_sig_fault_trapno.And of course I have rebased and compile tested Marco's compile time assert patches.
Eric
Eric W. Biederman (3):
signal/sparc:si_trapnois only used with SIGILLILL_ILLTRPsignal/alpha:si_trapnois only used with SIGFPE and SIGTRAPTRAP_UNK
signal: Remove the generic__ARCH_SI_TRAPNOsupportQuoted 4 lines
Marco Elver (3):
sparc64: Add compile-time asserts forsiginfo_toffsets
arm: Add compile-time asserts forsiginfo_toffsets
arm64: Add compile-time asserts forsiginfo_toffsetsNice, thanks for the respin. If I diffed it right, I see this is almost (modulo what you mentioned above) equivalent to:
https://lore.kernel.org/linux-api/[email protected]/
+ what's already in mainline. It's only missing:
Quoted 5 lines
signal: Verify the alignment and size of
siginfo_t
signal: RenameSIL_PERF_EVENTSIL_FAULT_PERF_EVENTfor consistencyWould this be appropriate for this series, or rather separately, or dropped completely?
Appropriate I just overlooked them.
Eric