diff mbox series

[2/3] signal: Implement SIL_FAULT_TRAPNO

Message ID m1o8dvs7s7.fsf_-_@fess.ebiederm.org
State New
Headers show
Series signal: Move si_trapno into the _si_fault union | expand

Commit Message

Eric W. Biederman April 30, 2021, 10:54 p.m. UTC
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.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 fs/signalfd.c          |  7 ++-----
 include/linux/signal.h |  1 +
 kernel/signal.c        | 36 ++++++++++++++----------------------
 3 files changed, 17 insertions(+), 27 deletions(-)

Comments

Eric W. Biederman April 30, 2021, 11:19 p.m. UTC | #1
ebiederm@xmission.com (Eric W. Biederman) writes:

> 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.

This change is missing a break in signalfd.

Eric

> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  fs/signalfd.c          |  7 ++-----
>  include/linux/signal.h |  1 +
>  kernel/signal.c        | 36 ++++++++++++++----------------------
>  3 files changed, 17 insertions(+), 27 deletions(-)
>
> diff --git a/fs/signalfd.c b/fs/signalfd.c
> index 040a1142915f..126c681a30e7 100644
> --- a/fs/signalfd.c
> +++ b/fs/signalfd.c
> @@ -123,15 +123,12 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
>  		 */
>  	case SIL_FAULT:
>  		new.ssi_addr = (long) kinfo->si_addr;
+ 		break;
> -#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:
> diff --git a/include/linux/signal.h b/include/linux/signal.h
> index 1e98548d7cf6..5160fd45e5ca 100644
> --- a/include/linux/signal.h
> +++ b/include/linux/signal.h
> @@ -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,
> diff --git a/kernel/signal.c b/kernel/signal.c
> index c3017aa8024a..7b2d61cb7411 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -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:
Marco Elver May 1, 2021, 10:33 a.m. UTC | #2
On Sat, 1 May 2021 at 00:54, Eric W. Biederman <ebiederm@xmission.com> wrote:
>
> 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.
>
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  fs/signalfd.c          |  7 ++-----
>  include/linux/signal.h |  1 +
>  kernel/signal.c        | 36 ++++++++++++++----------------------
>  3 files changed, 17 insertions(+), 27 deletions(-)
>
> diff --git a/fs/signalfd.c b/fs/signalfd.c
> index 040a1142915f..126c681a30e7 100644
> --- a/fs/signalfd.c
> +++ b/fs/signalfd.c
> @@ -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:
> diff --git a/include/linux/signal.h b/include/linux/signal.h
> index 1e98548d7cf6..5160fd45e5ca 100644
> --- a/include/linux/signal.h
> +++ b/include/linux/signal.h
> @@ -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,
> diff --git a/kernel/signal.c b/kernel/signal.c
> index c3017aa8024a..7b2d61cb7411 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -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;

The breakage isn't apparent here, but in later patches. These need to
become CONFIG_SPARC and CONFIG_ALPHA.


>                         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:
> --
> 2.30.1
Eric W. Biederman May 2, 2021, 6:24 p.m. UTC | #3
Marco Elver <elver@google.com> writes:

> On Sat, 1 May 2021 at 00:54, Eric W. Biederman <ebiederm@xmission.com> wrote:
>>
>> 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.
>>
>> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
>> ---
>>  fs/signalfd.c          |  7 ++-----
>>  include/linux/signal.h |  1 +
>>  kernel/signal.c        | 36 ++++++++++++++----------------------
>>  3 files changed, 17 insertions(+), 27 deletions(-)
>>
>> diff --git a/fs/signalfd.c b/fs/signalfd.c
>> index 040a1142915f..126c681a30e7 100644
>> --- a/fs/signalfd.c
>> +++ b/fs/signalfd.c
>> @@ -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:
>> diff --git a/include/linux/signal.h b/include/linux/signal.h
>> index 1e98548d7cf6..5160fd45e5ca 100644
>> --- a/include/linux/signal.h
>> +++ b/include/linux/signal.h
>> @@ -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,
>> diff --git a/kernel/signal.c b/kernel/signal.c
>> index c3017aa8024a..7b2d61cb7411 100644
>> --- a/kernel/signal.c
>> +++ b/kernel/signal.c
>> @@ -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;
>
> The breakage isn't apparent here, but in later patches. These need to
> become CONFIG_SPARC and CONFIG_ALPHA.

Good catch.  For some reason I thought IS_ENABLED added the CONFIG_
prefix but I looked and it doesn't.


>>                         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:
>> --
>> 2.30.1
diff mbox series

Patch

diff --git a/fs/signalfd.c b/fs/signalfd.c
index 040a1142915f..126c681a30e7 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -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:
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 1e98548d7cf6..5160fd45e5ca 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -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,
diff --git a/kernel/signal.c b/kernel/signal.c
index c3017aa8024a..7b2d61cb7411 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -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: