All of lore.kernel.org
 help / color / mirror / Atom feed
* RFC: bring UP 'lo' by default after creating new netns
@ 2017-06-29 23:57 Mahesh Bandewar (महेश बंडेवार)
  2017-06-30  1:08 ` Eric W. Biederman
  0 siblings, 1 reply; 49+ messages in thread
From: Mahesh Bandewar (महेश बंडेवार) @ 2017-06-29 23:57 UTC (permalink / raw)
  To: Eric Dumazet, ebiederm, adobriyan, David Miller, xiyou.wangcong
  Cc: linux-netdev

Creation of new network namespace is almost always followed up by
bringing up the loopback device.

        ip netns add foo
        ip -netns foo link set lo up

I'm not sure if there are any consequences of bringing the device UP
at the creation of network-namespace.

thanks,
--mahesh..

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 2178db8e47cd..ac0e86c9a17f 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -428,6 +428,11 @@ struct net *copy_net_ns(unsigned long flags,
                net_drop_ns(net);
                return ERR_PTR(rv);
        }
+       /* Set the loopback device UP */
+       rtnl_lock();
+       dev_open(net->loopback_dev);
+       rtnl_unlock();
+
        return net;
 }

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: RFC: bring UP 'lo' by default after creating new netns
  2017-06-29 23:57 RFC: bring UP 'lo' by default after creating new netns Mahesh Bandewar (महेश बंडेवार)
@ 2017-06-30  1:08 ` Eric W. Biederman
  2017-06-30  6:26   ` Mahesh Bandewar (महेश बंडेवार)
                     ` (6 more replies)
  0 siblings, 7 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30  1:08 UTC (permalink / raw)
  To: Mahesh Bandewar (महेश
	बंडेवार)
  Cc: Eric Dumazet, adobriyan, David Miller, xiyou.wangcong, linux-netdev

"Mahesh Bandewar (महेश बंडेवार)" <maheshb@google.com> writes:

> Creation of new network namespace is almost always followed up by
> bringing up the loopback device.
>
>         ip netns add foo
>         ip -netns foo link set lo up
>
> I'm not sure if there are any consequences of bringing the device UP
> at the creation of network-namespace.

Hard coded in net/core/net_namespace.c:copy_net_ns is definitely the
wrong place in the code for something like this.  If this lives anywhere
it should live in driver/net/loopback.c, or possibly in
net/core/dev.c:net_dev_init.

If we want this we want to match what we do when we the primary network
namespace.  Just so that there are no unneeded surprises with network
namespaces.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: RFC: bring UP 'lo' by default after creating new netns
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30  6:26   ` Mahesh Bandewar (महेश बंडेवार)
  2017-06-30 12:38     ` Eric W. Biederman
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Mahesh Bandewar (महेश बंडेवार) @ 2017-06-30  6:26 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Eric Dumazet, adobriyan, David Miller, xiyou.wangcong, linux-netdev

On Thu, Jun 29, 2017 at 6:08 PM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> "Mahesh Bandewar (महेश बंडेवार)" <maheshb@google.com> writes:
>
>> Creation of new network namespace is almost always followed up by
>> bringing up the loopback device.
>>
>>         ip netns add foo
>>         ip -netns foo link set lo up
>>
>> I'm not sure if there are any consequences of bringing the device UP
>> at the creation of network-namespace.jjh
>
> Hard coded in net/core/net_namespace.c:copy_net_ns is definitely the
> wrong place in the code for something like this.  If this lives anywhere
> it should live in driver/net/loopback.c, or possibly in
> net/core/dev.c:net_dev_init.
>
interestingly dev_open() needs RTNL while it's not recommended at
net_dev_init() time.
Also net_dev_init() is called at the sub-system registration, do you
mean loopback_net_init() time?

> If we want this we want to match what we do when we the primary network
> namespace.  Just so that there are no unneeded surprises with network
> namespaces.
>
Yes, correct, it should be same whether it's init-net or some other. I
can add the IFF_UP flag during
loopback_setup() but then it will not perform anything that is done
during dev_open() phase. I'll try
moving the code to loopback_net_init() to achieve the same result so
that I can avoid that hard-coding too.

Thanks for comments Eric.

--mahesh..

> Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-06-30 12:38     ` Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:38 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Andrei Vagin, Greg KH, Pavel Emelyanov,
	linux-arch-u79uwXL29TY76Z2rM5mHXA, Michael Kerrisk, Matt Turner,
	Ivan Kokshaysky, Al Viro, Andy Lutomirski, Cyrill Gorcunov,
	Thomas Gleixner, Richard Henderson, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, Eric W. Biederman,
	linux-alpha-u79uwXL29TY76Z2rM5mHXA, Linus Torvalds,
	Willy Tarreau

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that alpha is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced during the 2.5 development cycle so this
mess has had a long time for people to be able to depend upon it.

Cc: Richard Henderson <rth-hL46jP5Bxq7R7s880joybQ@public.gmane.org>
Cc: Ivan Kokshaysky <ink-biIs/Y0ymYJMZLIVYojuPNP0rXTJTi09@public.gmane.org>
Cc: Matt Turner <mattst88-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-alpha-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
History Tree: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
Ref: 0a635c7a84cf ("Fill in siginfo_t.")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/alpha/include/uapi/asm/siginfo.h | 5 +++++
 arch/alpha/kernel/traps.c             | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/siginfo.h b/arch/alpha/include/uapi/asm/siginfo.h
index 9822362a8424..687e4972971b 100644
--- a/arch/alpha/include/uapi/asm/siginfo.h
+++ b/arch/alpha/include/uapi/asm/siginfo.h
@@ -6,4 +6,9 @@
 
 #include <asm-generic/siginfo.h>
 
+/*
+ * SIGTRAP si_codes
+ */
+#define TRAP_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102d985b..37c4fc91b215 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_FIXME;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 		}
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:38     ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                       ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that alpha is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced during the 2.5 development cycle so this
mess has had a long time for people to be able to depend upon it.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
History Tree: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
Ref: 0a635c7a84cf ("Fill in siginfo_t.")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/alpha/include/uapi/asm/siginfo.h | 5 +++++
 arch/alpha/kernel/traps.c             | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/siginfo.h b/arch/alpha/include/uapi/asm/siginfo.h
index 9822362a8424..687e4972971b 100644
--- a/arch/alpha/include/uapi/asm/siginfo.h
+++ b/arch/alpha/include/uapi/asm/siginfo.h
@@ -6,4 +6,9 @@
 
 #include <asm-generic/siginfo.h>
 
+/*
+ * SIGTRAP si_codes
+ */
+#define TRAP_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102d985b..37c4fc91b215 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_FIXME;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 		}
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
@ 2017-06-30 12:38     ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Richard Henderson,
	Ivan Kokshaysky, Matt

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that alpha is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced during the 2.5 development cycle so this
mess has had a long time for people to be able to depend upon it.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
History Tree: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git
Ref: 0a635c7a84cf ("Fill in siginfo_t.")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/alpha/include/uapi/asm/siginfo.h | 5 +++++
 arch/alpha/kernel/traps.c             | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/siginfo.h b/arch/alpha/include/uapi/asm/siginfo.h
index 9822362a8424..687e4972971b 100644
--- a/arch/alpha/include/uapi/asm/siginfo.h
+++ b/arch/alpha/include/uapi/asm/siginfo.h
@@ -6,4 +6,9 @@
 
 #include <asm-generic/siginfo.h>
 
+/*
+ * SIGTRAP si_codes
+ */
+#define TRAP_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif
diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102d985b..37c4fc91b215 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_FIXME;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_FIXME;
 			break;
 		}
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
  2017-06-30 12:38     ` [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 3/8] signal/sparc: " Eric W. Biederman
                       ` (5 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Fenghua Yu, Eric W. Biederman,
	linux-ia64-u79uwXL29TY76Z2rM5mHXA, Andrei Vagin, Greg KH,
	Linux Containers, Pavel Emelyanov, Oleg Nesterov, Tony Luck,
	Al Viro, Andy Lutomirski, linux-api-u79uwXL29TY76Z2rM5mHXA,
	Cyrill Gorcunov, Michael Kerrisk, Thomas Gleixner,
	Linus Torvalds, Willy Tarreau, Andrey Vagin

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that ia64 is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced in 2.3.51 so this mess has had a long time for
people to be able to start depending on it.

Cc: Tony Luck <tony.luck-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Fenghua Yu <fenghua.yu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: linux-ia64-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/ia64/include/uapi/asm/siginfo.h | 1 +
 arch/ia64/kernel/traps.c             | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h
index f72bf0172bb2..fafea221f49c 100644
--- a/arch/ia64/include/uapi/asm/siginfo.h
+++ b/arch/ia64/include/uapi/asm/siginfo.h
@@ -108,6 +108,7 @@ typedef struct siginfo {
 /*
  * SIGFPE si_codes
  */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
 #define __FPE_DECOVF	(__SI_FAULT|9)	/* decimal overflow */
 #define __FPE_DECDIV	(__SI_FAULT|10)	/* decimal division by zero */
 #define __FPE_DECERR	(__SI_FAULT|11)	/* packed decimal error */
diff --git a/arch/ia64/kernel/traps.c b/arch/ia64/kernel/traps.c
index 7b1fe9462158..3cb17cf9b362 100644
--- a/arch/ia64/kernel/traps.c
+++ b/arch/ia64/kernel/traps.c
@@ -349,7 +349,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			}
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x11) {
 				siginfo.si_code = FPE_FLTINV;
@@ -373,7 +373,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			/* raise exception */
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x880) {
 				siginfo.si_code = FPE_FLTOVF;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                       ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Tony Luck, Fenghua Yu,
	linux-ia64

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that ia64 is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced in 2.3.51 so this mess has had a long time for
people to be able to start depending on it.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/ia64/include/uapi/asm/siginfo.h | 1 +
 arch/ia64/kernel/traps.c             | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h
index f72bf0172bb2..fafea221f49c 100644
--- a/arch/ia64/include/uapi/asm/siginfo.h
+++ b/arch/ia64/include/uapi/asm/siginfo.h
@@ -108,6 +108,7 @@ typedef struct siginfo {
 /*
  * SIGFPE si_codes
  */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
 #define __FPE_DECOVF	(__SI_FAULT|9)	/* decimal overflow */
 #define __FPE_DECDIV	(__SI_FAULT|10)	/* decimal division by zero */
 #define __FPE_DECERR	(__SI_FAULT|11)	/* packed decimal error */
diff --git a/arch/ia64/kernel/traps.c b/arch/ia64/kernel/traps.c
index 7b1fe9462158..3cb17cf9b362 100644
--- a/arch/ia64/kernel/traps.c
+++ b/arch/ia64/kernel/traps.c
@@ -349,7 +349,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			}
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x11) {
 				siginfo.si_code = FPE_FLTINV;
@@ -373,7 +373,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			/* raise exception */
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x880) {
 				siginfo.si_code = FPE_FLTOVF;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 12:39     ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Tony Luck, Fenghua Yu,
	linux-ia64

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

Given that ia64 is on it's last legs I don't know that it is worth
fixing this, but it is worth documenting what is going on so that
no one decides to copy this bad decision.

This was introduced in 2.3.51 so this mess has had a long time for
people to be able to start depending on it.

Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: linux-ia64@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/ia64/include/uapi/asm/siginfo.h | 1 +
 arch/ia64/kernel/traps.c             | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h
index f72bf0172bb2..fafea221f49c 100644
--- a/arch/ia64/include/uapi/asm/siginfo.h
+++ b/arch/ia64/include/uapi/asm/siginfo.h
@@ -108,6 +108,7 @@ typedef struct siginfo {
 /*
  * SIGFPE si_codes
  */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
 #define __FPE_DECOVF	(__SI_FAULT|9)	/* decimal overflow */
 #define __FPE_DECDIV	(__SI_FAULT|10)	/* decimal division by zero */
 #define __FPE_DECERR	(__SI_FAULT|11)	/* packed decimal error */
diff --git a/arch/ia64/kernel/traps.c b/arch/ia64/kernel/traps.c
index 7b1fe9462158..3cb17cf9b362 100644
--- a/arch/ia64/kernel/traps.c
+++ b/arch/ia64/kernel/traps.c
@@ -349,7 +349,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			}
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x11) {
 				siginfo.si_code = FPE_FLTINV;
@@ -373,7 +373,7 @@ handle_fpu_swa (int fp_fault, struct pt_regs *regs, unsigned long isr)
 			/* raise exception */
 			siginfo.si_signo = SIGFPE;
 			siginfo.si_errno = 0;
-			siginfo.si_code = __SI_FAULT;	/* default code */
+			siginfo.si_code = FPE_FIXME;	/* default code */
 			siginfo.si_addr = (void __user *) (regs->cr_iip + ia64_psr(regs)->ri);
 			if (isr & 0x880) {
 				siginfo.si_code = FPE_FLTOVF;
-- 
2.10.1


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
  2017-06-30 12:38     ` [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 4/8] signal/mips: " Eric W. Biederman
                       ` (4 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman,
	Andrei Vagin, Greg KH, Linux Containers, Pavel Emelyanov,
	Oleg Nesterov, David S. Miller,
	sparclinux-u79uwXL29TY76Z2rM5mHXA, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Linus Torvalds, Willy Tarreau,
	Andrey Vagin

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This was introduced in 2.3.41 so this mess has had a long time for
people to be able to start depending on it.

As this bug has existed for 17 years already I don't know if it is
worth fixing.  It is definitely worth documenting what is going
on so that no one decides to copy this bad decision.

Cc: "David S. Miller" <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
Cc: sparclinux-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/sparc/include/uapi/asm/siginfo.h | 5 +++++
 arch/sparc/kernel/traps_32.c          | 2 +-
 arch/sparc/kernel/traps_64.c          | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
index 2d9b79ccaa50..6bc5c677e92f 100644
--- a/arch/sparc/include/uapi/asm/siginfo.h
+++ b/arch/sparc/include/uapi/asm/siginfo.h
@@ -17,6 +17,11 @@
 #define SI_NOINFO	32767		/* no information in siginfo_t */
 
 /*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
+/*
  * SIGEMT si_codes
  */
 #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
index 466d4aed06c7..581cf35ee7e3 100644
--- a/arch/sparc/kernel/traps_32.c
+++ b/arch/sparc/kernel/traps_32.c
@@ -306,7 +306,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 	info.si_errno = 0;
 	info.si_addr = (void __user *)pc;
 	info.si_trapno = 0;
-	info.si_code = __SI_FAULT;
+	info.si_code = FPE_FIXME;
 	if ((fsr & 0x1c000) == (1 << 14)) {
 		if (fsr & 0x10)
 			info.si_code = FPE_FLTINV;
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index 196ee5eb4d48..e882e128faa3 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -2258,7 +2258,7 @@ static void do_fpe_common(struct pt_regs *regs)
 		info.si_errno = 0;
 		info.si_addr = (void __user *)regs->tpc;
 		info.si_trapno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = FPE_FIXME;
 		if ((fsr & 0x1c000) == (1 << 14)) {
 			if (fsr & 0x10)
 				info.si_code = FPE_FLTINV;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                       ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, David S. Miller, sparclinux

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This was introduced in 2.3.41 so this mess has had a long time for
people to be able to start depending on it.

As this bug has existed for 17 years already I don't know if it is
worth fixing.  It is definitely worth documenting what is going
on so that no one decides to copy this bad decision.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/sparc/include/uapi/asm/siginfo.h | 5 +++++
 arch/sparc/kernel/traps_32.c          | 2 +-
 arch/sparc/kernel/traps_64.c          | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
index 2d9b79ccaa50..6bc5c677e92f 100644
--- a/arch/sparc/include/uapi/asm/siginfo.h
+++ b/arch/sparc/include/uapi/asm/siginfo.h
@@ -17,6 +17,11 @@
 #define SI_NOINFO	32767		/* no information in siginfo_t */
 
 /*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
+/*
  * SIGEMT si_codes
  */
 #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
index 466d4aed06c7..581cf35ee7e3 100644
--- a/arch/sparc/kernel/traps_32.c
+++ b/arch/sparc/kernel/traps_32.c
@@ -306,7 +306,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 	info.si_errno = 0;
 	info.si_addr = (void __user *)pc;
 	info.si_trapno = 0;
-	info.si_code = __SI_FAULT;
+	info.si_code = FPE_FIXME;
 	if ((fsr & 0x1c000) == (1 << 14)) {
 		if (fsr & 0x10)
 			info.si_code = FPE_FLTINV;
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index 196ee5eb4d48..e882e128faa3 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -2258,7 +2258,7 @@ static void do_fpe_common(struct pt_regs *regs)
 		info.si_errno = 0;
 		info.si_addr = (void __user *)regs->tpc;
 		info.si_trapno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = FPE_FIXME;
 		if ((fsr & 0x1c000) == (1 << 14)) {
 			if (fsr & 0x10)
 				info.si_code = FPE_FLTINV;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 12:39     ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, David S. Miller, sparclinux

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This was introduced in 2.3.41 so this mess has had a long time for
people to be able to start depending on it.

As this bug has existed for 17 years already I don't know if it is
worth fixing.  It is definitely worth documenting what is going
on so that no one decides to copy this bad decision.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/sparc/include/uapi/asm/siginfo.h | 5 +++++
 arch/sparc/kernel/traps_32.c          | 2 +-
 arch/sparc/kernel/traps_64.c          | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
index 2d9b79ccaa50..6bc5c677e92f 100644
--- a/arch/sparc/include/uapi/asm/siginfo.h
+++ b/arch/sparc/include/uapi/asm/siginfo.h
@@ -17,6 +17,11 @@
 #define SI_NOINFO	32767		/* no information in siginfo_t */
 
 /*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
+/*
  * SIGEMT si_codes
  */
 #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
index 466d4aed06c7..581cf35ee7e3 100644
--- a/arch/sparc/kernel/traps_32.c
+++ b/arch/sparc/kernel/traps_32.c
@@ -306,7 +306,7 @@ void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
 	info.si_errno = 0;
 	info.si_addr = (void __user *)pc;
 	info.si_trapno = 0;
-	info.si_code = __SI_FAULT;
+	info.si_code = FPE_FIXME;
 	if ((fsr & 0x1c000) = (1 << 14)) {
 		if (fsr & 0x10)
 			info.si_code = FPE_FLTINV;
diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
index 196ee5eb4d48..e882e128faa3 100644
--- a/arch/sparc/kernel/traps_64.c
+++ b/arch/sparc/kernel/traps_64.c
@@ -2258,7 +2258,7 @@ static void do_fpe_common(struct pt_regs *regs)
 		info.si_errno = 0;
 		info.si_addr = (void __user *)regs->tpc;
 		info.si_trapno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = FPE_FIXME;
 		if ((fsr & 0x1c000) = (1 << 14)) {
 			if (fsr & 0x10)
 				info.si_code = FPE_FLTINV;
-- 
2.10.1


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 4/8] signal/mips: Document a conflict with SI_USER with SIGFPE
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
                       ` (2 preceding siblings ...)
  2017-06-30 12:39     ` [PATCH 3/8] signal/sparc: " Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39       ` Eric W. Biederman
                       ` (3 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Thiemo Seufer,
	Eric W. Biederman, Andrei Vagin, Greg KH, Linux Containers,
	Pavel Emelyanov, Oleg Nesterov, Ralf Baechle, Al Viro,
	Andy Lutomirski, linux-api-u79uwXL29TY76Z2rM5mHXA,
	Cyrill Gorcunov, Michael Kerrisk, Thomas Gleixner,
	Linus Torvalds, Willy Tarreau, Andrey Vagin

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This use of of __SI_FAULT is only a decade old.  Which compared
to the other pieces of kernel code that has made this mistake
is almost yesterday.

This is probably worth fixing but I don't know mips well enough
to know what si_code to would be the proper one to use.

Cc: Thiemo Seufer <ths-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>
Cc: Ralf Baechle <ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>
Ref: 948a34cf3988 ("[MIPS] Maintain si_code field properly for FP exceptions")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/mips/include/uapi/asm/siginfo.h | 5 +++++
 arch/mips/kernel/traps.c             | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/uapi/asm/siginfo.h b/arch/mips/include/uapi/asm/siginfo.h
index 8069cf766603..0d80df888325 100644
--- a/arch/mips/include/uapi/asm/siginfo.h
+++ b/arch/mips/include/uapi/asm/siginfo.h
@@ -123,4 +123,9 @@ typedef struct siginfo {
 #define SI_TIMER __SI_CODE(__SI_TIMER, -3) /* sent by timer expiration */
 #define SI_MESGQ __SI_CODE(__SI_MESGQ, -4) /* sent by real time mesq state change */
 
+/*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif /* _UAPI_ASM_SIGINFO_H */
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 9681b5877140..477dfca99147 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -732,7 +732,7 @@ void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
 	else if (fcr31 & FPU_CSR_INE_X)
 		si.si_code = FPE_FLTRES;
 	else
-		si.si_code = __SI_FAULT;
+		si.si_code = FPE_FIXME;
 	force_sig_info(SIGFPE, &si, tsk);
 }
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 4/8] signal/mips: Document a conflict with SI_USER with SIGFPE
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Thiemo Seufer, Ralf Baechle

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This use of of __SI_FAULT is only a decade old.  Which compared
to the other pieces of kernel code that has made this mistake
is almost yesterday.

This is probably worth fixing but I don't know mips well enough
to know what si_code to would be the proper one to use.

Cc: Thiemo Seufer <ths@linux-mips.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Ref: 948a34cf3988 ("[MIPS] Maintain si_code field properly for FP exceptions")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/mips/include/uapi/asm/siginfo.h | 5 +++++
 arch/mips/kernel/traps.c             | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/uapi/asm/siginfo.h b/arch/mips/include/uapi/asm/siginfo.h
index 8069cf766603..0d80df888325 100644
--- a/arch/mips/include/uapi/asm/siginfo.h
+++ b/arch/mips/include/uapi/asm/siginfo.h
@@ -123,4 +123,9 @@ typedef struct siginfo {
 #define SI_TIMER __SI_CODE(__SI_TIMER, -3) /* sent by timer expiration */
 #define SI_MESGQ __SI_CODE(__SI_MESGQ, -4) /* sent by real time mesq state change */
 
+/*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif /* _UAPI_ASM_SIGINFO_H */
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 9681b5877140..477dfca99147 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -732,7 +732,7 @@ void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
 	else if (fcr31 & FPU_CSR_INE_X)
 		si.si_code = FPE_FLTRES;
 	else
-		si.si_code = __SI_FAULT;
+		si.si_code = FPE_FIXME;
 	force_sig_info(SIGFPE, &si, tsk);
 }
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 4/8] signal/mips: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 12:39     ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch-u79uwXL29TY76Z2rM5mHXA,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Thiemo Seufer, Ralf Baechle

Setting si_code to __SI_FAULT results in a userspace seeing
an si_code of 0.  This is the same si_code as SI_USER.  Posix
and common sense requires that SI_USER not be a signal specific
si_code.  As such this use of 0 for the si_code is a pretty
horribly broken ABI.

This use of of __SI_FAULT is only a decade old.  Which compared
to the other pieces of kernel code that has made this mistake
is almost yesterday.

This is probably worth fixing but I don't know mips well enough
to know what si_code to would be the proper one to use.

Cc: Thiemo Seufer <ths-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>
Cc: Ralf Baechle <ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>
Ref: 948a34cf3988 ("[MIPS] Maintain si_code field properly for FP exceptions")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/mips/include/uapi/asm/siginfo.h | 5 +++++
 arch/mips/kernel/traps.c             | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/uapi/asm/siginfo.h b/arch/mips/include/uapi/asm/siginfo.h
index 8069cf766603..0d80df888325 100644
--- a/arch/mips/include/uapi/asm/siginfo.h
+++ b/arch/mips/include/uapi/asm/siginfo.h
@@ -123,4 +123,9 @@ typedef struct siginfo {
 #define SI_TIMER __SI_CODE(__SI_TIMER, -3) /* sent by timer expiration */
 #define SI_MESGQ __SI_CODE(__SI_MESGQ, -4) /* sent by real time mesq state change */
 
+/*
+ * SIGFPE si_codes
+ */
+#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+
 #endif /* _UAPI_ASM_SIGINFO_H */
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index 9681b5877140..477dfca99147 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -732,7 +732,7 @@ void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
 	else if (fcr31 & FPU_CSR_INE_X)
 		si.si_code = FPE_FLTRES;
 	else
-		si.si_code = __SI_FAULT;
+		si.si_code = FPE_FIXME;
 	force_sig_info(SIGFPE, &si, tsk);
 }
 
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 5/8] signal/testing: Don't look for __SI_FAULT in userspace
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:39       ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                         ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman,
	Andrei Vagin, Greg KH, Linux Containers, Dave Hansen,
	Pavel Emelyanov, Oleg Nesterov, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Linus Torvalds, Willy Tarreau,
	Andrey Vagin

Fix the debug print statements in these tests where they reference
si_codes and in particular __SI_FAULT.  __SI_FAULT is a kernel
internal value and should never be seen by userspace.

While I am in there also fix si_code_str.  si_codes are an enumeration
there are not a bitmap so == and not & is the apropriate operation to
test for an si_code.

Cc: Dave Hansen <dave.hansen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Fixes: 5f23f6d082a9 ("x86/pkeys: Add self-tests")
Fixes: e754aedc26ef ("x86/mpx, selftests: Add MPX self test")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 tools/testing/selftests/x86/mpx-mini-test.c   |  3 +--
 tools/testing/selftests/x86/protection_keys.c | 13 ++++++-------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c
index a8df159a8924..ec0f6b45ce8b 100644
--- a/tools/testing/selftests/x86/mpx-mini-test.c
+++ b/tools/testing/selftests/x86/mpx-mini-test.c
@@ -391,8 +391,7 @@ void handler(int signum, siginfo_t *si, void *vucontext)
 		br_count++;
 		dprintf1("#BR 0x%jx (total seen: %d)\n", status, br_count);
 
-#define __SI_FAULT      (3 << 16)
-#define SEGV_BNDERR     (__SI_FAULT|3)  /* failed address bound checks */
+#define SEGV_BNDERR     3  /* failed address bound checks */
 
 		dprintf2("Saw a #BR! status 0x%jx at %016lx br_reason: %jx\n",
 				status, ip, br_reason);
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index 3237bc010e1c..23927845518d 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -212,19 +212,18 @@ void dump_mem(void *dumpme, int len_bytes)
 	}
 }
 
-#define __SI_FAULT      (3 << 16)
-#define SEGV_BNDERR     (__SI_FAULT|3)  /* failed address bound checks */
-#define SEGV_PKUERR     (__SI_FAULT|4)
+#define SEGV_BNDERR     3  /* failed address bound checks */
+#define SEGV_PKUERR     4
 
 static char *si_code_str(int si_code)
 {
-	if (si_code & SEGV_MAPERR)
+	if (si_code == SEGV_MAPERR)
 		return "SEGV_MAPERR";
-	if (si_code & SEGV_ACCERR)
+	if (si_code == SEGV_ACCERR)
 		return "SEGV_ACCERR";
-	if (si_code & SEGV_BNDERR)
+	if (si_code == SEGV_BNDERR)
 		return "SEGV_BNDERR";
-	if (si_code & SEGV_PKUERR)
+	if (si_code == SEGV_PKUERR)
 		return "SEGV_PKUERR";
 	return "UNKNOWN";
 }
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 5/8] signal/testing: Don't look for __SI_FAULT in userspace
@ 2017-06-30 12:39       ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Dave Hansen

Fix the debug print statements in these tests where they reference
si_codes and in particular __SI_FAULT.  __SI_FAULT is a kernel
internal value and should never be seen by userspace.

While I am in there also fix si_code_str.  si_codes are an enumeration
there are not a bitmap so == and not & is the apropriate operation to
test for an si_code.

Cc: Dave Hansen <dave.hansen@linux.intel.com>
Fixes: 5f23f6d082a9 ("x86/pkeys: Add self-tests")
Fixes: e754aedc26ef ("x86/mpx, selftests: Add MPX self test")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 tools/testing/selftests/x86/mpx-mini-test.c   |  3 +--
 tools/testing/selftests/x86/protection_keys.c | 13 ++++++-------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/x86/mpx-mini-test.c b/tools/testing/selftests/x86/mpx-mini-test.c
index a8df159a8924..ec0f6b45ce8b 100644
--- a/tools/testing/selftests/x86/mpx-mini-test.c
+++ b/tools/testing/selftests/x86/mpx-mini-test.c
@@ -391,8 +391,7 @@ void handler(int signum, siginfo_t *si, void *vucontext)
 		br_count++;
 		dprintf1("#BR 0x%jx (total seen: %d)\n", status, br_count);
 
-#define __SI_FAULT      (3 << 16)
-#define SEGV_BNDERR     (__SI_FAULT|3)  /* failed address bound checks */
+#define SEGV_BNDERR     3  /* failed address bound checks */
 
 		dprintf2("Saw a #BR! status 0x%jx at %016lx br_reason: %jx\n",
 				status, ip, br_reason);
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index 3237bc010e1c..23927845518d 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -212,19 +212,18 @@ void dump_mem(void *dumpme, int len_bytes)
 	}
 }
 
-#define __SI_FAULT      (3 << 16)
-#define SEGV_BNDERR     (__SI_FAULT|3)  /* failed address bound checks */
-#define SEGV_PKUERR     (__SI_FAULT|4)
+#define SEGV_BNDERR     3  /* failed address bound checks */
+#define SEGV_PKUERR     4
 
 static char *si_code_str(int si_code)
 {
-	if (si_code & SEGV_MAPERR)
+	if (si_code == SEGV_MAPERR)
 		return "SEGV_MAPERR";
-	if (si_code & SEGV_ACCERR)
+	if (si_code == SEGV_ACCERR)
 		return "SEGV_ACCERR";
-	if (si_code & SEGV_BNDERR)
+	if (si_code == SEGV_BNDERR)
 		return "SEGV_BNDERR";
-	if (si_code & SEGV_PKUERR)
+	if (si_code == SEGV_PKUERR)
 		return "SEGV_PKUERR";
 	return "UNKNOWN";
 }
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 6/8] signal/x86: Fix SIGSYS handling in copy_siginfo_to_user32
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
                       ` (4 preceding siblings ...)
  2017-06-30 12:39       ` Eric W. Biederman
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39       ` Eric W. Biederman
  2017-06-30 12:39       ` Eric W. Biederman
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Andrei Vagin, Greg KH, H . Peter Anvin, Pavel Emelyanov,
	linux-arch-u79uwXL29TY76Z2rM5mHXA, Michael Kerrisk,
	Andy Lutomirski, Al Viro, James Morris, Cyrill Gorcunov,
	Thomas Gleixner, Will Drewry, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, Eric Paris, Eric W. Biederman, Linus Torvalds,
	Willy Tarreau

While examining the code I realized that we don't copy si_call_addr to
32bit callers.  Fix it.

It looks like no one has used this code path in the last 5 years.

Cc: Will Drewry <wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: H. Peter Anvin <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
Cc: Eric Paris <eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: Serge Hallyn <serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
Cc: James Morris <james.l.morris-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Fixes: a0727e8ce513 ("signal, x86: add SIGSYS info and make it synchronous.")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/x86/kernel/signal_compat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index 71beb28600d4..59e1029bb3d0 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -161,6 +161,7 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 				}
 				break;
 			case __SI_SYS >> 16:
+				put_user_ex(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 				put_user_ex(from->si_syscall, &to->si_syscall);
 				put_user_ex(from->si_arch, &to->si_arch);
 				break;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 6/8] signal/x86: Fix SIGSYS handling in copy_siginfo_to_user32
       [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-06-30 12:39     ` Eric W. Biederman
  2017-06-30 12:39     ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
                       ` (6 subsequent siblings)
  7 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Will Drewry, H . Peter Anvin,
	Eric Paris, James Morris

While examining the code I realized that we don't copy si_call_addr to
32bit callers.  Fix it.

It looks like no one has used this code path in the last 5 years.

Cc: Will Drewry <wad@chromium.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Eric Paris <eparis@redhat.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: James Morris <james.l.morris@oracle.com>
Fixes: a0727e8ce513 ("signal, x86: add SIGSYS info and make it synchronous.")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/x86/kernel/signal_compat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index 71beb28600d4..59e1029bb3d0 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -161,6 +161,7 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 				}
 				break;
 			case __SI_SYS >> 16:
+				put_user_ex(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 				put_user_ex(from->si_syscall, &to->si_syscall);
 				put_user_ex(from->si_arch, &to->si_arch);
 				break;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 6/8] signal/x86: Fix SIGSYS handling in copy_siginfo_to_user32
@ 2017-06-30 12:39     ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch-u79uwXL29TY76Z2rM5mHXA,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Michael Kerrisk, Eric W. Biederman, Will Drewry, H . Peter Anvin,
	Eric Paris

While examining the code I realized that we don't copy si_call_addr to
32bit callers.  Fix it.

It looks like no one has used this code path in the last 5 years.

Cc: Will Drewry <wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: H. Peter Anvin <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
Cc: Eric Paris <eparis-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: Serge Hallyn <serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
Cc: James Morris <james.l.morris-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Fixes: a0727e8ce513 ("signal, x86: add SIGSYS info and make it synchronous.")
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/x86/kernel/signal_compat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index 71beb28600d4..59e1029bb3d0 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -161,6 +161,7 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 				}
 				break;
 			case __SI_SYS >> 16:
+				put_user_ex(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 				put_user_ex(from->si_syscall, &to->si_syscall);
 				put_user_ex(from->si_arch, &to->si_arch);
 				break;
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 7/8] fcntl: Don't use ambiguous SIG_POLL si_codes
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:39       ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                         ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman,
	Andrei Vagin, Greg KH, Linux Containers, Pavel Emelyanov,
	Oleg Nesterov, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Linus Torvalds, Willy Tarreau,
	Andrey Vagin

We have a weird and problematic intersection of features that when
they all come together result in ambiguous siginfo values, that
we can not support properly.

- Supporting fcntl(F_SETSIG,...) with arbitrary valid signals.

- Using positive values for POLL_IN, POLL_OUT, POLL_MSG, ..., etc
  that imply they are signal specific si_codes and using the
  aforementioned arbitrary signal to deliver them.

- Supporting injection of arbitrary siginfo values for debugging and
  checkpoint/restore.

The result is that just looking at siginfo si_codes of 1 to 6 are
ambigious.  It could either be a signal specific si_code or it could
be a generic si_code.

For most of the kernel this is a non-issue but for sending signals
with siginfo it is impossible to play back the kernel signals and
get the same result.

Strictly speaking when the si_code was changed from SI_SIGIO to
POLL_IN and friends between 2.2 and 2.4 this functionality was not
ambiguous, as only real time signals were supported.  Before 2.4 was
released the kernel began supporting siginfo with non realtime signals
so they could give details of why the signal was sent.

The result is that if F_SETSIG is set to one of the signals with signal
specific si_codes then user space can not know why the signal was sent.

I grepped through a bunch of userspace programs using debian code
search to get a feel for how often people choose a signal that results
in an ambiguous si_code.  I only found one program doing so and it was
using SIGCHLD to test the F_SETSIG functionality, and did not appear
to be a real world usage.

Therefore the ambiguity does not appears to be a real world problem in
practice.  Remove the ambiguity while introducing the smallest chance
of breakage by changing the si_code to SI_SIGIO when signals with
signal specific si_codes are targeted.

Fixes: v2.3.40 -- Added support for queueing non-rt signals
Fixes: v2.3.21 -- Changed the si_code from SI_SIGIO
Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 fs/fcntl.c                         | 11 +++++++++++
 include/linux/signal.h             |  8 ++++++++
 include/uapi/asm-generic/siginfo.h |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/fs/fcntl.c b/fs/fcntl.c
index f4e7267d117f..3c4e17b0082a 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -629,6 +629,17 @@ static void send_sigio_to_task(struct task_struct *p,
 			si.si_signo = signum;
 			si.si_errno = 0;
 		        si.si_code  = reason;
+			/*
+			 * Posix definies POLL_IN and friends to be signal
+			 * specific si_codes for SIG_POLL.  Linux extended
+			 * these si_codes to other signals in a way that is
+			 * ambiguous if other signals also have signal
+			 * specific si_codes.  In that case use SI_SIGIO instead
+			 * to remove the ambiguity.
+			 */
+			if (sig_specific_sicodes(signum))
+				si.si_code = SI_SIGIO;
+
 			/* Make sure we are called with one of the POLL_*
 			   reasons, otherwise we could leak kernel stack into
 			   userspace.  */
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 1f5a16620693..76aff5b861d2 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -385,10 +385,18 @@ int unhandled_signal(struct task_struct *tsk, int sig);
         rt_sigmask(SIGCONT)   |  rt_sigmask(SIGCHLD)   | \
 	rt_sigmask(SIGWINCH)  |  rt_sigmask(SIGURG)    )
 
+#define SIG_SPECIFIC_SICODES_MASK (\
+	rt_sigmask(SIGILL)    |  rt_sigmask(SIGFPE)    | \
+	rt_sigmask(SIGSEGV)   |  rt_sigmask(SIGBUS)    | \
+	rt_sigmask(SIGTRAP)   |  rt_sigmask(SIGCHLD)   | \
+	rt_sigmask(SIGPOLL)   |  rt_sigmask(SIGSYS)    | \
+	SIGEMT_MASK                                    )
+
 #define sig_kernel_only(sig)		siginmask(sig, SIG_KERNEL_ONLY_MASK)
 #define sig_kernel_coredump(sig)	siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
 #define sig_kernel_ignore(sig)		siginmask(sig, SIG_KERNEL_IGNORE_MASK)
 #define sig_kernel_stop(sig)		siginmask(sig, SIG_KERNEL_STOP_MASK)
+#define sig_specific_sicodes(sig)	siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
 
 #define sig_fatal(t, signr) \
 	(!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index 1abaf62c86fc..e1081a6d842b 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -248,7 +248,7 @@ typedef struct siginfo {
 #define NSIGCHLD	6
 
 /*
- * SIGPOLL si_codes
+ * SIGPOLL (or any other signal without signal specific si_codes) si_codes
  */
 #define POLL_IN		(__SI_POLL|1)	/* data input available */
 #define POLL_OUT	(__SI_POLL|2)	/* output buffers available */
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 7/8] fcntl: Don't use ambiguous SIG_POLL si_codes
@ 2017-06-30 12:39       ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman

We have a weird and problematic intersection of features that when
they all come together result in ambiguous siginfo values, that
we can not support properly.

- Supporting fcntl(F_SETSIG,...) with arbitrary valid signals.

- Using positive values for POLL_IN, POLL_OUT, POLL_MSG, ..., etc
  that imply they are signal specific si_codes and using the
  aforementioned arbitrary signal to deliver them.

- Supporting injection of arbitrary siginfo values for debugging and
  checkpoint/restore.

The result is that just looking at siginfo si_codes of 1 to 6 are
ambigious.  It could either be a signal specific si_code or it could
be a generic si_code.

For most of the kernel this is a non-issue but for sending signals
with siginfo it is impossible to play back the kernel signals and
get the same result.

Strictly speaking when the si_code was changed from SI_SIGIO to
POLL_IN and friends between 2.2 and 2.4 this functionality was not
ambiguous, as only real time signals were supported.  Before 2.4 was
released the kernel began supporting siginfo with non realtime signals
so they could give details of why the signal was sent.

The result is that if F_SETSIG is set to one of the signals with signal
specific si_codes then user space can not know why the signal was sent.

I grepped through a bunch of userspace programs using debian code
search to get a feel for how often people choose a signal that results
in an ambiguous si_code.  I only found one program doing so and it was
using SIGCHLD to test the F_SETSIG functionality, and did not appear
to be a real world usage.

Therefore the ambiguity does not appears to be a real world problem in
practice.  Remove the ambiguity while introducing the smallest chance
of breakage by changing the si_code to SI_SIGIO when signals with
signal specific si_codes are targeted.

Fixes: v2.3.40 -- Added support for queueing non-rt signals
Fixes: v2.3.21 -- Changed the si_code from SI_SIGIO
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 fs/fcntl.c                         | 11 +++++++++++
 include/linux/signal.h             |  8 ++++++++
 include/uapi/asm-generic/siginfo.h |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/fs/fcntl.c b/fs/fcntl.c
index f4e7267d117f..3c4e17b0082a 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -629,6 +629,17 @@ static void send_sigio_to_task(struct task_struct *p,
 			si.si_signo = signum;
 			si.si_errno = 0;
 		        si.si_code  = reason;
+			/*
+			 * Posix definies POLL_IN and friends to be signal
+			 * specific si_codes for SIG_POLL.  Linux extended
+			 * these si_codes to other signals in a way that is
+			 * ambiguous if other signals also have signal
+			 * specific si_codes.  In that case use SI_SIGIO instead
+			 * to remove the ambiguity.
+			 */
+			if (sig_specific_sicodes(signum))
+				si.si_code = SI_SIGIO;
+
 			/* Make sure we are called with one of the POLL_*
 			   reasons, otherwise we could leak kernel stack into
 			   userspace.  */
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 1f5a16620693..76aff5b861d2 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -385,10 +385,18 @@ int unhandled_signal(struct task_struct *tsk, int sig);
         rt_sigmask(SIGCONT)   |  rt_sigmask(SIGCHLD)   | \
 	rt_sigmask(SIGWINCH)  |  rt_sigmask(SIGURG)    )
 
+#define SIG_SPECIFIC_SICODES_MASK (\
+	rt_sigmask(SIGILL)    |  rt_sigmask(SIGFPE)    | \
+	rt_sigmask(SIGSEGV)   |  rt_sigmask(SIGBUS)    | \
+	rt_sigmask(SIGTRAP)   |  rt_sigmask(SIGCHLD)   | \
+	rt_sigmask(SIGPOLL)   |  rt_sigmask(SIGSYS)    | \
+	SIGEMT_MASK                                    )
+
 #define sig_kernel_only(sig)		siginmask(sig, SIG_KERNEL_ONLY_MASK)
 #define sig_kernel_coredump(sig)	siginmask(sig, SIG_KERNEL_COREDUMP_MASK)
 #define sig_kernel_ignore(sig)		siginmask(sig, SIG_KERNEL_IGNORE_MASK)
 #define sig_kernel_stop(sig)		siginmask(sig, SIG_KERNEL_STOP_MASK)
+#define sig_specific_sicodes(sig)	siginmask(sig, SIG_SPECIFIC_SICODES_MASK)
 
 #define sig_fatal(t, signr) \
 	(!siginmask(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index 1abaf62c86fc..e1081a6d842b 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -248,7 +248,7 @@ typedef struct siginfo {
 #define NSIGCHLD	6
 
 /*
- * SIGPOLL si_codes
+ * SIGPOLL (or any other signal without signal specific si_codes) si_codes
  */
 #define POLL_IN		(__SI_POLL|1)	/* data input available */
 #define POLL_OUT	(__SI_POLL|2)	/* output buffers available */
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 8/8] signal: Remove kernel interal si_code magic
  2017-06-30  1:08 ` Eric W. Biederman
@ 2017-06-30 12:39       ` Eric W. Biederman
  2017-06-30 12:38     ` Eric W. Biederman
                         ` (5 subsequent siblings)
  6 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman,
	Andrei Vagin, Greg KH, Linux Containers, Pavel Emelyanov,
	Oleg Nesterov, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Linus Torvalds, Willy Tarreau,
	Andrey Vagin

struct siginfo is a union and the kernel since 2.4 has been hiding a union
tag in the high 16bits of si_code using the values:
__SI_KILL
__SI_TIMER
__SI_POLL
__SI_FAULT
__SI_CHLD
__SI_RT
__SI_MESGQ
__SI_SYS

While this looks plausible on the surface, in practice this situation has
not worked well.

- Injected positive signals are not copied to user space properly
  unless they have these magic high bits set.

- Injected positive signals are not reported properly by signalfd
  unless they have these magic high bits set.

- These kernel internal values leaked to userspace via ptrace_peek_siginfo

- It was possible to inject these kernel internal values and cause the
  the kernel to misbehave.

- Kernel developers got confused and expected these kernel internal values
  in userspace in kernel self tests.

- Kernel developers got confused and set si_code to __SI_FAULT which
  is SI_USER in userspace which causes userspace to think an ordinary user
  sent the signal and that it was not kernel generated.

- The values make it impossible to reorganize the code to transform
  siginfo_copy_to_user into a plain copy_to_user.  As si_code must
  be massaged before being passed to userspace.

So remove these kernel internal si codes and make the kernel code simpler
and more maintainable.

To replace these kernel internal magic si_codes introduce the helper
function siginfo_layout, that takes a signal number and an si_code and
computes which union member of siginfo is being used.  Have
siginfo_layout return an enumeration so that gcc will have enough
information to warn if a switch statement does not handle all of union
members.

A couple of architectures have a messed up ABI that defines signal
specific duplications of SI_USER which causes more special cases in
siginfo_layout than I would like.  The good news is only problem
architectures pay the cost.

Update all of the code that used the previous magic __SI_ values to
use the new SIL_ values and to call siginfo_layout to get those
values.  Escept where not all of the cases are handled remove the
defaults in the switch statements so that if a new case is missed in
the future the lack will show up at compile time.

Modify the code that copies siginfo si_code to userspace to just copy
the value and not cast si_code to a short first.  The high bits are no
longer used to hold a magic union member.

Fixup the siginfo header files to stop including the __SI_ values in
their constants and for the headers that were missing it to properly
update the number of si_codes for each signal type.

The fixes to copy_siginfo_from_user32 implementations has the
interesting property that several of them perviously should never have
worked as the __SI_ values they depended up where kernel internal.
With that dependency gone those implementations should work much
better.

The idea of not passing the __SI_ values out to userspace and then
not reinserting them has been tested with criu and criu worked without
changes.

Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
---
 arch/alpha/include/uapi/asm/siginfo.h    |   2 +-
 arch/arm64/kernel/signal32.c             |  23 +++----
 arch/blackfin/include/uapi/asm/siginfo.h |  30 +++++----
 arch/frv/include/uapi/asm/siginfo.h      |   2 +-
 arch/ia64/include/uapi/asm/siginfo.h     |  20 +++---
 arch/ia64/kernel/signal.c                |  17 +++---
 arch/mips/include/uapi/asm/siginfo.h     |   6 +-
 arch/mips/kernel/signal32.c              |  19 +++---
 arch/parisc/kernel/signal32.c            |  31 +++++-----
 arch/powerpc/kernel/signal_32.c          |  20 +++---
 arch/s390/kernel/compat_signal.c         |  32 +++++-----
 arch/sparc/include/uapi/asm/siginfo.h    |   4 +-
 arch/sparc/kernel/signal32.c             |  16 ++---
 arch/tile/include/uapi/asm/siginfo.h     |   4 +-
 arch/tile/kernel/compat_signal.c         |  18 +++---
 arch/tile/kernel/traps.c                 |   1 -
 arch/x86/kernel/signal_compat.c          |  21 +++----
 fs/fcntl.c                               |   2 +-
 fs/signalfd.c                            |  22 +++----
 include/asm-generic/siginfo.h            |  22 ++++---
 include/uapi/asm-generic/siginfo.h       | 102 ++++++++++++++-----------------
 kernel/compat.c                          |   2 -
 kernel/exit.c                            |   6 +-
 kernel/ptrace.c                          |   6 +-
 kernel/signal.c                          |  72 ++++++++++++++++------
 25 files changed, 254 insertions(+), 246 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/siginfo.h b/arch/alpha/include/uapi/asm/siginfo.h
index 687e4972971b..b6ff539ff426 100644
--- a/arch/alpha/include/uapi/asm/siginfo.h
+++ b/arch/alpha/include/uapi/asm/siginfo.h
@@ -9,6 +9,6 @@
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define TRAP_FIXME	0	/* Broken dup of SI_USER */
 
 #endif
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index c747a0fc5d7d..9b95a935c21d 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -142,25 +142,25 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	 */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad,
 				      SI_PAD_SIZE);
-	else switch (from->si_code & __SI_MASK) {
-	case __SI_KILL:
+	else switch (siginfo_layout(from->si_signo, from->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		break;
-	case __SI_TIMER:
+	case SIL_TIMER:
 		 err |= __put_user(from->si_tid, &to->si_tid);
 		 err |= __put_user(from->si_overrun, &to->si_overrun);
 		 err |= __put_user(from->si_int, &to->si_int);
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(from->si_band, &to->si_band);
 		err |= __put_user(from->si_fd, &to->si_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
 				  &to->si_addr);
 #ifdef BUS_MCEERR_AO
@@ -173,29 +173,24 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 			err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_status, &to->si_status);
 		err |= __put_user(from->si_utime, &to->si_utime);
 		err |= __put_user(from->si_stime, &to->si_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
+	case SIL_RT:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_int, &to->si_int);
 		break;
-	case __SI_SYS:
+	case SIL_SYS:
 		err |= __put_user((compat_uptr_t)(unsigned long)
 				from->si_call_addr, &to->si_call_addr);
 		err |= __put_user(from->si_syscall, &to->si_syscall);
 		err |= __put_user(from->si_arch, &to->si_arch);
 		break;
-	default: /* this is just in case for now ... */
-		err |= __put_user(from->si_pid, &to->si_pid);
-		err |= __put_user(from->si_uid, &to->si_uid);
-		break;
 	}
 	return err;
 }
diff --git a/arch/blackfin/include/uapi/asm/siginfo.h b/arch/blackfin/include/uapi/asm/siginfo.h
index c72f4e6e386f..79dfe3979123 100644
--- a/arch/blackfin/include/uapi/asm/siginfo.h
+++ b/arch/blackfin/include/uapi/asm/siginfo.h
@@ -14,28 +14,36 @@
 
 #define si_uid16	_sifields._kill._uid
 
-#define ILL_ILLPARAOP	(__SI_FAULT|2)	/* illegal opcode combine ********** */
-#define ILL_ILLEXCPT	(__SI_FAULT|4)	/* unrecoverable exception ********** */
-#define ILL_CPLB_VI	(__SI_FAULT|9)	/* D/I CPLB protect violation ******** */
-#define ILL_CPLB_MISS	(__SI_FAULT|10)	/* D/I CPLB miss ******** */
-#define ILL_CPLB_MULHIT	(__SI_FAULT|11)	/* D/I CPLB multiple hit ******** */
+#define ILL_ILLPARAOP	2	/* illegal opcode combine ********** */
+#define ILL_ILLEXCPT	4	/* unrecoverable exception ********** */
+#define ILL_CPLB_VI	9	/* D/I CPLB protect violation ******** */
+#define ILL_CPLB_MISS	10	/* D/I CPLB miss ******** */
+#define ILL_CPLB_MULHIT	11	/* D/I CPLB multiple hit ******** */
+#undef NSIGILL
+#define NSIGILL         11
 
 /*
  * SIGBUS si_codes
  */
-#define BUS_OPFETCH	(__SI_FAULT|4)	/* error from instruction fetch ******** */
+#define BUS_OPFETCH	4	/* error from instruction fetch ******** */
+#undef NSIGBUS
+#define NSIGBUS		4
 
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_STEP	(__SI_FAULT|1)	/* single-step breakpoint************* */
-#define TRAP_TRACEFLOW	(__SI_FAULT|2)	/* trace buffer overflow ************* */
-#define TRAP_WATCHPT	(__SI_FAULT|3)	/* watchpoint match      ************* */
-#define TRAP_ILLTRAP	(__SI_FAULT|4)	/* illegal trap          ************* */
+#define TRAP_STEP	1	/* single-step breakpoint************* */
+#define TRAP_TRACEFLOW	2	/* trace buffer overflow ************* */
+#define TRAP_WATCHPT	3	/* watchpoint match      ************* */
+#define TRAP_ILLTRAP	4	/* illegal trap          ************* */
+#undef NSIGTRAP
+#define NSIGTRAP	4
 
 /*
  * SIGSEGV si_codes
  */
-#define SEGV_STACKFLOW	(__SI_FAULT|3)	/* stack overflow */
+#define SEGV_STACKFLOW	3	/* stack overflow */
+#undef NSIGSEGV
+#define NSIGSEGV	3
 
 #endif /* _UAPI_BFIN_SIGINFO_H */
diff --git a/arch/frv/include/uapi/asm/siginfo.h b/arch/frv/include/uapi/asm/siginfo.h
index d3fd1ca45653..f55d9e0e9068 100644
--- a/arch/frv/include/uapi/asm/siginfo.h
+++ b/arch/frv/include/uapi/asm/siginfo.h
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 #include <asm-generic/siginfo.h>
 
-#define FPE_MDAOVF	(__SI_FAULT|9)	/* media overflow */
+#define FPE_MDAOVF	9	/* media overflow */
 #undef NSIGFPE
 #define NSIGFPE		9
 
diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h
index fafea221f49c..c3aaaee01dcb 100644
--- a/arch/ia64/include/uapi/asm/siginfo.h
+++ b/arch/ia64/include/uapi/asm/siginfo.h
@@ -99,28 +99,28 @@ typedef struct siginfo {
 /*
  * SIGILL si_codes
  */
-#define ILL_BADIADDR	(__SI_FAULT|9)	/* unimplemented instruction address */
-#define __ILL_BREAK	(__SI_FAULT|10)	/* illegal break */
-#define __ILL_BNDMOD	(__SI_FAULT|11)	/* bundle-update (modification) in progress */
+#define ILL_BADIADDR	9	/* unimplemented instruction address */
+#define __ILL_BREAK	10	/* illegal break */
+#define __ILL_BNDMOD	11	/* bundle-update (modification) in progress */
 #undef NSIGILL
 #define NSIGILL		11
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
-#define __FPE_DECOVF	(__SI_FAULT|9)	/* decimal overflow */
-#define __FPE_DECDIV	(__SI_FAULT|10)	/* decimal division by zero */
-#define __FPE_DECERR	(__SI_FAULT|11)	/* packed decimal error */
-#define __FPE_INVASC	(__SI_FAULT|12)	/* invalid ASCII digit */
-#define __FPE_INVDEC	(__SI_FAULT|13)	/* invalid decimal digit */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
+#define __FPE_DECOVF	9	/* decimal overflow */
+#define __FPE_DECDIV	10	/* decimal division by zero */
+#define __FPE_DECERR	11	/* packed decimal error */
+#define __FPE_INVASC	12	/* invalid ASCII digit */
+#define __FPE_INVDEC	13	/* invalid decimal digit */
 #undef NSIGFPE
 #define NSIGFPE		13
 
 /*
  * SIGSEGV si_codes
  */
-#define __SEGV_PSTKOVF	(__SI_FAULT|4)	/* paragraph stack overflow */
+#define __SEGV_PSTKOVF	4	/* paragraph stack overflow */
 #undef NSIGSEGV
 #define NSIGSEGV	4
 
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 5db52c6813c4..6146d53b6ad7 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -124,31 +124,30 @@ copy_siginfo_to_user (siginfo_t __user *to, const siginfo_t *from)
 		 */
 		err = __put_user(from->si_signo, &to->si_signo);
 		err |= __put_user(from->si_errno, &to->si_errno);
-		err |= __put_user((short)from->si_code, &to->si_code);
-		switch (from->si_code >> 16) {
-		      case __SI_FAULT >> 16:
+		err |= __put_user(from->si_code, &to->si_code);
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		      case SIL_FAULT:
 			err |= __put_user(from->si_flags, &to->si_flags);
 			err |= __put_user(from->si_isr, &to->si_isr);
-		      case __SI_POLL >> 16:
+		      case SIL_POLL:
 			err |= __put_user(from->si_addr, &to->si_addr);
 			err |= __put_user(from->si_imm, &to->si_imm);
 			break;
-		      case __SI_TIMER >> 16:
+		      case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_ptr, &to->si_ptr);
 			break;
-		      case __SI_RT >> 16:	/* Not generated by the kernel as of now.  */
-		      case __SI_MESGQ >> 16:
+		      case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_ptr, &to->si_ptr);
 			break;
-		      case __SI_CHLD >> 16:
+		      case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		      default:
+		      case SIL_KILL:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			break;
diff --git a/arch/mips/include/uapi/asm/siginfo.h b/arch/mips/include/uapi/asm/siginfo.h
index 0d80df888325..7b05ff5ce566 100644
--- a/arch/mips/include/uapi/asm/siginfo.h
+++ b/arch/mips/include/uapi/asm/siginfo.h
@@ -120,12 +120,12 @@ typedef struct siginfo {
 #undef SI_TIMER
 #undef SI_MESGQ
 #define SI_ASYNCIO	-2	/* sent by AIO completion */
-#define SI_TIMER __SI_CODE(__SI_TIMER, -3) /* sent by timer expiration */
-#define SI_MESGQ __SI_CODE(__SI_MESGQ, -4) /* sent by real time mesq state change */
+#define SI_TIMER	-3	/* sent by timer expiration */
+#define SI_MESGQ	-4	/* sent by real time mesq state change */
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
 
 #endif /* _UAPI_ASM_SIGINFO_H */
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 84165f2b31ff..cf5c7c05e5a3 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -93,38 +93,37 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_TIMER >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_SYS >> 16:
+		case SIL_SYS:
 			err |= __copy_to_user(&to->si_call_addr, &from->si_call_addr,
 					      sizeof(compat_uptr_t));
 			err |= __put_user(from->si_syscall, &to->si_syscall);
diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
index 70aaabb8b3cb..9e0cb6a577d6 100644
--- a/arch/parisc/kernel/signal32.c
+++ b/arch/parisc/kernel/signal32.c
@@ -290,25 +290,25 @@ copy_siginfo_from_user32 (siginfo_t *to, compat_siginfo_t __user *from)
 	if (to->si_code < 0)
 		err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (to->si_code >> 16) {
-		      case __SI_CHLD >> 16:
+		switch (siginfo_layout(to->si_signo, to->si_code)) {
+		      case SIL_CHLD:
 			err |= __get_user(to->si_utime, &from->si_utime);
 			err |= __get_user(to->si_stime, &from->si_stime);
 			err |= __get_user(to->si_status, &from->si_status);
 		      default:
+		      case SIL_KILL:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			break;
-		      case __SI_FAULT >> 16:
+		      case SIL_FAULT:
 			err |= __get_user(addr, &from->si_addr);
 			to->si_addr = compat_ptr(addr);
 			break;
-		      case __SI_POLL >> 16:
+		      case SIL_POLL:
 			err |= __get_user(to->si_band, &from->si_band);
 			err |= __get_user(to->si_fd, &from->si_fd);
 			break;
-		      case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		      case __SI_MESGQ >> 16:
+		      case SIL_RT:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			err |= __get_user(to->si_int, &from->si_int);
@@ -337,41 +337,40 @@ copy_siginfo_to_user32 (compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_CHLD >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			addr = ptr_to_compat(from->si_addr);
 			err |= __put_user(addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			val = (compat_int_t)from->si_int;
 			err |= __put_user(val, &to->si_int);
 			break;
-		case __SI_RT >> 16:	/* Not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			val = (compat_int_t)from->si_int;
 			err |= __put_user(val, &to->si_int);
 			break;
-		case __SI_SYS >> 16:
+		case SIL_SYS:
 			err |= __put_user(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 			err |= __put_user(from->si_syscall, &to->si_syscall);
 			err |= __put_user(from->si_arch, &to->si_arch);
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 97bb1385e771..92fb1c8dbbd8 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -913,42 +913,40 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *d, const siginfo_t *s)
 	 */
 	err = __put_user(s->si_signo, &d->si_signo);
 	err |= __put_user(s->si_errno, &d->si_errno);
-	err |= __put_user((short)s->si_code, &d->si_code);
+	err |= __put_user(s->si_code, &d->si_code);
 	if (s->si_code < 0)
 		err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
 				      SI_PAD_SIZE32);
-	else switch(s->si_code >> 16) {
-	case __SI_CHLD >> 16:
+	else switch(siginfo_layout(s->si_signo, s->si_code)) {
+	case SIL_CHLD:
 		err |= __put_user(s->si_pid, &d->si_pid);
 		err |= __put_user(s->si_uid, &d->si_uid);
 		err |= __put_user(s->si_utime, &d->si_utime);
 		err |= __put_user(s->si_stime, &d->si_stime);
 		err |= __put_user(s->si_status, &d->si_status);
 		break;
-	case __SI_FAULT >> 16:
+	case SIL_FAULT:
 		err |= __put_user((unsigned int)(unsigned long)s->si_addr,
 				  &d->si_addr);
 		break;
-	case __SI_POLL >> 16:
+	case SIL_POLL:
 		err |= __put_user(s->si_band, &d->si_band);
 		err |= __put_user(s->si_fd, &d->si_fd);
 		break;
-	case __SI_TIMER >> 16:
+	case SIL_TIMER:
 		err |= __put_user(s->si_tid, &d->si_tid);
 		err |= __put_user(s->si_overrun, &d->si_overrun);
 		err |= __put_user(s->si_int, &d->si_int);
 		break;
-	case __SI_SYS >> 16:
+	case SIL_SYS:
 		err |= __put_user(ptr_to_compat(s->si_call_addr), &d->si_call_addr);
 		err |= __put_user(s->si_syscall, &d->si_syscall);
 		err |= __put_user(s->si_arch, &d->si_arch);
 		break;
-	case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-	case __SI_MESGQ >> 16:
+	case SIL_RT:
 		err |= __put_user(s->si_int, &d->si_int);
 		/* fallthrough */
-	case __SI_KILL >> 16:
-	default:
+	case SIL_KILL:
 		err |= __put_user(s->si_pid, &d->si_pid);
 		err |= __put_user(s->si_uid, &d->si_uid);
 		break;
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index c620049c61f2..f549c4657376 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -75,35 +75,34 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_RT:
 			err |= __put_user(from->si_int, &to->si_int);
 			/* fallthrough */
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user((unsigned long) from->si_addr,
 					  &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
@@ -127,32 +126,31 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
 	if (to->si_code < 0)
 		err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (to->si_code >> 16) {
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		switch (siginfo_layout(to->si_signo, to->si_code)) {
+		case SIL_RT:
 			err |= __get_user(to->si_int, &from->si_int);
 			/* fallthrough */
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			err |= __get_user(to->si_utime, &from->si_utime);
 			err |= __get_user(to->si_stime, &from->si_stime);
 			err |= __get_user(to->si_status, &from->si_status);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __get_user(tmp, &from->si_addr);
 			to->si_addr = (void __force __user *)
 				(u64) (tmp & PSW32_ADDR_INSN);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __get_user(to->si_band, &from->si_band);
 			err |= __get_user(to->si_fd, &from->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __get_user(to->si_tid, &from->si_tid);
 			err |= __get_user(to->si_overrun, &from->si_overrun);
 			err |= __get_user(to->si_int, &from->si_int);
diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
index 6bc5c677e92f..7ba6e93d90e7 100644
--- a/arch/sparc/include/uapi/asm/siginfo.h
+++ b/arch/sparc/include/uapi/asm/siginfo.h
@@ -19,12 +19,12 @@
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
 
 /*
  * SIGEMT si_codes
  */
-#define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
+#define EMT_TAGOVF	1	/* tag overflow */
 #define NSIGEMT		1
 
 #endif /* _UAPI__SPARC_SIGINFO_H */
diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
index b4096bb665b2..0e4c08c45a37 100644
--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -85,34 +85,34 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_TIMER >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user(from->si_trapno, &to->si_trapno);
 			err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
diff --git a/arch/tile/include/uapi/asm/siginfo.h b/arch/tile/include/uapi/asm/siginfo.h
index 56d661bb010b..e83f931aa1f0 100644
--- a/arch/tile/include/uapi/asm/siginfo.h
+++ b/arch/tile/include/uapi/asm/siginfo.h
@@ -26,8 +26,8 @@
 /*
  * Additional Tile-specific SIGILL si_codes
  */
-#define ILL_DBLFLT	(__SI_FAULT|9)	/* double fault */
-#define ILL_HARDWALL	(__SI_FAULT|10)	/* user networks hardwall violation */
+#define ILL_DBLFLT	9	/* double fault */
+#define ILL_HARDWALL	10	/* user networks hardwall violation */
 #undef NSIGILL
 #define NSIGILL		10
 
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index 0e863f1ee08c..971d87a1d8cf 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -64,7 +64,7 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *fr
 	   3 ints plus the relevant union member.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 
 	if (from->si_code < 0) {
 		err |= __put_user(from->si_pid, &to->si_pid);
@@ -77,28 +77,26 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *fr
 		 */
 		err |= __put_user(from->_sifields._pad[0],
 				  &to->_sifields._pad[0]);
-		switch (from->si_code >> 16) {
-		case __SI_FAULT >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_FAULT:
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 			/* FALL THROUGH */
 		default:
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-			 /* This is not generated by the kernel as of now.  */
-		case __SI_RT >> 16:
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
index 54804866f238..4433d1dc28e6 100644
--- a/arch/tile/kernel/traps.c
+++ b/arch/tile/kernel/traps.c
@@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
 
 	/* Make it the requested signal. */
 	*sigp = sig;
-	*codep = code | __SI_FAULT;
 	return 1;
 }
 
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index 59e1029bb3d0..cd71b45307b0 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -129,7 +129,7 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 		   3 ints plus the relevant union member.  */
 		put_user_ex(from->si_signo, &to->si_signo);
 		put_user_ex(from->si_errno, &to->si_errno);
-		put_user_ex((short)from->si_code, &to->si_code);
+		put_user_ex(from->si_code, &to->si_code);
 
 		if (from->si_code < 0) {
 			put_user_ex(from->si_pid, &to->si_pid);
@@ -142,8 +142,8 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 			 */
 			put_user_ex(from->_sifields._pad[0],
 					  &to->_sifields._pad[0]);
-			switch (from->si_code >> 16) {
-			case __SI_FAULT >> 16:
+			switch (siginfo_layout(from->si_signo, from->si_code)) {
+			case SIL_FAULT:
 				if (from->si_signo == SIGBUS &&
 				    (from->si_code == BUS_MCEERR_AR ||
 				     from->si_code == BUS_MCEERR_AO))
@@ -160,12 +160,12 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 						put_user_ex(from->si_pkey, &to->si_pkey);
 				}
 				break;
-			case __SI_SYS >> 16:
+			case SIL_SYS:
 				put_user_ex(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 				put_user_ex(from->si_syscall, &to->si_syscall);
 				put_user_ex(from->si_arch, &to->si_arch);
 				break;
-			case __SI_CHLD >> 16:
+			case SIL_CHLD:
 				if (!x32_ABI) {
 					put_user_ex(from->si_utime, &to->si_utime);
 					put_user_ex(from->si_stime, &to->si_stime);
@@ -175,21 +175,18 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 				}
 				put_user_ex(from->si_status, &to->si_status);
 				/* FALL THROUGH */
-			default:
-			case __SI_KILL >> 16:
+			case SIL_KILL:
 				put_user_ex(from->si_uid, &to->si_uid);
 				break;
-			case __SI_POLL >> 16:
+			case SIL_POLL:
 				put_user_ex(from->si_fd, &to->si_fd);
 				break;
-			case __SI_TIMER >> 16:
+			case SIL_TIMER:
 				put_user_ex(from->si_overrun, &to->si_overrun);
 				put_user_ex(ptr_to_compat(from->si_ptr),
 					    &to->si_ptr);
 				break;
-				 /* This is not generated by the kernel as of now.  */
-			case __SI_RT >> 16:
-			case __SI_MESGQ >> 16:
+			case SIL_RT:
 				put_user_ex(from->si_uid, &to->si_uid);
 				put_user_ex(from->si_int, &to->si_int);
 				break;
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 3c4e17b0082a..e961fae9b42f 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -643,7 +643,7 @@ static void send_sigio_to_task(struct task_struct *p,
 			/* Make sure we are called with one of the POLL_*
 			   reasons, otherwise we could leak kernel stack into
 			   userspace.  */
-			BUG_ON((reason & __SI_MASK) != __SI_POLL);
+			BUG_ON((reason <= SI_USER) || (reason >= NSIGPOLL));
 			if (reason - POLL_IN >= NSIGPOLL)
 				si.si_band  = ~0L;
 			else
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 7e3d71109f51..6e6ce726c2da 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -95,23 +95,23 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 	 */
 	err |= __put_user(kinfo->si_signo, &uinfo->ssi_signo);
 	err |= __put_user(kinfo->si_errno, &uinfo->ssi_errno);
-	err |= __put_user((short) kinfo->si_code, &uinfo->ssi_code);
-	switch (kinfo->si_code & __SI_MASK) {
-	case __SI_KILL:
+	err |= __put_user(kinfo->si_code, &uinfo->ssi_code);
+	switch (siginfo_layout(kinfo->si_signo, kinfo->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
 		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
 		break;
-	case __SI_TIMER:
+	case SIL_TIMER:
 		 err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid);
 		 err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun);
 		 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
 		 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(kinfo->si_band, &uinfo->ssi_band);
 		err |= __put_user(kinfo->si_fd, &uinfo->ssi_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user((long) kinfo->si_addr, &uinfo->ssi_addr);
 #ifdef __ARCH_SI_TRAPNO
 		err |= __put_user(kinfo->si_trapno, &uinfo->ssi_trapno);
@@ -128,20 +128,14 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 					  &uinfo->ssi_addr_lsb);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
 		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
 		err |= __put_user(kinfo->si_status, &uinfo->ssi_status);
 		err |= __put_user(kinfo->si_utime, &uinfo->ssi_utime);
 		err |= __put_user(kinfo->si_stime, &uinfo->ssi_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
-		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
-		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
-		err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
-		err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
-		break;
+	case SIL_RT:
 	default:
 		/*
 		 * This case catches also the signals queued by sigqueue().
diff --git a/include/asm-generic/siginfo.h b/include/asm-generic/siginfo.h
index a2508a8f9a9c..9f4a9df9cfd7 100644
--- a/include/asm-generic/siginfo.h
+++ b/include/asm-generic/siginfo.h
@@ -3,20 +3,22 @@
 
 #include <uapi/asm-generic/siginfo.h>
 
-#define __SI_MASK	0xffff0000u
-#define __SI_KILL	(0 << 16)
-#define __SI_TIMER	(1 << 16)
-#define __SI_POLL	(2 << 16)
-#define __SI_FAULT	(3 << 16)
-#define __SI_CHLD	(4 << 16)
-#define __SI_RT		(5 << 16)
-#define __SI_MESGQ	(6 << 16)
-#define __SI_SYS	(7 << 16)
-#define __SI_CODE(T,N)	((T) | ((N) & 0xffff))
+enum siginfo_layout {
+	SIL_KILL,
+	SIL_TIMER,
+	SIL_POLL,
+	SIL_FAULT,
+	SIL_CHLD,
+	SIL_RT,
+#ifdef __ARCH_SIGSYS
+	SIL_SYS,
+#endif
+};
 
 struct siginfo;
 void do_schedule_next_timer(struct siginfo *info);
 
 extern int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from);
+extern enum siginfo_layout siginfo_layout(int sig, int si_code);
 
 #endif
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index e1081a6d842b..77336f1e51ea 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -151,18 +151,6 @@ typedef struct siginfo {
 #define si_arch		_sifields._sigsys._arch
 #endif
 
-#ifndef __KERNEL__
-#define __SI_KILL	0
-#define __SI_TIMER	0
-#define __SI_POLL	0
-#define __SI_FAULT	0
-#define __SI_CHLD	0
-#define __SI_RT		0
-#define __SI_MESGQ	0
-#define __SI_SYS	0
-#define __SI_CODE(T,N)	(N)
-#endif
-
 /*
  * si_code values
  * Digital reserves positive values for kernel-generated signals.
@@ -170,8 +158,8 @@ typedef struct siginfo {
 #define SI_USER		0		/* sent by kill, sigsend, raise */
 #define SI_KERNEL	0x80		/* sent by the kernel from somewhere */
 #define SI_QUEUE	-1		/* sent by sigqueue */
-#define SI_TIMER __SI_CODE(__SI_TIMER,-2) /* sent by timer expiration */
-#define SI_MESGQ __SI_CODE(__SI_MESGQ,-3) /* sent by real time mesq state change */
+#define SI_TIMER	-2 /* sent by timer expiration */
+#define SI_MESGQ	-3 /* sent by real time mesq state change */
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 #define SI_TKILL	-6		/* sent by tkill system call */
@@ -183,86 +171,86 @@ typedef struct siginfo {
 /*
  * SIGILL si_codes
  */
-#define ILL_ILLOPC	(__SI_FAULT|1)	/* illegal opcode */
-#define ILL_ILLOPN	(__SI_FAULT|2)	/* illegal operand */
-#define ILL_ILLADR	(__SI_FAULT|3)	/* illegal addressing mode */
-#define ILL_ILLTRP	(__SI_FAULT|4)	/* illegal trap */
-#define ILL_PRVOPC	(__SI_FAULT|5)	/* privileged opcode */
-#define ILL_PRVREG	(__SI_FAULT|6)	/* privileged register */
-#define ILL_COPROC	(__SI_FAULT|7)	/* coprocessor error */
-#define ILL_BADSTK	(__SI_FAULT|8)	/* internal stack error */
+#define ILL_ILLOPC	1	/* illegal opcode */
+#define ILL_ILLOPN	2	/* illegal operand */
+#define ILL_ILLADR	3	/* illegal addressing mode */
+#define ILL_ILLTRP	4	/* illegal trap */
+#define ILL_PRVOPC	5	/* privileged opcode */
+#define ILL_PRVREG	6	/* privileged register */
+#define ILL_COPROC	7	/* coprocessor error */
+#define ILL_BADSTK	8	/* internal stack error */
 #define NSIGILL		8
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_INTDIV	(__SI_FAULT|1)	/* integer divide by zero */
-#define FPE_INTOVF	(__SI_FAULT|2)	/* integer overflow */
-#define FPE_FLTDIV	(__SI_FAULT|3)	/* floating point divide by zero */
-#define FPE_FLTOVF	(__SI_FAULT|4)	/* floating point overflow */
-#define FPE_FLTUND	(__SI_FAULT|5)	/* floating point underflow */
-#define FPE_FLTRES	(__SI_FAULT|6)	/* floating point inexact result */
-#define FPE_FLTINV	(__SI_FAULT|7)	/* floating point invalid operation */
-#define FPE_FLTSUB	(__SI_FAULT|8)	/* subscript out of range */
+#define FPE_INTDIV	1	/* integer divide by zero */
+#define FPE_INTOVF	2	/* integer overflow */
+#define FPE_FLTDIV	3	/* floating point divide by zero */
+#define FPE_FLTOVF	4	/* floating point overflow */
+#define FPE_FLTUND	5	/* floating point underflow */
+#define FPE_FLTRES	6	/* floating point inexact result */
+#define FPE_FLTINV	7	/* floating point invalid operation */
+#define FPE_FLTSUB	8	/* subscript out of range */
 #define NSIGFPE		8
 
 /*
  * SIGSEGV si_codes
  */
-#define SEGV_MAPERR	(__SI_FAULT|1)	/* address not mapped to object */
-#define SEGV_ACCERR	(__SI_FAULT|2)	/* invalid permissions for mapped object */
-#define SEGV_BNDERR	(__SI_FAULT|3)  /* failed address bound checks */
-#define SEGV_PKUERR	(__SI_FAULT|4)  /* failed protection key checks */
+#define SEGV_MAPERR	1	/* address not mapped to object */
+#define SEGV_ACCERR	2	/* invalid permissions for mapped object */
+#define SEGV_BNDERR	3	/* failed address bound checks */
+#define SEGV_PKUERR	4	/* failed protection key checks */
 #define NSIGSEGV	4
 
 /*
  * SIGBUS si_codes
  */
-#define BUS_ADRALN	(__SI_FAULT|1)	/* invalid address alignment */
-#define BUS_ADRERR	(__SI_FAULT|2)	/* non-existent physical address */
-#define BUS_OBJERR	(__SI_FAULT|3)	/* object specific hardware error */
+#define BUS_ADRALN	1	/* invalid address alignment */
+#define BUS_ADRERR	2	/* non-existent physical address */
+#define BUS_OBJERR	3	/* object specific hardware error */
 /* hardware memory error consumed on a machine check: action required */
-#define BUS_MCEERR_AR	(__SI_FAULT|4)
+#define BUS_MCEERR_AR	4
 /* hardware memory error detected in process but not consumed: action optional*/
-#define BUS_MCEERR_AO	(__SI_FAULT|5)
+#define BUS_MCEERR_AO	5
 #define NSIGBUS		5
 
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_BRKPT	(__SI_FAULT|1)	/* process breakpoint */
-#define TRAP_TRACE	(__SI_FAULT|2)	/* process trace trap */
-#define TRAP_BRANCH     (__SI_FAULT|3)  /* process taken branch trap */
-#define TRAP_HWBKPT     (__SI_FAULT|4)  /* hardware breakpoint/watchpoint */
+#define TRAP_BRKPT	1	/* process breakpoint */
+#define TRAP_TRACE	2	/* process trace trap */
+#define TRAP_BRANCH     3	/* process taken branch trap */
+#define TRAP_HWBKPT     4	/* hardware breakpoint/watchpoint */
 #define NSIGTRAP	4
 
 /*
  * SIGCHLD si_codes
  */
-#define CLD_EXITED	(__SI_CHLD|1)	/* child has exited */
-#define CLD_KILLED	(__SI_CHLD|2)	/* child was killed */
-#define CLD_DUMPED	(__SI_CHLD|3)	/* child terminated abnormally */
-#define CLD_TRAPPED	(__SI_CHLD|4)	/* traced child has trapped */
-#define CLD_STOPPED	(__SI_CHLD|5)	/* child has stopped */
-#define CLD_CONTINUED	(__SI_CHLD|6)	/* stopped child has continued */
+#define CLD_EXITED	1	/* child has exited */
+#define CLD_KILLED	2	/* child was killed */
+#define CLD_DUMPED	3	/* child terminated abnormally */
+#define CLD_TRAPPED	4	/* traced child has trapped */
+#define CLD_STOPPED	5	/* child has stopped */
+#define CLD_CONTINUED	6	/* stopped child has continued */
 #define NSIGCHLD	6
 
 /*
  * SIGPOLL (or any other signal without signal specific si_codes) si_codes
  */
-#define POLL_IN		(__SI_POLL|1)	/* data input available */
-#define POLL_OUT	(__SI_POLL|2)	/* output buffers available */
-#define POLL_MSG	(__SI_POLL|3)	/* input message available */
-#define POLL_ERR	(__SI_POLL|4)	/* i/o error */
-#define POLL_PRI	(__SI_POLL|5)	/* high priority input available */
-#define POLL_HUP	(__SI_POLL|6)	/* device disconnected */
+#define POLL_IN		1	/* data input available */
+#define POLL_OUT	2	/* output buffers available */
+#define POLL_MSG	3	/* input message available */
+#define POLL_ERR	4	/* i/o error */
+#define POLL_PRI	5	/* high priority input available */
+#define POLL_HUP	6	/* device disconnected */
 #define NSIGPOLL	6
 
 /*
  * SIGSYS si_codes
  */
-#define SYS_SECCOMP		(__SI_SYS|1)	/* seccomp triggered */
-#define NSIGSYS	1
+#define SYS_SECCOMP	1	/* seccomp triggered */
+#define NSIGSYS		1
 
 /*
  * sigevent definitions
diff --git a/kernel/compat.c b/kernel/compat.c
index 933bcb31ae10..bb6ccbf78f25 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -604,8 +604,6 @@ COMPAT_SYSCALL_DEFINE5(waitid,
 			return -EFAULT;
 	}
 
-	BUG_ON(info.si_code & __SI_MASK);
-	info.si_code |= __SI_CHLD;
 	return copy_siginfo_to_user32(uinfo, &info);
 }
 
diff --git a/kernel/exit.c b/kernel/exit.c
index 516acdb0e0ec..520bc848297c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1064,7 +1064,7 @@ static int wait_noreap_copyout(struct wait_opts *wo, struct task_struct *p,
 		if (!retval)
 			retval = put_user(0, &infop->si_errno);
 		if (!retval)
-			retval = put_user((short)why, &infop->si_code);
+			retval = put_user(why, &infop->si_code);
 		if (!retval)
 			retval = put_user(pid, &infop->si_pid);
 		if (!retval)
@@ -1203,7 +1203,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
 			why = (status & 0x80) ? CLD_DUMPED : CLD_KILLED;
 			status &= 0x7f;
 		}
-		retval = put_user((short)why, &infop->si_code);
+		retval = put_user(why, &infop->si_code);
 		if (!retval)
 			retval = put_user(status, &infop->si_status);
 	}
@@ -1326,7 +1326,7 @@ static int wait_task_stopped(struct wait_opts *wo,
 	if (!retval && infop)
 		retval = put_user(0, &infop->si_errno);
 	if (!retval && infop)
-		retval = put_user((short)why, &infop->si_code);
+		retval = put_user(why, &infop->si_code);
 	if (!retval && infop)
 		retval = put_user(exit_code, &infop->si_status);
 	if (!retval && infop)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 266ddcc1d8bb..885ec5e5c9df 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -722,8 +722,7 @@ static int ptrace_peek_siginfo(struct task_struct *child,
 		if (unlikely(in_compat_syscall())) {
 			compat_siginfo_t __user *uinfo = compat_ptr(data);
 
-			if (copy_siginfo_to_user32(uinfo, &info) ||
-			    __put_user(info.si_code, &uinfo->si_code)) {
+			if (copy_siginfo_to_user32(uinfo, &info)) {
 				ret = -EFAULT;
 				break;
 			}
@@ -733,8 +732,7 @@ static int ptrace_peek_siginfo(struct task_struct *child,
 		{
 			siginfo_t __user *uinfo = (siginfo_t __user *) data;
 
-			if (copy_siginfo_to_user(uinfo, &info) ||
-			    __put_user(info.si_code, &uinfo->si_code)) {
+			if (copy_siginfo_to_user(uinfo, &info)) {
 				ret = -EFAULT;
 				break;
 			}
diff --git a/kernel/signal.c b/kernel/signal.c
index 45b4c1ffe14e..e55d6c5159f2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2678,6 +2678,51 @@ COMPAT_SYSCALL_DEFINE2(rt_sigpending, compat_sigset_t __user *, uset,
 }
 #endif
 
+enum siginfo_layout siginfo_layout(int sig, int si_code)
+{
+	enum siginfo_layout layout = SIL_KILL;
+	if ((si_code > SI_USER) && (si_code < SI_KERNEL)) {
+		static const struct {
+			unsigned char limit, layout;
+		} filter[] = {
+			[SIGILL]  = { NSIGILL,  SIL_FAULT },
+			[SIGFPE]  = { NSIGFPE,  SIL_FAULT },
+			[SIGSEGV] = { NSIGSEGV, SIL_FAULT },
+			[SIGBUS]  = { NSIGBUS,  SIL_FAULT },
+			[SIGTRAP] = { NSIGTRAP, SIL_FAULT },
+#if defined(SIGMET) && defined(NSIGEMT)
+			[SIGEMT]  = { NSIGEMT,  SIL_FAULT },
+#endif
+			[SIGCHLD] = { NSIGCHLD, SIL_CHLD },
+			[SIGPOLL] = { NSIGPOLL, SIL_POLL },
+#ifdef __ARCH_SIGSYS
+			[SIGSYS]  = { NSIGSYS,  SIL_SYS },
+#endif
+		};
+		if ((sig < ARRAY_SIZE(filter)) && (si_code <= filter[sig].limit))
+			layout = filter[sig].layout;
+		else if (si_code <= NSIGPOLL)
+			layout = SIL_POLL;
+	} else {
+		if (si_code == SI_TIMER)
+			layout = SIL_TIMER;
+		else if (si_code == SI_SIGIO)
+			layout = SIL_POLL;
+		else if (si_code < 0)
+			layout = SIL_RT;
+		/* Tests to support buggy kernel ABIs */
+#ifdef TRAP_FIXME
+		if ((sig == SIGTRAP) && (si_code == TRAP_FIXME))
+			layout = SIL_FAULT;
+#endif
+#ifdef FPE_FIXME
+		if ((sig == SIGFPE) && (si_code == FPE_FIXME))
+			layout = SIL_FAULT;
+#endif
+	}
+	return layout;
+}
+
 #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
 
 int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
@@ -2700,22 +2745,20 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
 	 */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
-	switch (from->si_code & __SI_MASK) {
-	case __SI_KILL:
+	err |= __put_user(from->si_code, &to->si_code);
+	switch (siginfo_layout(from->si_signo, from->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		break;
-	case __SI_TIMER:
-		 err |= __put_user(from->si_tid, &to->si_tid);
-		 err |= __put_user(from->si_overrun, &to->si_overrun);
-		 err |= __put_user(from->si_ptr, &to->si_ptr);
+	case SIL_TIMER:
+		/* Unreached SI_TIMER is negative */
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(from->si_band, &to->si_band);
 		err |= __put_user(from->si_fd, &to->si_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user(from->si_addr, &to->si_addr);
 #ifdef __ARCH_SI_TRAPNO
 		err |= __put_user(from->si_trapno, &to->si_trapno);
@@ -2740,30 +2783,25 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
 			err |= __put_user(from->si_pkey, &to->si_pkey);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_status, &to->si_status);
 		err |= __put_user(from->si_utime, &to->si_utime);
 		err |= __put_user(from->si_stime, &to->si_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
+	case SIL_RT:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_ptr, &to->si_ptr);
 		break;
 #ifdef __ARCH_SIGSYS
-	case __SI_SYS:
+	case SIL_SYS:
 		err |= __put_user(from->si_call_addr, &to->si_call_addr);
 		err |= __put_user(from->si_syscall, &to->si_syscall);
 		err |= __put_user(from->si_arch, &to->si_arch);
 		break;
 #endif
-	default: /* this is just in case for now ... */
-		err |= __put_user(from->si_pid, &to->si_pid);
-		err |= __put_user(from->si_uid, &to->si_uid);
-		break;
 	}
 	return err;
 }
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 8/8] signal: Remove kernel interal si_code magic
@ 2017-06-30 12:39       ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 12:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andy Lutomirski, Linus Torvalds, Al Viro, Oleg Nesterov,
	Andrei Vagin, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk, Eric W. Biederman

struct siginfo is a union and the kernel since 2.4 has been hiding a union
tag in the high 16bits of si_code using the values:
__SI_KILL
__SI_TIMER
__SI_POLL
__SI_FAULT
__SI_CHLD
__SI_RT
__SI_MESGQ
__SI_SYS

While this looks plausible on the surface, in practice this situation has
not worked well.

- Injected positive signals are not copied to user space properly
  unless they have these magic high bits set.

- Injected positive signals are not reported properly by signalfd
  unless they have these magic high bits set.

- These kernel internal values leaked to userspace via ptrace_peek_siginfo

- It was possible to inject these kernel internal values and cause the
  the kernel to misbehave.

- Kernel developers got confused and expected these kernel internal values
  in userspace in kernel self tests.

- Kernel developers got confused and set si_code to __SI_FAULT which
  is SI_USER in userspace which causes userspace to think an ordinary user
  sent the signal and that it was not kernel generated.

- The values make it impossible to reorganize the code to transform
  siginfo_copy_to_user into a plain copy_to_user.  As si_code must
  be massaged before being passed to userspace.

So remove these kernel internal si codes and make the kernel code simpler
and more maintainable.

To replace these kernel internal magic si_codes introduce the helper
function siginfo_layout, that takes a signal number and an si_code and
computes which union member of siginfo is being used.  Have
siginfo_layout return an enumeration so that gcc will have enough
information to warn if a switch statement does not handle all of union
members.

A couple of architectures have a messed up ABI that defines signal
specific duplications of SI_USER which causes more special cases in
siginfo_layout than I would like.  The good news is only problem
architectures pay the cost.

Update all of the code that used the previous magic __SI_ values to
use the new SIL_ values and to call siginfo_layout to get those
values.  Escept where not all of the cases are handled remove the
defaults in the switch statements so that if a new case is missed in
the future the lack will show up at compile time.

Modify the code that copies siginfo si_code to userspace to just copy
the value and not cast si_code to a short first.  The high bits are no
longer used to hold a magic union member.

Fixup the siginfo header files to stop including the __SI_ values in
their constants and for the headers that were missing it to properly
update the number of si_codes for each signal type.

The fixes to copy_siginfo_from_user32 implementations has the
interesting property that several of them perviously should never have
worked as the __SI_ values they depended up where kernel internal.
With that dependency gone those implementations should work much
better.

The idea of not passing the __SI_ values out to userspace and then
not reinserting them has been tested with criu and criu worked without
changes.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 arch/alpha/include/uapi/asm/siginfo.h    |   2 +-
 arch/arm64/kernel/signal32.c             |  23 +++----
 arch/blackfin/include/uapi/asm/siginfo.h |  30 +++++----
 arch/frv/include/uapi/asm/siginfo.h      |   2 +-
 arch/ia64/include/uapi/asm/siginfo.h     |  20 +++---
 arch/ia64/kernel/signal.c                |  17 +++---
 arch/mips/include/uapi/asm/siginfo.h     |   6 +-
 arch/mips/kernel/signal32.c              |  19 +++---
 arch/parisc/kernel/signal32.c            |  31 +++++-----
 arch/powerpc/kernel/signal_32.c          |  20 +++---
 arch/s390/kernel/compat_signal.c         |  32 +++++-----
 arch/sparc/include/uapi/asm/siginfo.h    |   4 +-
 arch/sparc/kernel/signal32.c             |  16 ++---
 arch/tile/include/uapi/asm/siginfo.h     |   4 +-
 arch/tile/kernel/compat_signal.c         |  18 +++---
 arch/tile/kernel/traps.c                 |   1 -
 arch/x86/kernel/signal_compat.c          |  21 +++----
 fs/fcntl.c                               |   2 +-
 fs/signalfd.c                            |  22 +++----
 include/asm-generic/siginfo.h            |  22 ++++---
 include/uapi/asm-generic/siginfo.h       | 102 ++++++++++++++-----------------
 kernel/compat.c                          |   2 -
 kernel/exit.c                            |   6 +-
 kernel/ptrace.c                          |   6 +-
 kernel/signal.c                          |  72 ++++++++++++++++------
 25 files changed, 254 insertions(+), 246 deletions(-)

diff --git a/arch/alpha/include/uapi/asm/siginfo.h b/arch/alpha/include/uapi/asm/siginfo.h
index 687e4972971b..b6ff539ff426 100644
--- a/arch/alpha/include/uapi/asm/siginfo.h
+++ b/arch/alpha/include/uapi/asm/siginfo.h
@@ -9,6 +9,6 @@
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define TRAP_FIXME	0	/* Broken dup of SI_USER */
 
 #endif
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index c747a0fc5d7d..9b95a935c21d 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -142,25 +142,25 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	 */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad,
 				      SI_PAD_SIZE);
-	else switch (from->si_code & __SI_MASK) {
-	case __SI_KILL:
+	else switch (siginfo_layout(from->si_signo, from->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		break;
-	case __SI_TIMER:
+	case SIL_TIMER:
 		 err |= __put_user(from->si_tid, &to->si_tid);
 		 err |= __put_user(from->si_overrun, &to->si_overrun);
 		 err |= __put_user(from->si_int, &to->si_int);
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(from->si_band, &to->si_band);
 		err |= __put_user(from->si_fd, &to->si_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
 				  &to->si_addr);
 #ifdef BUS_MCEERR_AO
@@ -173,29 +173,24 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 			err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_status, &to->si_status);
 		err |= __put_user(from->si_utime, &to->si_utime);
 		err |= __put_user(from->si_stime, &to->si_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
+	case SIL_RT:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_int, &to->si_int);
 		break;
-	case __SI_SYS:
+	case SIL_SYS:
 		err |= __put_user((compat_uptr_t)(unsigned long)
 				from->si_call_addr, &to->si_call_addr);
 		err |= __put_user(from->si_syscall, &to->si_syscall);
 		err |= __put_user(from->si_arch, &to->si_arch);
 		break;
-	default: /* this is just in case for now ... */
-		err |= __put_user(from->si_pid, &to->si_pid);
-		err |= __put_user(from->si_uid, &to->si_uid);
-		break;
 	}
 	return err;
 }
diff --git a/arch/blackfin/include/uapi/asm/siginfo.h b/arch/blackfin/include/uapi/asm/siginfo.h
index c72f4e6e386f..79dfe3979123 100644
--- a/arch/blackfin/include/uapi/asm/siginfo.h
+++ b/arch/blackfin/include/uapi/asm/siginfo.h
@@ -14,28 +14,36 @@
 
 #define si_uid16	_sifields._kill._uid
 
-#define ILL_ILLPARAOP	(__SI_FAULT|2)	/* illegal opcode combine ********** */
-#define ILL_ILLEXCPT	(__SI_FAULT|4)	/* unrecoverable exception ********** */
-#define ILL_CPLB_VI	(__SI_FAULT|9)	/* D/I CPLB protect violation ******** */
-#define ILL_CPLB_MISS	(__SI_FAULT|10)	/* D/I CPLB miss ******** */
-#define ILL_CPLB_MULHIT	(__SI_FAULT|11)	/* D/I CPLB multiple hit ******** */
+#define ILL_ILLPARAOP	2	/* illegal opcode combine ********** */
+#define ILL_ILLEXCPT	4	/* unrecoverable exception ********** */
+#define ILL_CPLB_VI	9	/* D/I CPLB protect violation ******** */
+#define ILL_CPLB_MISS	10	/* D/I CPLB miss ******** */
+#define ILL_CPLB_MULHIT	11	/* D/I CPLB multiple hit ******** */
+#undef NSIGILL
+#define NSIGILL         11
 
 /*
  * SIGBUS si_codes
  */
-#define BUS_OPFETCH	(__SI_FAULT|4)	/* error from instruction fetch ******** */
+#define BUS_OPFETCH	4	/* error from instruction fetch ******** */
+#undef NSIGBUS
+#define NSIGBUS		4
 
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_STEP	(__SI_FAULT|1)	/* single-step breakpoint************* */
-#define TRAP_TRACEFLOW	(__SI_FAULT|2)	/* trace buffer overflow ************* */
-#define TRAP_WATCHPT	(__SI_FAULT|3)	/* watchpoint match      ************* */
-#define TRAP_ILLTRAP	(__SI_FAULT|4)	/* illegal trap          ************* */
+#define TRAP_STEP	1	/* single-step breakpoint************* */
+#define TRAP_TRACEFLOW	2	/* trace buffer overflow ************* */
+#define TRAP_WATCHPT	3	/* watchpoint match      ************* */
+#define TRAP_ILLTRAP	4	/* illegal trap          ************* */
+#undef NSIGTRAP
+#define NSIGTRAP	4
 
 /*
  * SIGSEGV si_codes
  */
-#define SEGV_STACKFLOW	(__SI_FAULT|3)	/* stack overflow */
+#define SEGV_STACKFLOW	3	/* stack overflow */
+#undef NSIGSEGV
+#define NSIGSEGV	3
 
 #endif /* _UAPI_BFIN_SIGINFO_H */
diff --git a/arch/frv/include/uapi/asm/siginfo.h b/arch/frv/include/uapi/asm/siginfo.h
index d3fd1ca45653..f55d9e0e9068 100644
--- a/arch/frv/include/uapi/asm/siginfo.h
+++ b/arch/frv/include/uapi/asm/siginfo.h
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 #include <asm-generic/siginfo.h>
 
-#define FPE_MDAOVF	(__SI_FAULT|9)	/* media overflow */
+#define FPE_MDAOVF	9	/* media overflow */
 #undef NSIGFPE
 #define NSIGFPE		9
 
diff --git a/arch/ia64/include/uapi/asm/siginfo.h b/arch/ia64/include/uapi/asm/siginfo.h
index fafea221f49c..c3aaaee01dcb 100644
--- a/arch/ia64/include/uapi/asm/siginfo.h
+++ b/arch/ia64/include/uapi/asm/siginfo.h
@@ -99,28 +99,28 @@ typedef struct siginfo {
 /*
  * SIGILL si_codes
  */
-#define ILL_BADIADDR	(__SI_FAULT|9)	/* unimplemented instruction address */
-#define __ILL_BREAK	(__SI_FAULT|10)	/* illegal break */
-#define __ILL_BNDMOD	(__SI_FAULT|11)	/* bundle-update (modification) in progress */
+#define ILL_BADIADDR	9	/* unimplemented instruction address */
+#define __ILL_BREAK	10	/* illegal break */
+#define __ILL_BNDMOD	11	/* bundle-update (modification) in progress */
 #undef NSIGILL
 #define NSIGILL		11
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
-#define __FPE_DECOVF	(__SI_FAULT|9)	/* decimal overflow */
-#define __FPE_DECDIV	(__SI_FAULT|10)	/* decimal division by zero */
-#define __FPE_DECERR	(__SI_FAULT|11)	/* packed decimal error */
-#define __FPE_INVASC	(__SI_FAULT|12)	/* invalid ASCII digit */
-#define __FPE_INVDEC	(__SI_FAULT|13)	/* invalid decimal digit */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
+#define __FPE_DECOVF	9	/* decimal overflow */
+#define __FPE_DECDIV	10	/* decimal division by zero */
+#define __FPE_DECERR	11	/* packed decimal error */
+#define __FPE_INVASC	12	/* invalid ASCII digit */
+#define __FPE_INVDEC	13	/* invalid decimal digit */
 #undef NSIGFPE
 #define NSIGFPE		13
 
 /*
  * SIGSEGV si_codes
  */
-#define __SEGV_PSTKOVF	(__SI_FAULT|4)	/* paragraph stack overflow */
+#define __SEGV_PSTKOVF	4	/* paragraph stack overflow */
 #undef NSIGSEGV
 #define NSIGSEGV	4
 
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 5db52c6813c4..6146d53b6ad7 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -124,31 +124,30 @@ copy_siginfo_to_user (siginfo_t __user *to, const siginfo_t *from)
 		 */
 		err = __put_user(from->si_signo, &to->si_signo);
 		err |= __put_user(from->si_errno, &to->si_errno);
-		err |= __put_user((short)from->si_code, &to->si_code);
-		switch (from->si_code >> 16) {
-		      case __SI_FAULT >> 16:
+		err |= __put_user(from->si_code, &to->si_code);
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		      case SIL_FAULT:
 			err |= __put_user(from->si_flags, &to->si_flags);
 			err |= __put_user(from->si_isr, &to->si_isr);
-		      case __SI_POLL >> 16:
+		      case SIL_POLL:
 			err |= __put_user(from->si_addr, &to->si_addr);
 			err |= __put_user(from->si_imm, &to->si_imm);
 			break;
-		      case __SI_TIMER >> 16:
+		      case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_ptr, &to->si_ptr);
 			break;
-		      case __SI_RT >> 16:	/* Not generated by the kernel as of now.  */
-		      case __SI_MESGQ >> 16:
+		      case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_ptr, &to->si_ptr);
 			break;
-		      case __SI_CHLD >> 16:
+		      case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		      default:
+		      case SIL_KILL:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			break;
diff --git a/arch/mips/include/uapi/asm/siginfo.h b/arch/mips/include/uapi/asm/siginfo.h
index 0d80df888325..7b05ff5ce566 100644
--- a/arch/mips/include/uapi/asm/siginfo.h
+++ b/arch/mips/include/uapi/asm/siginfo.h
@@ -120,12 +120,12 @@ typedef struct siginfo {
 #undef SI_TIMER
 #undef SI_MESGQ
 #define SI_ASYNCIO	-2	/* sent by AIO completion */
-#define SI_TIMER __SI_CODE(__SI_TIMER, -3) /* sent by timer expiration */
-#define SI_MESGQ __SI_CODE(__SI_MESGQ, -4) /* sent by real time mesq state change */
+#define SI_TIMER	-3	/* sent by timer expiration */
+#define SI_MESGQ	-4	/* sent by real time mesq state change */
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
 
 #endif /* _UAPI_ASM_SIGINFO_H */
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index 84165f2b31ff..cf5c7c05e5a3 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -93,38 +93,37 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_TIMER >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_SYS >> 16:
+		case SIL_SYS:
 			err |= __copy_to_user(&to->si_call_addr, &from->si_call_addr,
 					      sizeof(compat_uptr_t));
 			err |= __put_user(from->si_syscall, &to->si_syscall);
diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
index 70aaabb8b3cb..9e0cb6a577d6 100644
--- a/arch/parisc/kernel/signal32.c
+++ b/arch/parisc/kernel/signal32.c
@@ -290,25 +290,25 @@ copy_siginfo_from_user32 (siginfo_t *to, compat_siginfo_t __user *from)
 	if (to->si_code < 0)
 		err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (to->si_code >> 16) {
-		      case __SI_CHLD >> 16:
+		switch (siginfo_layout(to->si_signo, to->si_code)) {
+		      case SIL_CHLD:
 			err |= __get_user(to->si_utime, &from->si_utime);
 			err |= __get_user(to->si_stime, &from->si_stime);
 			err |= __get_user(to->si_status, &from->si_status);
 		      default:
+		      case SIL_KILL:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			break;
-		      case __SI_FAULT >> 16:
+		      case SIL_FAULT:
 			err |= __get_user(addr, &from->si_addr);
 			to->si_addr = compat_ptr(addr);
 			break;
-		      case __SI_POLL >> 16:
+		      case SIL_POLL:
 			err |= __get_user(to->si_band, &from->si_band);
 			err |= __get_user(to->si_fd, &from->si_fd);
 			break;
-		      case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		      case __SI_MESGQ >> 16:
+		      case SIL_RT:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			err |= __get_user(to->si_int, &from->si_int);
@@ -337,41 +337,40 @@ copy_siginfo_to_user32 (compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_CHLD >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
-		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			addr = ptr_to_compat(from->si_addr);
 			err |= __put_user(addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			val = (compat_int_t)from->si_int;
 			err |= __put_user(val, &to->si_int);
 			break;
-		case __SI_RT >> 16:	/* Not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_pid, &to->si_pid);
 			val = (compat_int_t)from->si_int;
 			err |= __put_user(val, &to->si_int);
 			break;
-		case __SI_SYS >> 16:
+		case SIL_SYS:
 			err |= __put_user(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 			err |= __put_user(from->si_syscall, &to->si_syscall);
 			err |= __put_user(from->si_arch, &to->si_arch);
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 97bb1385e771..92fb1c8dbbd8 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -913,42 +913,40 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *d, const siginfo_t *s)
 	 */
 	err = __put_user(s->si_signo, &d->si_signo);
 	err |= __put_user(s->si_errno, &d->si_errno);
-	err |= __put_user((short)s->si_code, &d->si_code);
+	err |= __put_user(s->si_code, &d->si_code);
 	if (s->si_code < 0)
 		err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
 				      SI_PAD_SIZE32);
-	else switch(s->si_code >> 16) {
-	case __SI_CHLD >> 16:
+	else switch(siginfo_layout(s->si_signo, s->si_code)) {
+	case SIL_CHLD:
 		err |= __put_user(s->si_pid, &d->si_pid);
 		err |= __put_user(s->si_uid, &d->si_uid);
 		err |= __put_user(s->si_utime, &d->si_utime);
 		err |= __put_user(s->si_stime, &d->si_stime);
 		err |= __put_user(s->si_status, &d->si_status);
 		break;
-	case __SI_FAULT >> 16:
+	case SIL_FAULT:
 		err |= __put_user((unsigned int)(unsigned long)s->si_addr,
 				  &d->si_addr);
 		break;
-	case __SI_POLL >> 16:
+	case SIL_POLL:
 		err |= __put_user(s->si_band, &d->si_band);
 		err |= __put_user(s->si_fd, &d->si_fd);
 		break;
-	case __SI_TIMER >> 16:
+	case SIL_TIMER:
 		err |= __put_user(s->si_tid, &d->si_tid);
 		err |= __put_user(s->si_overrun, &d->si_overrun);
 		err |= __put_user(s->si_int, &d->si_int);
 		break;
-	case __SI_SYS >> 16:
+	case SIL_SYS:
 		err |= __put_user(ptr_to_compat(s->si_call_addr), &d->si_call_addr);
 		err |= __put_user(s->si_syscall, &d->si_syscall);
 		err |= __put_user(s->si_arch, &d->si_arch);
 		break;
-	case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-	case __SI_MESGQ >> 16:
+	case SIL_RT:
 		err |= __put_user(s->si_int, &d->si_int);
 		/* fallthrough */
-	case __SI_KILL >> 16:
-	default:
+	case SIL_KILL:
 		err |= __put_user(s->si_pid, &d->si_pid);
 		err |= __put_user(s->si_uid, &d->si_uid);
 		break;
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index c620049c61f2..f549c4657376 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -75,35 +75,34 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_RT:
 			err |= __put_user(from->si_int, &to->si_int);
 			/* fallthrough */
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user((unsigned long) from->si_addr,
 					  &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
@@ -127,32 +126,31 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
 	if (to->si_code < 0)
 		err |= __copy_from_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (to->si_code >> 16) {
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		switch (siginfo_layout(to->si_signo, to->si_code)) {
+		case SIL_RT:
 			err |= __get_user(to->si_int, &from->si_int);
 			/* fallthrough */
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __get_user(to->si_pid, &from->si_pid);
 			err |= __get_user(to->si_uid, &from->si_uid);
 			err |= __get_user(to->si_utime, &from->si_utime);
 			err |= __get_user(to->si_stime, &from->si_stime);
 			err |= __get_user(to->si_status, &from->si_status);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __get_user(tmp, &from->si_addr);
 			to->si_addr = (void __force __user *)
 				(u64) (tmp & PSW32_ADDR_INSN);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __get_user(to->si_band, &from->si_band);
 			err |= __get_user(to->si_fd, &from->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __get_user(to->si_tid, &from->si_tid);
 			err |= __get_user(to->si_overrun, &from->si_overrun);
 			err |= __get_user(to->si_int, &from->si_int);
diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
index 6bc5c677e92f..7ba6e93d90e7 100644
--- a/arch/sparc/include/uapi/asm/siginfo.h
+++ b/arch/sparc/include/uapi/asm/siginfo.h
@@ -19,12 +19,12 @@
 /*
  * SIGFPE si_codes
  */
-#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
+#define FPE_FIXME	0	/* Broken dup of SI_USER */
 
 /*
  * SIGEMT si_codes
  */
-#define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
+#define EMT_TAGOVF	1	/* tag overflow */
 #define NSIGEMT		1
 
 #endif /* _UAPI__SPARC_SIGINFO_H */
diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
index b4096bb665b2..0e4c08c45a37 100644
--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -85,34 +85,34 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
 	   at the same time.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 	if (from->si_code < 0)
 		err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE);
 	else {
-		switch (from->si_code >> 16) {
-		case __SI_TIMER >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_TIMER:
 			err |= __put_user(from->si_tid, &to->si_tid);
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 		default:
+		case SIL_KILL:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_FAULT >> 16:
+		case SIL_FAULT:
 			err |= __put_user(from->si_trapno, &to->si_trapno);
 			err |= __put_user((unsigned long)from->si_addr, &to->si_addr);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_band, &to->si_band);
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_RT >> 16: /* This is not generated by the kernel as of now.  */
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_pid, &to->si_pid);
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
diff --git a/arch/tile/include/uapi/asm/siginfo.h b/arch/tile/include/uapi/asm/siginfo.h
index 56d661bb010b..e83f931aa1f0 100644
--- a/arch/tile/include/uapi/asm/siginfo.h
+++ b/arch/tile/include/uapi/asm/siginfo.h
@@ -26,8 +26,8 @@
 /*
  * Additional Tile-specific SIGILL si_codes
  */
-#define ILL_DBLFLT	(__SI_FAULT|9)	/* double fault */
-#define ILL_HARDWALL	(__SI_FAULT|10)	/* user networks hardwall violation */
+#define ILL_DBLFLT	9	/* double fault */
+#define ILL_HARDWALL	10	/* user networks hardwall violation */
 #undef NSIGILL
 #define NSIGILL		10
 
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index 0e863f1ee08c..971d87a1d8cf 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -64,7 +64,7 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *fr
 	   3 ints plus the relevant union member.  */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
+	err |= __put_user(from->si_code, &to->si_code);
 
 	if (from->si_code < 0) {
 		err |= __put_user(from->si_pid, &to->si_pid);
@@ -77,28 +77,26 @@ int copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *fr
 		 */
 		err |= __put_user(from->_sifields._pad[0],
 				  &to->_sifields._pad[0]);
-		switch (from->si_code >> 16) {
-		case __SI_FAULT >> 16:
+		switch (siginfo_layout(from->si_signo, from->si_code)) {
+		case SIL_FAULT:
 			break;
-		case __SI_CHLD >> 16:
+		case SIL_CHLD:
 			err |= __put_user(from->si_utime, &to->si_utime);
 			err |= __put_user(from->si_stime, &to->si_stime);
 			err |= __put_user(from->si_status, &to->si_status);
 			/* FALL THROUGH */
 		default:
-		case __SI_KILL >> 16:
+		case SIL_KILL:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			break;
-		case __SI_POLL >> 16:
+		case SIL_POLL:
 			err |= __put_user(from->si_fd, &to->si_fd);
 			break;
-		case __SI_TIMER >> 16:
+		case SIL_TIMER:
 			err |= __put_user(from->si_overrun, &to->si_overrun);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
-			 /* This is not generated by the kernel as of now.  */
-		case __SI_RT >> 16:
-		case __SI_MESGQ >> 16:
+		case SIL_RT:
 			err |= __put_user(from->si_uid, &to->si_uid);
 			err |= __put_user(from->si_int, &to->si_int);
 			break;
diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
index 54804866f238..4433d1dc28e6 100644
--- a/arch/tile/kernel/traps.c
+++ b/arch/tile/kernel/traps.c
@@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
 
 	/* Make it the requested signal. */
 	*sigp = sig;
-	*codep = code | __SI_FAULT;
 	return 1;
 }
 
diff --git a/arch/x86/kernel/signal_compat.c b/arch/x86/kernel/signal_compat.c
index 59e1029bb3d0..cd71b45307b0 100644
--- a/arch/x86/kernel/signal_compat.c
+++ b/arch/x86/kernel/signal_compat.c
@@ -129,7 +129,7 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 		   3 ints plus the relevant union member.  */
 		put_user_ex(from->si_signo, &to->si_signo);
 		put_user_ex(from->si_errno, &to->si_errno);
-		put_user_ex((short)from->si_code, &to->si_code);
+		put_user_ex(from->si_code, &to->si_code);
 
 		if (from->si_code < 0) {
 			put_user_ex(from->si_pid, &to->si_pid);
@@ -142,8 +142,8 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 			 */
 			put_user_ex(from->_sifields._pad[0],
 					  &to->_sifields._pad[0]);
-			switch (from->si_code >> 16) {
-			case __SI_FAULT >> 16:
+			switch (siginfo_layout(from->si_signo, from->si_code)) {
+			case SIL_FAULT:
 				if (from->si_signo == SIGBUS &&
 				    (from->si_code == BUS_MCEERR_AR ||
 				     from->si_code == BUS_MCEERR_AO))
@@ -160,12 +160,12 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 						put_user_ex(from->si_pkey, &to->si_pkey);
 				}
 				break;
-			case __SI_SYS >> 16:
+			case SIL_SYS:
 				put_user_ex(ptr_to_compat(from->si_call_addr), &to->si_call_addr);
 				put_user_ex(from->si_syscall, &to->si_syscall);
 				put_user_ex(from->si_arch, &to->si_arch);
 				break;
-			case __SI_CHLD >> 16:
+			case SIL_CHLD:
 				if (!x32_ABI) {
 					put_user_ex(from->si_utime, &to->si_utime);
 					put_user_ex(from->si_stime, &to->si_stime);
@@ -175,21 +175,18 @@ int __copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from,
 				}
 				put_user_ex(from->si_status, &to->si_status);
 				/* FALL THROUGH */
-			default:
-			case __SI_KILL >> 16:
+			case SIL_KILL:
 				put_user_ex(from->si_uid, &to->si_uid);
 				break;
-			case __SI_POLL >> 16:
+			case SIL_POLL:
 				put_user_ex(from->si_fd, &to->si_fd);
 				break;
-			case __SI_TIMER >> 16:
+			case SIL_TIMER:
 				put_user_ex(from->si_overrun, &to->si_overrun);
 				put_user_ex(ptr_to_compat(from->si_ptr),
 					    &to->si_ptr);
 				break;
-				 /* This is not generated by the kernel as of now.  */
-			case __SI_RT >> 16:
-			case __SI_MESGQ >> 16:
+			case SIL_RT:
 				put_user_ex(from->si_uid, &to->si_uid);
 				put_user_ex(from->si_int, &to->si_int);
 				break;
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 3c4e17b0082a..e961fae9b42f 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -643,7 +643,7 @@ static void send_sigio_to_task(struct task_struct *p,
 			/* Make sure we are called with one of the POLL_*
 			   reasons, otherwise we could leak kernel stack into
 			   userspace.  */
-			BUG_ON((reason & __SI_MASK) != __SI_POLL);
+			BUG_ON((reason <= SI_USER) || (reason >= NSIGPOLL));
 			if (reason - POLL_IN >= NSIGPOLL)
 				si.si_band  = ~0L;
 			else
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 7e3d71109f51..6e6ce726c2da 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -95,23 +95,23 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 	 */
 	err |= __put_user(kinfo->si_signo, &uinfo->ssi_signo);
 	err |= __put_user(kinfo->si_errno, &uinfo->ssi_errno);
-	err |= __put_user((short) kinfo->si_code, &uinfo->ssi_code);
-	switch (kinfo->si_code & __SI_MASK) {
-	case __SI_KILL:
+	err |= __put_user(kinfo->si_code, &uinfo->ssi_code);
+	switch (siginfo_layout(kinfo->si_signo, kinfo->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
 		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
 		break;
-	case __SI_TIMER:
+	case SIL_TIMER:
 		 err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid);
 		 err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun);
 		 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
 		 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(kinfo->si_band, &uinfo->ssi_band);
 		err |= __put_user(kinfo->si_fd, &uinfo->ssi_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user((long) kinfo->si_addr, &uinfo->ssi_addr);
 #ifdef __ARCH_SI_TRAPNO
 		err |= __put_user(kinfo->si_trapno, &uinfo->ssi_trapno);
@@ -128,20 +128,14 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
 					  &uinfo->ssi_addr_lsb);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
 		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
 		err |= __put_user(kinfo->si_status, &uinfo->ssi_status);
 		err |= __put_user(kinfo->si_utime, &uinfo->ssi_utime);
 		err |= __put_user(kinfo->si_stime, &uinfo->ssi_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
-		err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
-		err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
-		err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
-		err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
-		break;
+	case SIL_RT:
 	default:
 		/*
 		 * This case catches also the signals queued by sigqueue().
diff --git a/include/asm-generic/siginfo.h b/include/asm-generic/siginfo.h
index a2508a8f9a9c..9f4a9df9cfd7 100644
--- a/include/asm-generic/siginfo.h
+++ b/include/asm-generic/siginfo.h
@@ -3,20 +3,22 @@
 
 #include <uapi/asm-generic/siginfo.h>
 
-#define __SI_MASK	0xffff0000u
-#define __SI_KILL	(0 << 16)
-#define __SI_TIMER	(1 << 16)
-#define __SI_POLL	(2 << 16)
-#define __SI_FAULT	(3 << 16)
-#define __SI_CHLD	(4 << 16)
-#define __SI_RT		(5 << 16)
-#define __SI_MESGQ	(6 << 16)
-#define __SI_SYS	(7 << 16)
-#define __SI_CODE(T,N)	((T) | ((N) & 0xffff))
+enum siginfo_layout {
+	SIL_KILL,
+	SIL_TIMER,
+	SIL_POLL,
+	SIL_FAULT,
+	SIL_CHLD,
+	SIL_RT,
+#ifdef __ARCH_SIGSYS
+	SIL_SYS,
+#endif
+};
 
 struct siginfo;
 void do_schedule_next_timer(struct siginfo *info);
 
 extern int copy_siginfo_to_user(struct siginfo __user *to, const struct siginfo *from);
+extern enum siginfo_layout siginfo_layout(int sig, int si_code);
 
 #endif
diff --git a/include/uapi/asm-generic/siginfo.h b/include/uapi/asm-generic/siginfo.h
index e1081a6d842b..77336f1e51ea 100644
--- a/include/uapi/asm-generic/siginfo.h
+++ b/include/uapi/asm-generic/siginfo.h
@@ -151,18 +151,6 @@ typedef struct siginfo {
 #define si_arch		_sifields._sigsys._arch
 #endif
 
-#ifndef __KERNEL__
-#define __SI_KILL	0
-#define __SI_TIMER	0
-#define __SI_POLL	0
-#define __SI_FAULT	0
-#define __SI_CHLD	0
-#define __SI_RT		0
-#define __SI_MESGQ	0
-#define __SI_SYS	0
-#define __SI_CODE(T,N)	(N)
-#endif
-
 /*
  * si_code values
  * Digital reserves positive values for kernel-generated signals.
@@ -170,8 +158,8 @@ typedef struct siginfo {
 #define SI_USER		0		/* sent by kill, sigsend, raise */
 #define SI_KERNEL	0x80		/* sent by the kernel from somewhere */
 #define SI_QUEUE	-1		/* sent by sigqueue */
-#define SI_TIMER __SI_CODE(__SI_TIMER,-2) /* sent by timer expiration */
-#define SI_MESGQ __SI_CODE(__SI_MESGQ,-3) /* sent by real time mesq state change */
+#define SI_TIMER	-2 /* sent by timer expiration */
+#define SI_MESGQ	-3 /* sent by real time mesq state change */
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 #define SI_TKILL	-6		/* sent by tkill system call */
@@ -183,86 +171,86 @@ typedef struct siginfo {
 /*
  * SIGILL si_codes
  */
-#define ILL_ILLOPC	(__SI_FAULT|1)	/* illegal opcode */
-#define ILL_ILLOPN	(__SI_FAULT|2)	/* illegal operand */
-#define ILL_ILLADR	(__SI_FAULT|3)	/* illegal addressing mode */
-#define ILL_ILLTRP	(__SI_FAULT|4)	/* illegal trap */
-#define ILL_PRVOPC	(__SI_FAULT|5)	/* privileged opcode */
-#define ILL_PRVREG	(__SI_FAULT|6)	/* privileged register */
-#define ILL_COPROC	(__SI_FAULT|7)	/* coprocessor error */
-#define ILL_BADSTK	(__SI_FAULT|8)	/* internal stack error */
+#define ILL_ILLOPC	1	/* illegal opcode */
+#define ILL_ILLOPN	2	/* illegal operand */
+#define ILL_ILLADR	3	/* illegal addressing mode */
+#define ILL_ILLTRP	4	/* illegal trap */
+#define ILL_PRVOPC	5	/* privileged opcode */
+#define ILL_PRVREG	6	/* privileged register */
+#define ILL_COPROC	7	/* coprocessor error */
+#define ILL_BADSTK	8	/* internal stack error */
 #define NSIGILL		8
 
 /*
  * SIGFPE si_codes
  */
-#define FPE_INTDIV	(__SI_FAULT|1)	/* integer divide by zero */
-#define FPE_INTOVF	(__SI_FAULT|2)	/* integer overflow */
-#define FPE_FLTDIV	(__SI_FAULT|3)	/* floating point divide by zero */
-#define FPE_FLTOVF	(__SI_FAULT|4)	/* floating point overflow */
-#define FPE_FLTUND	(__SI_FAULT|5)	/* floating point underflow */
-#define FPE_FLTRES	(__SI_FAULT|6)	/* floating point inexact result */
-#define FPE_FLTINV	(__SI_FAULT|7)	/* floating point invalid operation */
-#define FPE_FLTSUB	(__SI_FAULT|8)	/* subscript out of range */
+#define FPE_INTDIV	1	/* integer divide by zero */
+#define FPE_INTOVF	2	/* integer overflow */
+#define FPE_FLTDIV	3	/* floating point divide by zero */
+#define FPE_FLTOVF	4	/* floating point overflow */
+#define FPE_FLTUND	5	/* floating point underflow */
+#define FPE_FLTRES	6	/* floating point inexact result */
+#define FPE_FLTINV	7	/* floating point invalid operation */
+#define FPE_FLTSUB	8	/* subscript out of range */
 #define NSIGFPE		8
 
 /*
  * SIGSEGV si_codes
  */
-#define SEGV_MAPERR	(__SI_FAULT|1)	/* address not mapped to object */
-#define SEGV_ACCERR	(__SI_FAULT|2)	/* invalid permissions for mapped object */
-#define SEGV_BNDERR	(__SI_FAULT|3)  /* failed address bound checks */
-#define SEGV_PKUERR	(__SI_FAULT|4)  /* failed protection key checks */
+#define SEGV_MAPERR	1	/* address not mapped to object */
+#define SEGV_ACCERR	2	/* invalid permissions for mapped object */
+#define SEGV_BNDERR	3	/* failed address bound checks */
+#define SEGV_PKUERR	4	/* failed protection key checks */
 #define NSIGSEGV	4
 
 /*
  * SIGBUS si_codes
  */
-#define BUS_ADRALN	(__SI_FAULT|1)	/* invalid address alignment */
-#define BUS_ADRERR	(__SI_FAULT|2)	/* non-existent physical address */
-#define BUS_OBJERR	(__SI_FAULT|3)	/* object specific hardware error */
+#define BUS_ADRALN	1	/* invalid address alignment */
+#define BUS_ADRERR	2	/* non-existent physical address */
+#define BUS_OBJERR	3	/* object specific hardware error */
 /* hardware memory error consumed on a machine check: action required */
-#define BUS_MCEERR_AR	(__SI_FAULT|4)
+#define BUS_MCEERR_AR	4
 /* hardware memory error detected in process but not consumed: action optional*/
-#define BUS_MCEERR_AO	(__SI_FAULT|5)
+#define BUS_MCEERR_AO	5
 #define NSIGBUS		5
 
 /*
  * SIGTRAP si_codes
  */
-#define TRAP_BRKPT	(__SI_FAULT|1)	/* process breakpoint */
-#define TRAP_TRACE	(__SI_FAULT|2)	/* process trace trap */
-#define TRAP_BRANCH     (__SI_FAULT|3)  /* process taken branch trap */
-#define TRAP_HWBKPT     (__SI_FAULT|4)  /* hardware breakpoint/watchpoint */
+#define TRAP_BRKPT	1	/* process breakpoint */
+#define TRAP_TRACE	2	/* process trace trap */
+#define TRAP_BRANCH     3	/* process taken branch trap */
+#define TRAP_HWBKPT     4	/* hardware breakpoint/watchpoint */
 #define NSIGTRAP	4
 
 /*
  * SIGCHLD si_codes
  */
-#define CLD_EXITED	(__SI_CHLD|1)	/* child has exited */
-#define CLD_KILLED	(__SI_CHLD|2)	/* child was killed */
-#define CLD_DUMPED	(__SI_CHLD|3)	/* child terminated abnormally */
-#define CLD_TRAPPED	(__SI_CHLD|4)	/* traced child has trapped */
-#define CLD_STOPPED	(__SI_CHLD|5)	/* child has stopped */
-#define CLD_CONTINUED	(__SI_CHLD|6)	/* stopped child has continued */
+#define CLD_EXITED	1	/* child has exited */
+#define CLD_KILLED	2	/* child was killed */
+#define CLD_DUMPED	3	/* child terminated abnormally */
+#define CLD_TRAPPED	4	/* traced child has trapped */
+#define CLD_STOPPED	5	/* child has stopped */
+#define CLD_CONTINUED	6	/* stopped child has continued */
 #define NSIGCHLD	6
 
 /*
  * SIGPOLL (or any other signal without signal specific si_codes) si_codes
  */
-#define POLL_IN		(__SI_POLL|1)	/* data input available */
-#define POLL_OUT	(__SI_POLL|2)	/* output buffers available */
-#define POLL_MSG	(__SI_POLL|3)	/* input message available */
-#define POLL_ERR	(__SI_POLL|4)	/* i/o error */
-#define POLL_PRI	(__SI_POLL|5)	/* high priority input available */
-#define POLL_HUP	(__SI_POLL|6)	/* device disconnected */
+#define POLL_IN		1	/* data input available */
+#define POLL_OUT	2	/* output buffers available */
+#define POLL_MSG	3	/* input message available */
+#define POLL_ERR	4	/* i/o error */
+#define POLL_PRI	5	/* high priority input available */
+#define POLL_HUP	6	/* device disconnected */
 #define NSIGPOLL	6
 
 /*
  * SIGSYS si_codes
  */
-#define SYS_SECCOMP		(__SI_SYS|1)	/* seccomp triggered */
-#define NSIGSYS	1
+#define SYS_SECCOMP	1	/* seccomp triggered */
+#define NSIGSYS		1
 
 /*
  * sigevent definitions
diff --git a/kernel/compat.c b/kernel/compat.c
index 933bcb31ae10..bb6ccbf78f25 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -604,8 +604,6 @@ COMPAT_SYSCALL_DEFINE5(waitid,
 			return -EFAULT;
 	}
 
-	BUG_ON(info.si_code & __SI_MASK);
-	info.si_code |= __SI_CHLD;
 	return copy_siginfo_to_user32(uinfo, &info);
 }
 
diff --git a/kernel/exit.c b/kernel/exit.c
index 516acdb0e0ec..520bc848297c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1064,7 +1064,7 @@ static int wait_noreap_copyout(struct wait_opts *wo, struct task_struct *p,
 		if (!retval)
 			retval = put_user(0, &infop->si_errno);
 		if (!retval)
-			retval = put_user((short)why, &infop->si_code);
+			retval = put_user(why, &infop->si_code);
 		if (!retval)
 			retval = put_user(pid, &infop->si_pid);
 		if (!retval)
@@ -1203,7 +1203,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
 			why = (status & 0x80) ? CLD_DUMPED : CLD_KILLED;
 			status &= 0x7f;
 		}
-		retval = put_user((short)why, &infop->si_code);
+		retval = put_user(why, &infop->si_code);
 		if (!retval)
 			retval = put_user(status, &infop->si_status);
 	}
@@ -1326,7 +1326,7 @@ static int wait_task_stopped(struct wait_opts *wo,
 	if (!retval && infop)
 		retval = put_user(0, &infop->si_errno);
 	if (!retval && infop)
-		retval = put_user((short)why, &infop->si_code);
+		retval = put_user(why, &infop->si_code);
 	if (!retval && infop)
 		retval = put_user(exit_code, &infop->si_status);
 	if (!retval && infop)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 266ddcc1d8bb..885ec5e5c9df 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -722,8 +722,7 @@ static int ptrace_peek_siginfo(struct task_struct *child,
 		if (unlikely(in_compat_syscall())) {
 			compat_siginfo_t __user *uinfo = compat_ptr(data);
 
-			if (copy_siginfo_to_user32(uinfo, &info) ||
-			    __put_user(info.si_code, &uinfo->si_code)) {
+			if (copy_siginfo_to_user32(uinfo, &info)) {
 				ret = -EFAULT;
 				break;
 			}
@@ -733,8 +732,7 @@ static int ptrace_peek_siginfo(struct task_struct *child,
 		{
 			siginfo_t __user *uinfo = (siginfo_t __user *) data;
 
-			if (copy_siginfo_to_user(uinfo, &info) ||
-			    __put_user(info.si_code, &uinfo->si_code)) {
+			if (copy_siginfo_to_user(uinfo, &info)) {
 				ret = -EFAULT;
 				break;
 			}
diff --git a/kernel/signal.c b/kernel/signal.c
index 45b4c1ffe14e..e55d6c5159f2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2678,6 +2678,51 @@ COMPAT_SYSCALL_DEFINE2(rt_sigpending, compat_sigset_t __user *, uset,
 }
 #endif
 
+enum siginfo_layout siginfo_layout(int sig, int si_code)
+{
+	enum siginfo_layout layout = SIL_KILL;
+	if ((si_code > SI_USER) && (si_code < SI_KERNEL)) {
+		static const struct {
+			unsigned char limit, layout;
+		} filter[] = {
+			[SIGILL]  = { NSIGILL,  SIL_FAULT },
+			[SIGFPE]  = { NSIGFPE,  SIL_FAULT },
+			[SIGSEGV] = { NSIGSEGV, SIL_FAULT },
+			[SIGBUS]  = { NSIGBUS,  SIL_FAULT },
+			[SIGTRAP] = { NSIGTRAP, SIL_FAULT },
+#if defined(SIGMET) && defined(NSIGEMT)
+			[SIGEMT]  = { NSIGEMT,  SIL_FAULT },
+#endif
+			[SIGCHLD] = { NSIGCHLD, SIL_CHLD },
+			[SIGPOLL] = { NSIGPOLL, SIL_POLL },
+#ifdef __ARCH_SIGSYS
+			[SIGSYS]  = { NSIGSYS,  SIL_SYS },
+#endif
+		};
+		if ((sig < ARRAY_SIZE(filter)) && (si_code <= filter[sig].limit))
+			layout = filter[sig].layout;
+		else if (si_code <= NSIGPOLL)
+			layout = SIL_POLL;
+	} else {
+		if (si_code == SI_TIMER)
+			layout = SIL_TIMER;
+		else if (si_code == SI_SIGIO)
+			layout = SIL_POLL;
+		else if (si_code < 0)
+			layout = SIL_RT;
+		/* Tests to support buggy kernel ABIs */
+#ifdef TRAP_FIXME
+		if ((sig == SIGTRAP) && (si_code == TRAP_FIXME))
+			layout = SIL_FAULT;
+#endif
+#ifdef FPE_FIXME
+		if ((sig == SIGFPE) && (si_code == FPE_FIXME))
+			layout = SIL_FAULT;
+#endif
+	}
+	return layout;
+}
+
 #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
 
 int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
@@ -2700,22 +2745,20 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
 	 */
 	err = __put_user(from->si_signo, &to->si_signo);
 	err |= __put_user(from->si_errno, &to->si_errno);
-	err |= __put_user((short)from->si_code, &to->si_code);
-	switch (from->si_code & __SI_MASK) {
-	case __SI_KILL:
+	err |= __put_user(from->si_code, &to->si_code);
+	switch (siginfo_layout(from->si_signo, from->si_code)) {
+	case SIL_KILL:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		break;
-	case __SI_TIMER:
-		 err |= __put_user(from->si_tid, &to->si_tid);
-		 err |= __put_user(from->si_overrun, &to->si_overrun);
-		 err |= __put_user(from->si_ptr, &to->si_ptr);
+	case SIL_TIMER:
+		/* Unreached SI_TIMER is negative */
 		break;
-	case __SI_POLL:
+	case SIL_POLL:
 		err |= __put_user(from->si_band, &to->si_band);
 		err |= __put_user(from->si_fd, &to->si_fd);
 		break;
-	case __SI_FAULT:
+	case SIL_FAULT:
 		err |= __put_user(from->si_addr, &to->si_addr);
 #ifdef __ARCH_SI_TRAPNO
 		err |= __put_user(from->si_trapno, &to->si_trapno);
@@ -2740,30 +2783,25 @@ int copy_siginfo_to_user(siginfo_t __user *to, const siginfo_t *from)
 			err |= __put_user(from->si_pkey, &to->si_pkey);
 #endif
 		break;
-	case __SI_CHLD:
+	case SIL_CHLD:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_status, &to->si_status);
 		err |= __put_user(from->si_utime, &to->si_utime);
 		err |= __put_user(from->si_stime, &to->si_stime);
 		break;
-	case __SI_RT: /* This is not generated by the kernel as of now. */
-	case __SI_MESGQ: /* But this is */
+	case SIL_RT:
 		err |= __put_user(from->si_pid, &to->si_pid);
 		err |= __put_user(from->si_uid, &to->si_uid);
 		err |= __put_user(from->si_ptr, &to->si_ptr);
 		break;
 #ifdef __ARCH_SIGSYS
-	case __SI_SYS:
+	case SIL_SYS:
 		err |= __put_user(from->si_call_addr, &to->si_call_addr);
 		err |= __put_user(from->si_syscall, &to->si_syscall);
 		err |= __put_user(from->si_arch, &to->si_arch);
 		break;
 #endif
-	default: /* this is just in case for now ... */
-		err |= __put_user(from->si_pid, &to->si_pid);
-		err |= __put_user(from->si_uid, &to->si_uid);
-		break;
 	}
 	return err;
 }
-- 
2.10.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found]     ` <20170630123906.8865-3-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-06-30 16:45       ` David Miller
  0 siblings, 0 replies; 49+ messages in thread
From: David Miller @ 2017-06-30 16:45 UTC (permalink / raw)
  To: ebiederm-aS9lmoZGLiVWk0Htik3J/w
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	greg-U8xfFu+wG4EAvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, oleg-H+wXaHxf7aLQT0dZR+AlfA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	sparclinux-u79uwXL29TY76Z2rM5mHXA,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	luto-DgEjT+Ai2ygdnm+yROfE0A, linux-api-u79uwXL29TY76Z2rM5mHXA,
	gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, tglx-hfZtesqFncYOwBW4kG4KsQ,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, w,
	avagin-GEFAQzZX7r8dnm+yROfE0A

From: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Date: Fri, 30 Jun 2017 07:39:01 -0500

> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
> index 2d9b79ccaa50..6bc5c677e92f 100644
> --- a/arch/sparc/include/uapi/asm/siginfo.h
> +++ b/arch/sparc/include/uapi/asm/siginfo.h
> @@ -17,6 +17,11 @@
>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>  
>  /*
> + * SIGFPE si_codes
> + */
> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
> +
> +/*
>   * SIGEMT si_codes
>   */
>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */

It's one thing to say FIXME in a comment in a kernel local header or
C file.

It's quite another to put this into the name of a macro which has
visibility in the global user compilation namespace.

I don't think you should really do that.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
  2017-06-30 12:39     ` Eric W. Biederman
@ 2017-06-30 16:45       ` David Miller
  -1 siblings, 0 replies; 49+ messages in thread
From: David Miller @ 2017-06-30 16:45 UTC (permalink / raw)
  To: ebiederm
  Cc: linux-kernel, luto, torvalds, viro, oleg, avagin, tglx, greg,
	avagin, serge, xemul, gorcunov, peterz, w, linux-arch, linux-api,
	containers, mtk.manpages, sparclinux

From: "Eric W. Biederman" <ebiederm@xmission.com>
Date: Fri, 30 Jun 2017 07:39:01 -0500

> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
> index 2d9b79ccaa50..6bc5c677e92f 100644
> --- a/arch/sparc/include/uapi/asm/siginfo.h
> +++ b/arch/sparc/include/uapi/asm/siginfo.h
> @@ -17,6 +17,11 @@
>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>  
>  /*
> + * SIGFPE si_codes
> + */
> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
> +
> +/*
>   * SIGEMT si_codes
>   */
>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */

It's one thing to say FIXME in a comment in a kernel local header or
C file.

It's quite another to put this into the name of a macro which has
visibility in the global user compilation namespace.

I don't think you should really do that.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 16:45       ` David Miller
  0 siblings, 0 replies; 49+ messages in thread
From: David Miller @ 2017-06-30 16:45 UTC (permalink / raw)
  To: ebiederm
  Cc: linux-kernel, luto, torvalds, viro, oleg, avagin, tglx, greg,
	avagin, serge, xemul, gorcunov, peterz, w, linux-arch, linux-api,
	containers, mtk.manpages, sparclinux

From: "Eric W. Biederman" <ebiederm@xmission.com>
Date: Fri, 30 Jun 2017 07:39:01 -0500

> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
> index 2d9b79ccaa50..6bc5c677e92f 100644
> --- a/arch/sparc/include/uapi/asm/siginfo.h
> +++ b/arch/sparc/include/uapi/asm/siginfo.h
> @@ -17,6 +17,11 @@
>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>  
>  /*
> + * SIGFPE si_codes
> + */
> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
> +
> +/*
>   * SIGEMT si_codes
>   */
>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */

It's one thing to say FIXME in a comment in a kernel local header or
C file.

It's quite another to put this into the name of a macro which has
visibility in the global user compilation namespace.

I don't think you should really do that.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
  2017-06-30 16:45       ` David Miller
  (?)
@ 2017-06-30 18:13           ` Eric W. Biederman
  -1 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 18:13 UTC (permalink / raw)
  To: David Miller
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	greg-U8xfFu+wG4EAvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, oleg-H+wXaHxf7aLQT0dZR+AlfA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	sparclinux-u79uwXL29TY76Z2rM5mHXA,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	luto-DgEjT+Ai2ygdnm+yROfE0A, linux-api-u79uwXL29TY76Z2rM5mHXA,
	gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, tglx-hfZtesqFncYOwBW4kG4KsQ,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, w,
	avagin-GEFAQzZX7r8dnm+yROfE0A

David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> writes:

> From: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
> Date: Fri, 30 Jun 2017 07:39:01 -0500
>
>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>> index 2d9b79ccaa50..6bc5c677e92f 100644
>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>> @@ -17,6 +17,11 @@
>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>  
>>  /*
>> + * SIGFPE si_codes
>> + */
>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>> +
>> +/*
>>   * SIGEMT si_codes
>>   */
>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>
> It's one thing to say FIXME in a comment in a kernel local header or
> C file.
>
> It's quite another to put this into the name of a macro which has
> visibility in the global user compilation namespace.
>
> I don't think you should really do that.

Good point.

Sigh.   It almost fits because we did do something off in the uapi
exported to userspace and we don't have a header file definition for
that case.

Still.  At this point arch/sparc/include/asm/siginfo.h is
a better fit for that definition.

I will respin and fix that.

I wish I knew what would make a better default floating point si_code on
sparc.  Using 0 aka SI_USER is doesn't fit at all.  Sigh.

Unfortunately I don't know the architecture well enough to even guess
what is going on in do_fpe_common when when no bits in fsr are set.

Any suggests for a better fix than just documenting that linux does
something weird and ill advised here?

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 18:13           ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 18:13 UTC (permalink / raw)
  To: David Miller
  Cc: linux-kernel, luto, torvalds, viro, oleg, avagin, tglx, greg,
	avagin, serge, xemul, gorcunov, peterz, w, linux-arch, linux-api,
	containers, mtk.manpages, sparclinux

David Miller <davem@davemloft.net> writes:

> From: "Eric W. Biederman" <ebiederm@xmission.com>
> Date: Fri, 30 Jun 2017 07:39:01 -0500
>
>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>> index 2d9b79ccaa50..6bc5c677e92f 100644
>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>> @@ -17,6 +17,11 @@
>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>  
>>  /*
>> + * SIGFPE si_codes
>> + */
>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>> +
>> +/*
>>   * SIGEMT si_codes
>>   */
>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>
> It's one thing to say FIXME in a comment in a kernel local header or
> C file.
>
> It's quite another to put this into the name of a macro which has
> visibility in the global user compilation namespace.
>
> I don't think you should really do that.

Good point.

Sigh.   It almost fits because we did do something off in the uapi
exported to userspace and we don't have a header file definition for
that case.

Still.  At this point arch/sparc/include/asm/siginfo.h is
a better fit for that definition.

I will respin and fix that.

I wish I knew what would make a better default floating point si_code on
sparc.  Using 0 aka SI_USER is doesn't fit at all.  Sigh.

Unfortunately I don't know the architecture well enough to even guess
what is going on in do_fpe_common when when no bits in fsr are set.

Any suggests for a better fix than just documenting that linux does
something weird and ill advised here?

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-06-30 18:13           ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-06-30 18:13 UTC (permalink / raw)
  To: David Miller
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	greg-U8xfFu+wG4EAvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, oleg-H+wXaHxf7aLQT0dZR+AlfA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	sparclinux-u79uwXL29TY76Z2rM5mHXA,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	luto-DgEjT+Ai2ygdnm+yROfE0A, linux-api-u79uwXL29TY76Z2rM5mHXA,
	gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, tglx-hfZtesqFncYOwBW4kG4KsQ,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, w,
	avagin-GEFAQzZX7r8dnm+yROfE0A

David Miller <davem@davemloft.net> writes:

> From: "Eric W. Biederman" <ebiederm@xmission.com>
> Date: Fri, 30 Jun 2017 07:39:01 -0500
>
>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>> index 2d9b79ccaa50..6bc5c677e92f 100644
>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>> @@ -17,6 +17,11 @@
>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>  
>>  /*
>> + * SIGFPE si_codes
>> + */
>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>> +
>> +/*
>>   * SIGEMT si_codes
>>   */
>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>
> It's one thing to say FIXME in a comment in a kernel local header or
> C file.
>
> It's quite another to put this into the name of a macro which has
> visibility in the global user compilation namespace.
>
> I don't think you should really do that.

Good point.

Sigh.   It almost fits because we did do something off in the uapi
exported to userspace and we don't have a header file definition for
that case.

Still.  At this point arch/sparc/include/asm/siginfo.h is
a better fit for that definition.

I will respin and fix that.

I wish I knew what would make a better default floating point si_code on
sparc.  Using 0 aka SI_USER is doesn't fit at all.  Sigh.

Unfortunately I don't know the architecture well enough to even guess
what is going on in do_fpe_common when when no bits in fsr are set.

Any suggests for a better fix than just documenting that linux does
something weird and ill advised here?

Eric


^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
       [not found]     ` <20170630123906.8865-1-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-07-02 14:13       ` Helge Deller
  0 siblings, 0 replies; 49+ messages in thread
From: Helge Deller @ 2017-07-02 14:13 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Andrei Vagin, Greg KH, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Pavel Emelyanov, linux-arch-u79uwXL29TY76Z2rM5mHXA,
	Michael Kerrisk, Matt Turner, Ivan Kokshaysky, Al Viro,
	Andy Lutomirski, Cyrill Gorcunov, Thomas Gleixner,
	Richard Henderson, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, linux-alpha-u79uwXL29TY76Z2rM5mHXA,
	Linus Torvalds, Willy Tarreau

* Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>:
> Setting si_code to __SI_FAULT results in a userspace seeing
> an si_code of 0.  This is the same si_code as SI_USER.  Posix
> and common sense requires that SI_USER not be a signal specific
> si_code.  As such this use of 0 for the si_code is a pretty
> horribly broken ABI.
> 
> Given that alpha is on it's last legs I don't know that it is worth
> fixing this, but it is worth documenting what is going on so that
> no one decides to copy this bad decision.

The ABI was already broken, so IMHO I think it's better to somehow "fix"
it instead. Agreed, alpha and some other architectures are already aged,
but nevertheless most of them build in debian-ports.  Below is a
suggested fix which reuses/misuses other existing trap codes instead.

Helge

Signed-off-by: Helge Deller <deller-Mmb7MZpHnFY@public.gmane.org>

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102..2ed37dd 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_HWBKPT;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = FPE_FLTSUB;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_HWBKPT;
 			break;
 		}

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
  2017-06-30 12:38     ` Eric W. Biederman
@ 2017-07-02 14:13       ` Helge Deller
  -1 siblings, 0 replies; 49+ messages in thread
From: Helge Deller @ 2017-07-02 14:13 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-kernel, Andy Lutomirski, Linus Torvalds, Al Viro,
	Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

* Eric W. Biederman <ebiederm@xmission.com>:
> Setting si_code to __SI_FAULT results in a userspace seeing
> an si_code of 0.  This is the same si_code as SI_USER.  Posix
> and common sense requires that SI_USER not be a signal specific
> si_code.  As such this use of 0 for the si_code is a pretty
> horribly broken ABI.
> 
> Given that alpha is on it's last legs I don't know that it is worth
> fixing this, but it is worth documenting what is going on so that
> no one decides to copy this bad decision.

The ABI was already broken, so IMHO I think it's better to somehow "fix"
it instead. Agreed, alpha and some other architectures are already aged,
but nevertheless most of them build in debian-ports.  Below is a
suggested fix which reuses/misuses other existing trap codes instead.

Helge

Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102..2ed37dd 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_HWBKPT;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = FPE_FLTSUB;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_HWBKPT;
 			break;
 		}
 

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
@ 2017-07-02 14:13       ` Helge Deller
  0 siblings, 0 replies; 49+ messages in thread
From: Helge Deller @ 2017-07-02 14:13 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-kernel, Andy Lutomirski, Linus Torvalds, Al Viro,
	Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky, Matt Turner

* Eric W. Biederman <ebiederm@xmission.com>:
> Setting si_code to __SI_FAULT results in a userspace seeing
> an si_code of 0.  This is the same si_code as SI_USER.  Posix
> and common sense requires that SI_USER not be a signal specific
> si_code.  As such this use of 0 for the si_code is a pretty
> horribly broken ABI.
> 
> Given that alpha is on it's last legs I don't know that it is worth
> fixing this, but it is worth documenting what is going on so that
> no one decides to copy this bad decision.

The ABI was already broken, so IMHO I think it's better to somehow "fix"
it instead. Agreed, alpha and some other architectures are already aged,
but nevertheless most of them build in debian-ports.  Below is a
suggested fix which reuses/misuses other existing trap codes instead.

Helge

Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 65bb102..2ed37dd 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 	      case 1: /* bugcheck */
 		info.si_signo = SIGTRAP;
 		info.si_errno = 0;
-		info.si_code = __SI_FAULT;
+		info.si_code = TRAP_HWBKPT;
 		info.si_addr = (void __user *) regs->pc;
 		info.si_trapno = 0;
 		send_sig_info(SIGTRAP, &info, current);
@@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 			break;
 		case GEN_ROPRAND:
 			signo = SIGFPE;
-			code = __SI_FAULT;
+			code = FPE_FLTSUB;
 			break;
 
 		case GEN_DECOVF:
@@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
 		case GEN_SUBRNG7:
 		default:
 			signo = SIGTRAP;
-			code = __SI_FAULT;
+			code = TRAP_HWBKPT;
 			break;
 		}
 



^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH 8/8] signal: Remove kernel interal si_code magic
  2017-06-30 12:39       ` Eric W. Biederman
@ 2017-07-12 22:36           ` Andrei Vagin
  -1 siblings, 0 replies; 49+ messages in thread
From: Andrei Vagin @ 2017-07-12 22:36 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Andrey Vagin, Greg KH,
	Linux Containers, Oleg Nesterov,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Pavel Emelyanov,
	Linus Torvalds, Willy Tarreau

On Fri, Jun 30, 2017 at 07:39:06AM -0500, Eric W. Biederman wrote:
> struct siginfo is a union and the kernel since 2.4 has been hiding a union
> tag in the high 16bits of si_code using the values:
> __SI_KILL
> __SI_TIMER
> __SI_POLL
> __SI_FAULT
> __SI_CHLD
> __SI_RT
> __SI_MESGQ
> __SI_SYS
> 
> While this looks plausible on the surface, in practice this situation has
> not worked well.
> 
> - Injected positive signals are not copied to user space properly
>   unless they have these magic high bits set.
> 
> - Injected positive signals are not reported properly by signalfd
>   unless they have these magic high bits set.
> 
> - These kernel internal values leaked to userspace via ptrace_peek_siginfo
> 
> - It was possible to inject these kernel internal values and cause the
>   the kernel to misbehave.
> 
> - Kernel developers got confused and expected these kernel internal values
>   in userspace in kernel self tests.
> 
> - Kernel developers got confused and set si_code to __SI_FAULT which
>   is SI_USER in userspace which causes userspace to think an ordinary user
>   sent the signal and that it was not kernel generated.
> 
> - The values make it impossible to reorganize the code to transform
>   siginfo_copy_to_user into a plain copy_to_user.  As si_code must
>   be massaged before being passed to userspace.
> 
> So remove these kernel internal si codes and make the kernel code simpler
> and more maintainable.
> 
> To replace these kernel internal magic si_codes introduce the helper
> function siginfo_layout, that takes a signal number and an si_code and
> computes which union member of siginfo is being used.  Have
> siginfo_layout return an enumeration so that gcc will have enough
> information to warn if a switch statement does not handle all of union
> members.
> 
> A couple of architectures have a messed up ABI that defines signal
> specific duplications of SI_USER which causes more special cases in
> siginfo_layout than I would like.  The good news is only problem
> architectures pay the cost.
> 
> Update all of the code that used the previous magic __SI_ values to
> use the new SIL_ values and to call siginfo_layout to get those
> values.  Escept where not all of the cases are handled remove the
> defaults in the switch statements so that if a new case is missed in
> the future the lack will show up at compile time.
> 
> Modify the code that copies siginfo si_code to userspace to just copy
> the value and not cast si_code to a short first.  The high bits are no
> longer used to hold a magic union member.
> 
> Fixup the siginfo header files to stop including the __SI_ values in
> their constants and for the headers that were missing it to properly
> update the number of si_codes for each signal type.
> 
> The fixes to copy_siginfo_from_user32 implementations has the
> interesting property that several of them perviously should never have
> worked as the __SI_ values they depended up where kernel internal.
> With that dependency gone those implementations should work much
> better.
> 
> The idea of not passing the __SI_ values out to userspace and then
> not reinserting them has been tested with criu and criu worked without
> changes.
> 
> Signed-off-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
> ---
>  arch/alpha/include/uapi/asm/siginfo.h    |   2 +-
>  arch/arm64/kernel/signal32.c             |  23 +++----
>  arch/blackfin/include/uapi/asm/siginfo.h |  30 +++++----
>  arch/frv/include/uapi/asm/siginfo.h      |   2 +-
>  arch/ia64/include/uapi/asm/siginfo.h     |  20 +++---
>  arch/ia64/kernel/signal.c                |  17 +++---
>  arch/mips/include/uapi/asm/siginfo.h     |   6 +-
>  arch/mips/kernel/signal32.c              |  19 +++---
>  arch/parisc/kernel/signal32.c            |  31 +++++-----
>  arch/powerpc/kernel/signal_32.c          |  20 +++---
>  arch/s390/kernel/compat_signal.c         |  32 +++++-----
>  arch/sparc/include/uapi/asm/siginfo.h    |   4 +-
>  arch/sparc/kernel/signal32.c             |  16 ++---
>  arch/tile/include/uapi/asm/siginfo.h     |   4 +-
>  arch/tile/kernel/compat_signal.c         |  18 +++---
>  arch/tile/kernel/traps.c                 |   1 -
>  arch/x86/kernel/signal_compat.c          |  21 +++----
>  fs/fcntl.c                               |   2 +-
>  fs/signalfd.c                            |  22 +++----
>  include/asm-generic/siginfo.h            |  22 ++++---
>  include/uapi/asm-generic/siginfo.h       | 102 ++++++++++++++-----------------
>  kernel/compat.c                          |   2 -
>  kernel/exit.c                            |   6 +-
>  kernel/ptrace.c                          |   6 +-
>  kernel/signal.c                          |  72 ++++++++++++++++------
>  25 files changed, 254 insertions(+), 246 deletions(-)
> 
<...>
> diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
> index 54804866f238..4433d1dc28e6 100644
> --- a/arch/tile/kernel/traps.c
> +++ b/arch/tile/kernel/traps.c
> @@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
>  
>  	/* Make it the requested signal. */
>  	*sigp = sig;
> -	*codep = code | __SI_FAULT;

Are you sure that we don't need to set codep here?

>  	return 1;
>  }
>  

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 8/8] signal: Remove kernel interal si_code magic
@ 2017-07-12 22:36           ` Andrei Vagin
  0 siblings, 0 replies; 49+ messages in thread
From: Andrei Vagin @ 2017-07-12 22:36 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-kernel, Andy Lutomirski, Linus Torvalds, Al Viro,
	Oleg Nesterov, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk

On Fri, Jun 30, 2017 at 07:39:06AM -0500, Eric W. Biederman wrote:
> struct siginfo is a union and the kernel since 2.4 has been hiding a union
> tag in the high 16bits of si_code using the values:
> __SI_KILL
> __SI_TIMER
> __SI_POLL
> __SI_FAULT
> __SI_CHLD
> __SI_RT
> __SI_MESGQ
> __SI_SYS
> 
> While this looks plausible on the surface, in practice this situation has
> not worked well.
> 
> - Injected positive signals are not copied to user space properly
>   unless they have these magic high bits set.
> 
> - Injected positive signals are not reported properly by signalfd
>   unless they have these magic high bits set.
> 
> - These kernel internal values leaked to userspace via ptrace_peek_siginfo
> 
> - It was possible to inject these kernel internal values and cause the
>   the kernel to misbehave.
> 
> - Kernel developers got confused and expected these kernel internal values
>   in userspace in kernel self tests.
> 
> - Kernel developers got confused and set si_code to __SI_FAULT which
>   is SI_USER in userspace which causes userspace to think an ordinary user
>   sent the signal and that it was not kernel generated.
> 
> - The values make it impossible to reorganize the code to transform
>   siginfo_copy_to_user into a plain copy_to_user.  As si_code must
>   be massaged before being passed to userspace.
> 
> So remove these kernel internal si codes and make the kernel code simpler
> and more maintainable.
> 
> To replace these kernel internal magic si_codes introduce the helper
> function siginfo_layout, that takes a signal number and an si_code and
> computes which union member of siginfo is being used.  Have
> siginfo_layout return an enumeration so that gcc will have enough
> information to warn if a switch statement does not handle all of union
> members.
> 
> A couple of architectures have a messed up ABI that defines signal
> specific duplications of SI_USER which causes more special cases in
> siginfo_layout than I would like.  The good news is only problem
> architectures pay the cost.
> 
> Update all of the code that used the previous magic __SI_ values to
> use the new SIL_ values and to call siginfo_layout to get those
> values.  Escept where not all of the cases are handled remove the
> defaults in the switch statements so that if a new case is missed in
> the future the lack will show up at compile time.
> 
> Modify the code that copies siginfo si_code to userspace to just copy
> the value and not cast si_code to a short first.  The high bits are no
> longer used to hold a magic union member.
> 
> Fixup the siginfo header files to stop including the __SI_ values in
> their constants and for the headers that were missing it to properly
> update the number of si_codes for each signal type.
> 
> The fixes to copy_siginfo_from_user32 implementations has the
> interesting property that several of them perviously should never have
> worked as the __SI_ values they depended up where kernel internal.
> With that dependency gone those implementations should work much
> better.
> 
> The idea of not passing the __SI_ values out to userspace and then
> not reinserting them has been tested with criu and criu worked without
> changes.
> 
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>  arch/alpha/include/uapi/asm/siginfo.h    |   2 +-
>  arch/arm64/kernel/signal32.c             |  23 +++----
>  arch/blackfin/include/uapi/asm/siginfo.h |  30 +++++----
>  arch/frv/include/uapi/asm/siginfo.h      |   2 +-
>  arch/ia64/include/uapi/asm/siginfo.h     |  20 +++---
>  arch/ia64/kernel/signal.c                |  17 +++---
>  arch/mips/include/uapi/asm/siginfo.h     |   6 +-
>  arch/mips/kernel/signal32.c              |  19 +++---
>  arch/parisc/kernel/signal32.c            |  31 +++++-----
>  arch/powerpc/kernel/signal_32.c          |  20 +++---
>  arch/s390/kernel/compat_signal.c         |  32 +++++-----
>  arch/sparc/include/uapi/asm/siginfo.h    |   4 +-
>  arch/sparc/kernel/signal32.c             |  16 ++---
>  arch/tile/include/uapi/asm/siginfo.h     |   4 +-
>  arch/tile/kernel/compat_signal.c         |  18 +++---
>  arch/tile/kernel/traps.c                 |   1 -
>  arch/x86/kernel/signal_compat.c          |  21 +++----
>  fs/fcntl.c                               |   2 +-
>  fs/signalfd.c                            |  22 +++----
>  include/asm-generic/siginfo.h            |  22 ++++---
>  include/uapi/asm-generic/siginfo.h       | 102 ++++++++++++++-----------------
>  kernel/compat.c                          |   2 -
>  kernel/exit.c                            |   6 +-
>  kernel/ptrace.c                          |   6 +-
>  kernel/signal.c                          |  72 ++++++++++++++++------
>  25 files changed, 254 insertions(+), 246 deletions(-)
> 
<...>
> diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
> index 54804866f238..4433d1dc28e6 100644
> --- a/arch/tile/kernel/traps.c
> +++ b/arch/tile/kernel/traps.c
> @@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
>  
>  	/* Make it the requested signal. */
>  	*sigp = sig;
> -	*codep = code | __SI_FAULT;

Are you sure that we don't need to set codep here?

>  	return 1;
>  }
>  

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 8/8] signal: Remove kernel interal si_code magic
       [not found]           ` <20170712223557.GA21885-1ViLX0X+lBJGNQ1M2rI3KwRV3xvJKrda@public.gmane.org>
@ 2017-07-12 23:08             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-12 23:08 UTC (permalink / raw)
  To: Andrei Vagin
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, Andrey Vagin, Greg KH,
	Linux Containers, Oleg Nesterov,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Al Viro, Andy Lutomirski,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Cyrill Gorcunov,
	Michael Kerrisk, Thomas Gleixner, Pavel Emelyanov,
	Linus Torvalds, Willy Tarreau

Andrei Vagin <avagin-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org> writes:

>> diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
>> index 54804866f238..4433d1dc28e6 100644
>> --- a/arch/tile/kernel/traps.c
>> +++ b/arch/tile/kernel/traps.c
>> @@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
>>  
>>  	/* Make it the requested signal. */
>>  	*sigp = sig;
>> -	*codep = code | __SI_FAULT;
>
> Are you sure that we don't need to set codep here?

Looking closely we definitely do.  Good catch.  Thank you.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 8/8] signal: Remove kernel interal si_code magic
  2017-07-12 22:36           ` Andrei Vagin
  (?)
  (?)
@ 2017-07-12 23:08           ` Eric W. Biederman
  -1 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-12 23:08 UTC (permalink / raw)
  To: Andrei Vagin
  Cc: linux-kernel, Andy Lutomirski, Linus Torvalds, Al Viro,
	Oleg Nesterov, Thomas Gleixner, Greg KH, Andrey Vagin,
	Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra,
	Willy Tarreau, linux-arch, linux-api, Linux Containers,
	Michael Kerrisk

Andrei Vagin <avagin@virtuozzo.com> writes:

>> diff --git a/arch/tile/kernel/traps.c b/arch/tile/kernel/traps.c
>> index 54804866f238..4433d1dc28e6 100644
>> --- a/arch/tile/kernel/traps.c
>> +++ b/arch/tile/kernel/traps.c
>> @@ -188,7 +188,6 @@ static int special_ill(tile_bundle_bits bundle, int *sigp, int *codep)
>>  
>>  	/* Make it the requested signal. */
>>  	*sigp = sig;
>> -	*codep = code | __SI_FAULT;
>
> Are you sure that we don't need to set codep here?

Looking closely we definitely do.  Good catch.  Thank you.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
       [not found]       ` <20170702141320.GA32254-PwtjyNU/e7vkVFMGpb/cPg@public.gmane.org>
@ 2017-07-14 10:59         ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-14 10:59 UTC (permalink / raw)
  To: Helge Deller
  Cc: Andrei Vagin, Greg KH, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Pavel Emelyanov, linux-arch-u79uwXL29TY76Z2rM5mHXA,
	Michael Kerrisk, Matt Turner, Ivan Kokshaysky, Al Viro,
	Andy Lutomirski, Cyrill Gorcunov, Thomas Gleixner,
	Richard Henderson, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, linux-alpha-u79uwXL29TY76Z2rM5mHXA,
	Linus Torvalds, Willy Tarreau

Helge Deller <deller-Mmb7MZpHnFY@public.gmane.org> writes:

> * Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>:
>> Setting si_code to __SI_FAULT results in a userspace seeing
>> an si_code of 0.  This is the same si_code as SI_USER.  Posix
>> and common sense requires that SI_USER not be a signal specific
>> si_code.  As such this use of 0 for the si_code is a pretty
>> horribly broken ABI.
>> 
>> Given that alpha is on it's last legs I don't know that it is worth
>> fixing this, but it is worth documenting what is going on so that
>> no one decides to copy this bad decision.
>
> The ABI was already broken, so IMHO I think it's better to somehow "fix"
> it instead. Agreed, alpha and some other architectures are already aged,
> but nevertheless most of them build in debian-ports.  Below is a
> suggested fix which reuses/misuses other existing trap codes instead.

The conflict with SI_USER is real.  I don't know that we have any actual
applications that are suffering.

I simply don't have the architecture specific references handy to know
in which cases the oddities will happen let alone test them.  Plus at
least for ia64 and alpha those architectures don't appear to be
receiving updates for new syscalls, and no new hardware is being built
so I don't know how much longer they will last.

That is building for alpha gives:
>   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

But a real fix like you have shown if you can get it approved by the
alpha architecture maintainers I am more than happy to see, and would
very much prefer.

You certainly noticed that the middle case was SIGFPE when I missed
that.

Unfortunately I don't currently have the competence to judge the
effects of your patch.

Eric

> Helge
>
> Signed-off-by: Helge Deller <deller-Mmb7MZpHnFY@public.gmane.org>
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 65bb102..2ed37dd 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  	      case 1: /* bugcheck */
>  		info.si_signo = SIGTRAP;
>  		info.si_errno = 0;
> -		info.si_code = __SI_FAULT;
> +		info.si_code = TRAP_HWBKPT;
>  		info.si_addr = (void __user *) regs->pc;
>  		info.si_trapno = 0;
>  		send_sig_info(SIGTRAP, &info, current);
> @@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  			break;
>  		case GEN_ROPRAND:
>  			signo = SIGFPE;
> -			code = __SI_FAULT;
> +			code = FPE_FLTSUB;
>  			break;
>  
>  		case GEN_DECOVF:
> @@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  		case GEN_SUBRNG7:
>  		default:
>  			signo = SIGTRAP;
> -			code = __SI_FAULT;
> +			code = TRAP_HWBKPT;
>  			break;
>  		}
>  

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
       [not found]       ` <20170702141320.GA32254-PwtjyNU/e7vkVFMGpb/cPg@public.gmane.org>
@ 2017-07-14 10:59         ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-14 10:59 UTC (permalink / raw)
  To: Helge Deller
  Cc: linux-kernel, Andy Lutomirski, Linus Torvalds, Al Viro,
	Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

Helge Deller <deller@gmx.de> writes:

> * Eric W. Biederman <ebiederm@xmission.com>:
>> Setting si_code to __SI_FAULT results in a userspace seeing
>> an si_code of 0.  This is the same si_code as SI_USER.  Posix
>> and common sense requires that SI_USER not be a signal specific
>> si_code.  As such this use of 0 for the si_code is a pretty
>> horribly broken ABI.
>> 
>> Given that alpha is on it's last legs I don't know that it is worth
>> fixing this, but it is worth documenting what is going on so that
>> no one decides to copy this bad decision.
>
> The ABI was already broken, so IMHO I think it's better to somehow "fix"
> it instead. Agreed, alpha and some other architectures are already aged,
> but nevertheless most of them build in debian-ports.  Below is a
> suggested fix which reuses/misuses other existing trap codes instead.

The conflict with SI_USER is real.  I don't know that we have any actual
applications that are suffering.

I simply don't have the architecture specific references handy to know
in which cases the oddities will happen let alone test them.  Plus at
least for ia64 and alpha those architectures don't appear to be
receiving updates for new syscalls, and no new hardware is being built
so I don't know how much longer they will last.

That is building for alpha gives:
>   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

But a real fix like you have shown if you can get it approved by the
alpha architecture maintainers I am more than happy to see, and would
very much prefer.

You certainly noticed that the middle case was SIGFPE when I missed
that.

Unfortunately I don't currently have the competence to judge the
effects of your patch.

Eric

> Helge
>
> Signed-off-by: Helge Deller <deller@gmx.de>
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 65bb102..2ed37dd 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  	      case 1: /* bugcheck */
>  		info.si_signo = SIGTRAP;
>  		info.si_errno = 0;
> -		info.si_code = __SI_FAULT;
> +		info.si_code = TRAP_HWBKPT;
>  		info.si_addr = (void __user *) regs->pc;
>  		info.si_trapno = 0;
>  		send_sig_info(SIGTRAP, &info, current);
> @@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  			break;
>  		case GEN_ROPRAND:
>  			signo = SIGFPE;
> -			code = __SI_FAULT;
> +			code = FPE_FLTSUB;
>  			break;
>  
>  		case GEN_DECOVF:
> @@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  		case GEN_SUBRNG7:
>  		default:
>  			signo = SIGTRAP;
> -			code = __SI_FAULT;
> +			code = TRAP_HWBKPT;
>  			break;
>  		}
>  

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
@ 2017-07-14 10:59         ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-14 10:59 UTC (permalink / raw)
  To: Helge Deller
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, Andy Lutomirski,
	Linus Torvalds, Al Viro, Oleg Nesterov, Andrei Vagin,
	Thomas Gleixner, Greg KH, Andrey Vagin, Serge Hallyn,
	Pavel Emelyanov, Cyrill Gorcunov, Peter Zijlstra, Willy Tarreau,
	linux-arch-u79uwXL29TY76Z2rM5mHXA,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Michael Kerrisk, Richard Henderson, Ivan Kokshaysky, Matt Turner

Helge Deller <deller-Mmb7MZpHnFY@public.gmane.org> writes:

> * Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>:
>> Setting si_code to __SI_FAULT results in a userspace seeing
>> an si_code of 0.  This is the same si_code as SI_USER.  Posix
>> and common sense requires that SI_USER not be a signal specific
>> si_code.  As such this use of 0 for the si_code is a pretty
>> horribly broken ABI.
>> 
>> Given that alpha is on it's last legs I don't know that it is worth
>> fixing this, but it is worth documenting what is going on so that
>> no one decides to copy this bad decision.
>
> The ABI was already broken, so IMHO I think it's better to somehow "fix"
> it instead. Agreed, alpha and some other architectures are already aged,
> but nevertheless most of them build in debian-ports.  Below is a
> suggested fix which reuses/misuses other existing trap codes instead.

The conflict with SI_USER is real.  I don't know that we have any actual
applications that are suffering.

I simply don't have the architecture specific references handy to know
in which cases the oddities will happen let alone test them.  Plus at
least for ia64 and alpha those architectures don't appear to be
receiving updates for new syscalls, and no new hardware is being built
so I don't know how much longer they will last.

That is building for alpha gives:
>   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

But a real fix like you have shown if you can get it approved by the
alpha architecture maintainers I am more than happy to see, and would
very much prefer.

You certainly noticed that the middle case was SIGFPE when I missed
that.

Unfortunately I don't currently have the competence to judge the
effects of your patch.

Eric

> Helge
>
> Signed-off-by: Helge Deller <deller-Mmb7MZpHnFY@public.gmane.org>
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 65bb102..2ed37dd 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -278,7 +278,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  	      case 1: /* bugcheck */
>  		info.si_signo = SIGTRAP;
>  		info.si_errno = 0;
> -		info.si_code = __SI_FAULT;
> +		info.si_code = TRAP_HWBKPT;
>  		info.si_addr = (void __user *) regs->pc;
>  		info.si_trapno = 0;
>  		send_sig_info(SIGTRAP, &info, current);
> @@ -318,7 +318,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  			break;
>  		case GEN_ROPRAND:
>  			signo = SIGFPE;
> -			code = __SI_FAULT;
> +			code = FPE_FLTSUB;
>  			break;
>  
>  		case GEN_DECOVF:
> @@ -340,7 +340,7 @@ do_entIF(unsigned long type, struct pt_regs *regs)
>  		case GEN_SUBRNG7:
>  		default:
>  			signo = SIGTRAP;
> -			code = __SI_FAULT;
> +			code = TRAP_HWBKPT;
>  			break;
>  		}
>  

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
       [not found]         ` <87fudz5lol.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-07-17  8:14           ` Michael Cree
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Cree @ 2017-07-17  8:14 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Andrei Vagin, Greg KH, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Pavel Emelyanov, linux-arch-u79uwXL29TY76Z2rM5mHXA, Helge Deller,
	Michael Kerrisk, Matt Turner, Ivan Kokshaysky, Al Viro,
	Andy Lutomirski, Cyrill Gorcunov, Thomas Gleixner,
	Richard Henderson, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, linux-alpha-u79uwXL29TY76Z2rM5mHXA,
	Linus Torvalds, Willy Tarreau

On Fri, Jul 14, 2017 at 05:59:06AM -0500, Eric W. Biederman wrote:
> in which cases the oddities will happen let alone test them.  Plus at
> least for ia64 and alpha those architectures don't appear to be
> receiving updates for new syscalls, and no new hardware is being built
> so I don't know how much longer they will last.
> 
> That is building for alpha gives:
> >   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> > <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> > <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> > <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> > <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> > <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> > <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> > <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> > <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> > <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> > <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> > <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> > <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

Patches to wire up most of those syscalls on Alpha was posted recently
along with others to fix module loading, etc., but unfortunately they
do not appear to have been applied during the merge window...

Cheers,
Michael.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
  2017-07-14 10:59         ` Eric W. Biederman
@ 2017-07-17  8:14           ` Michael Cree
  -1 siblings, 0 replies; 49+ messages in thread
From: Michael Cree @ 2017-07-17  8:14 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Helge Deller, linux-kernel, Andy Lutomirski, Linus Torvalds,
	Al Viro, Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

On Fri, Jul 14, 2017 at 05:59:06AM -0500, Eric W. Biederman wrote:
> in which cases the oddities will happen let alone test them.  Plus at
> least for ia64 and alpha those architectures don't appear to be
> receiving updates for new syscalls, and no new hardware is being built
> so I don't know how much longer they will last.
> 
> That is building for alpha gives:
> >   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> > <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> > <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> > <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> > <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> > <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> > <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> > <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> > <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> > <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> > <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> > <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> > <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

Patches to wire up most of those syscalls on Alpha was posted recently
along with others to fix module loading, etc., but unfortunately they
do not appear to have been applied during the merge window...

Cheers,
Michael.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
@ 2017-07-17  8:14           ` Michael Cree
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Cree @ 2017-07-17  8:14 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Helge Deller, linux-kernel, Andy Lutomirski, Linus Torvalds,
	Al Viro, Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky

On Fri, Jul 14, 2017 at 05:59:06AM -0500, Eric W. Biederman wrote:
> in which cases the oddities will happen let alone test them.  Plus at
> least for ia64 and alpha those architectures don't appear to be
> receiving updates for new syscalls, and no new hardware is being built
> so I don't know how much longer they will last.
> 
> That is building for alpha gives:
> >   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
> > <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
> > <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
> > <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
> > <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
> > <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
> > <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
> > <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
> > <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
> > <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
> > <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
> > <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
> > <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]

Patches to wire up most of those syscalls on Alpha was posted recently
along with others to fix module loading, etc., but unfortunately they
do not appear to have been applied during the merge window...

Cheers,
Michael.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
  2017-07-17  8:14           ` Michael Cree
@ 2017-07-18 13:37             ` Eric W. Biederman
  -1 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:37 UTC (permalink / raw)
  To: Michael Cree
  Cc: Andrei Vagin, Greg KH, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	Pavel Emelyanov, linux-arch-u79uwXL29TY76Z2rM5mHXA, Helge Deller,
	Michael Kerrisk, Matt Turner, Ivan Kokshaysky, Al Viro,
	Andy Lutomirski, Cyrill Gorcunov, Thomas Gleixner,
	Richard Henderson, Andrey Vagin,
	linux-api-u79uwXL29TY76Z2rM5mHXA, Linux Containers,
	Oleg Nesterov, linux-alpha-u79uwXL29TY76Z2rM5mHXA,
	Linus Torvalds, Willy Tarreau

Michael Cree <mcree-q3Ck4f9/EBK9koe0gwxAeg@public.gmane.org> writes:

> On Fri, Jul 14, 2017 at 05:59:06AM -0500, Eric W. Biederman wrote:
>> in which cases the oddities will happen let alone test them.  Plus at
>> least for ia64 and alpha those architectures don't appear to be
>> receiving updates for new syscalls, and no new hardware is being built
>> so I don't know how much longer they will last.
>> 
>> That is building for alpha gives:
>> >   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
>> > <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
>> > <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
>> > <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
>> > <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
>> > <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
>> > <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
>> > <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
>> > <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
>> > <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
>> > <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
>> > <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
>> > <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]
>
> Patches to wire up most of those syscalls on Alpha was posted recently
> along with others to fix module loading, etc., but unfortunately they
> do not appear to have been applied during the merge window...

Odd.

In general wiring up system calls is something that can even happen in
-rc2 or -rc3 as system calls get added in -rc1 and then the
architectures have a chance to send in the small patches wiring the up.
At least that is how I understand the usual rules for being a non-x86
architecture.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP
@ 2017-07-18 13:37             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:37 UTC (permalink / raw)
  To: Michael Cree
  Cc: Helge Deller, linux-kernel, Andy Lutomirski, Linus Torvalds,
	Al Viro, Oleg Nesterov, Andrei Vagin, Thomas Gleixner, Greg KH,
	Andrey Vagin, Serge Hallyn, Pavel Emelyanov, Cyrill Gorcunov,
	Peter Zijlstra, Willy Tarreau, linux-arch, linux-api,
	Linux Containers, Michael Kerrisk, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

Michael Cree <mcree@orcon.net.nz> writes:

> On Fri, Jul 14, 2017 at 05:59:06AM -0500, Eric W. Biederman wrote:
>> in which cases the oddities will happen let alone test them.  Plus at
>> least for ia64 and alpha those architectures don't appear to be
>> receiving updates for new syscalls, and no new hardware is being built
>> so I don't know how much longer they will last.
>> 
>> That is building for alpha gives:
>> >   CALL    /home/eric/projects/linux/linux-exit-cleanups/scripts/checksyscalls.sh
>> > <stdin>:1239:2: warning: #warning syscall seccomp not implemented [-Wcpp]
>> > <stdin>:1248:2: warning: #warning syscall bpf not implemented [-Wcpp]
>> > <stdin>:1299:2: warning: #warning syscall userfaultfd not implemented [-Wcpp]
>> > <stdin>:1302:2: warning: #warning syscall membarrier not implemented [-Wcpp]
>> > <stdin>:1305:2: warning: #warning syscall mlock2 not implemented [-Wcpp]
>> > <stdin>:1308:2: warning: #warning syscall copy_file_range not implemented [-Wcpp]
>> > <stdin>:1311:2: warning: #warning syscall preadv2 not implemented [-Wcpp]
>> > <stdin>:1314:2: warning: #warning syscall pwritev2 not implemented [-Wcpp]
>> > <stdin>:1317:2: warning: #warning syscall pkey_mprotect not implemented [-Wcpp]
>> > <stdin>:1320:2: warning: #warning syscall pkey_alloc not implemented [-Wcpp]
>> > <stdin>:1323:2: warning: #warning syscall pkey_free not implemented [-Wcpp]
>> > <stdin>:1326:2: warning: #warning syscall statx not implemented [-Wcpp]
>
> Patches to wire up most of those syscalls on Alpha was posted recently
> along with others to fix module loading, etc., but unfortunately they
> do not appear to have been applied during the merge window...

Odd.

In general wiring up system calls is something that can even happen in
-rc2 or -rc3 as system calls get added in -rc1 and then the
architectures have a chance to send in the small patches wiring the up.
At least that is how I understand the usual rules for being a non-x86
architecture.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found]           ` <8737ahwdgr.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2017-07-18 13:43             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:43 UTC (permalink / raw)
  To: David Miller
  Cc: linux-arch-u79uwXL29TY76Z2rM5mHXA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	greg-U8xfFu+wG4EAvxtiuMwx3w,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, oleg-H+wXaHxf7aLQT0dZR+AlfA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	sparclinux-u79uwXL29TY76Z2rM5mHXA,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	luto-DgEjT+Ai2ygdnm+yROfE0A, linux-api-u79uwXL29TY76Z2rM5mHXA,
	gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, tglx-hfZtesqFncYOwBW4kG4KsQ,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b, w,
	avagin-GEFAQzZX7r8dnm+yROfE0A

ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman) writes:

> David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> writes:
>
>> From: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
>> Date: Fri, 30 Jun 2017 07:39:01 -0500
>>
>>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>>> index 2d9b79ccaa50..6bc5c677e92f 100644
>>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>>> @@ -17,6 +17,11 @@
>>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>>  
>>>  /*
>>> + * SIGFPE si_codes
>>> + */
>>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>>> +
>>> +/*
>>>   * SIGEMT si_codes
>>>   */
>>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>>
>> It's one thing to say FIXME in a comment in a kernel local header or
>> C file.
>>
>> It's quite another to put this into the name of a macro which has
>> visibility in the global user compilation namespace.
>>
>> I don't think you should really do that.
>
> Good point.
>
> Sigh.   It almost fits because we did do something off in the uapi
> exported to userspace and we don't have a header file definition for
> that case.
>
> Still.  At this point arch/sparc/include/asm/siginfo.h is
> a better fit for that definition.
>
> I will respin and fix that.

Except arch/<arch>/include/asm/siginfo.h has now been eliminated.
So these definitions have to be
#ifdef __KERNEL__
#define ..._FIXME
#endif

In the uapi but not visible in the headers outside of the kernel.
Which seems appropriate for these values.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found]           ` <8737ahwdgr.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
  2017-07-18 13:43             ` Eric W. Biederman
@ 2017-07-18 13:43             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:43 UTC (permalink / raw)
  To: David Miller
  Cc: linux-kernel, luto, torvalds, viro, oleg, avagin, tglx, greg,
	avagin, serge, xemul, gorcunov, peterz, w, linux-arch, linux-api,
	containers, mtk.manpages, sparclinux

ebiederm@xmission.com (Eric W. Biederman) writes:

> David Miller <davem@davemloft.net> writes:
>
>> From: "Eric W. Biederman" <ebiederm@xmission.com>
>> Date: Fri, 30 Jun 2017 07:39:01 -0500
>>
>>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>>> index 2d9b79ccaa50..6bc5c677e92f 100644
>>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>>> @@ -17,6 +17,11 @@
>>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>>  
>>>  /*
>>> + * SIGFPE si_codes
>>> + */
>>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>>> +
>>> +/*
>>>   * SIGEMT si_codes
>>>   */
>>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>>
>> It's one thing to say FIXME in a comment in a kernel local header or
>> C file.
>>
>> It's quite another to put this into the name of a macro which has
>> visibility in the global user compilation namespace.
>>
>> I don't think you should really do that.
>
> Good point.
>
> Sigh.   It almost fits because we did do something off in the uapi
> exported to userspace and we don't have a header file definition for
> that case.
>
> Still.  At this point arch/sparc/include/asm/siginfo.h is
> a better fit for that definition.
>
> I will respin and fix that.

Except arch/<arch>/include/asm/siginfo.h has now been eliminated.
So these definitions have to be
#ifdef __KERNEL__
#define ..._FIXME
#endif

In the uapi but not visible in the headers outside of the kernel.
Which seems appropriate for these values.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-07-18 13:43             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:43 UTC (permalink / raw)
  To: David Miller
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, luto-DgEjT+Ai2ygdnm+yROfE0A,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	oleg-H+wXaHxf7aLQT0dZR+AlfA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	tglx-hfZtesqFncYOwBW4kG4KsQ, greg-U8xfFu+wG4EAvxtiuMwx3w,
	avagin-GEFAQzZX7r8dnm+yROfE0A, serge-A9i7LUbDfNHQT0dZR+AlfA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	peterz-wEGCiKHe2LqWVfeAwA7xHQ, w,
	linux-arch-u79uwXL29TY76Z2rM5mHXA,
	linux-api-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
	sparclinux-u79uwXL29TY76Z2rM5mHXA

ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman) writes:

> David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> writes:
>
>> From: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
>> Date: Fri, 30 Jun 2017 07:39:01 -0500
>>
>>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>>> index 2d9b79ccaa50..6bc5c677e92f 100644
>>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>>> @@ -17,6 +17,11 @@
>>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>>  
>>>  /*
>>> + * SIGFPE si_codes
>>> + */
>>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>>> +
>>> +/*
>>>   * SIGEMT si_codes
>>>   */
>>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>>
>> It's one thing to say FIXME in a comment in a kernel local header or
>> C file.
>>
>> It's quite another to put this into the name of a macro which has
>> visibility in the global user compilation namespace.
>>
>> I don't think you should really do that.
>
> Good point.
>
> Sigh.   It almost fits because we did do something off in the uapi
> exported to userspace and we don't have a header file definition for
> that case.
>
> Still.  At this point arch/sparc/include/asm/siginfo.h is
> a better fit for that definition.
>
> I will respin and fix that.

Except arch/<arch>/include/asm/siginfo.h has now been eliminated.
So these definitions have to be
#ifdef __KERNEL__
#define ..._FIXME
#endif

In the uapi but not visible in the headers outside of the kernel.
Which seems appropriate for these values.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
@ 2017-07-18 13:43             ` Eric W. Biederman
  0 siblings, 0 replies; 49+ messages in thread
From: Eric W. Biederman @ 2017-07-18 13:43 UTC (permalink / raw)
  To: David Miller
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, luto-DgEjT+Ai2ygdnm+yROfE0A,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	oleg-H+wXaHxf7aLQT0dZR+AlfA, avagin-5HdwGun5lf+gSpxsJD1C4w,
	tglx-hfZtesqFncYOwBW4kG4KsQ, greg-U8xfFu+wG4EAvxtiuMwx3w,
	avagin-GEFAQzZX7r8dnm+yROfE0A, serge-A9i7LUbDfNHQT0dZR+AlfA,
	xemul-5HdwGun5lf+gSpxsJD1C4w, gorcunov-GEFAQzZX7r8dnm+yROfE0A,
	peterz-wEGCiKHe2LqWVfeAwA7xHQ, w,
	linux-arch-u79uwXL29TY76Z2rM5mHXA,
	linux-api-u79uwXL29TY76Z2rM5mHXA,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
	sparclinux-u79uwXL29TY76Z2rM5mHXA

ebiederm@xmission.com (Eric W. Biederman) writes:

> David Miller <davem@davemloft.net> writes:
>
>> From: "Eric W. Biederman" <ebiederm@xmission.com>
>> Date: Fri, 30 Jun 2017 07:39:01 -0500
>>
>>> diff --git a/arch/sparc/include/uapi/asm/siginfo.h b/arch/sparc/include/uapi/asm/siginfo.h
>>> index 2d9b79ccaa50..6bc5c677e92f 100644
>>> --- a/arch/sparc/include/uapi/asm/siginfo.h
>>> +++ b/arch/sparc/include/uapi/asm/siginfo.h
>>> @@ -17,6 +17,11 @@
>>>  #define SI_NOINFO	32767		/* no information in siginfo_t */
>>>  
>>>  /*
>>> + * SIGFPE si_codes
>>> + */
>>> +#define FPE_FIXME	(__SI_FAULT|0)	/* Broken dup of SI_USER */
>>> +
>>> +/*
>>>   * SIGEMT si_codes
>>>   */
>>>  #define EMT_TAGOVF	(__SI_FAULT|1)	/* tag overflow */
>>
>> It's one thing to say FIXME in a comment in a kernel local header or
>> C file.
>>
>> It's quite another to put this into the name of a macro which has
>> visibility in the global user compilation namespace.
>>
>> I don't think you should really do that.
>
> Good point.
>
> Sigh.   It almost fits because we did do something off in the uapi
> exported to userspace and we don't have a header file definition for
> that case.
>
> Still.  At this point arch/sparc/include/asm/siginfo.h is
> a better fit for that definition.
>
> I will respin and fix that.

Except arch/<arch>/include/asm/siginfo.h has now been eliminated.
So these definitions have to be
#ifdef __KERNEL__
#define ..._FIXME
#endif

In the uapi but not visible in the headers outside of the kernel.
Which seems appropriate for these values.

Eric

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2017-07-18 13:51 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 23:57 RFC: bring UP 'lo' by default after creating new netns Mahesh Bandewar (महेश बंडेवार)
2017-06-30  1:08 ` Eric W. Biederman
2017-06-30  6:26   ` Mahesh Bandewar (महेश बंडेवार)
2017-06-30 12:38   ` [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP Eric W. Biederman
2017-06-30 12:38     ` Eric W. Biederman
     [not found]     ` <20170630123906.8865-1-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-07-02 14:13       ` Helge Deller
2017-07-02 14:13     ` Helge Deller
2017-07-02 14:13       ` Helge Deller
     [not found]       ` <20170702141320.GA32254-PwtjyNU/e7vkVFMGpb/cPg@public.gmane.org>
2017-07-14 10:59         ` Eric W. Biederman
2017-07-14 10:59       ` Eric W. Biederman
2017-07-14 10:59         ` Eric W. Biederman
2017-07-17  8:14         ` Michael Cree
2017-07-17  8:14           ` Michael Cree
2017-07-18 13:37           ` Eric W. Biederman
2017-07-18 13:37             ` Eric W. Biederman
     [not found]         ` <87fudz5lol.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-07-17  8:14           ` Michael Cree
2017-06-30 12:39   ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
2017-06-30 12:39     ` Eric W. Biederman
2017-06-30 12:39   ` [PATCH 3/8] signal/sparc: " Eric W. Biederman
2017-06-30 12:39     ` Eric W. Biederman
2017-06-30 16:45     ` David Miller
2017-06-30 16:45       ` David Miller
     [not found]       ` <20170630.124505.736865959393416284.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2017-06-30 18:13         ` Eric W. Biederman
2017-06-30 18:13           ` Eric W. Biederman
2017-06-30 18:13           ` Eric W. Biederman
2017-07-18 13:43           ` Eric W. Biederman
2017-07-18 13:43             ` Eric W. Biederman
2017-07-18 13:43             ` Eric W. Biederman
     [not found]           ` <8737ahwdgr.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-07-18 13:43             ` Eric W. Biederman
     [not found]     ` <20170630123906.8865-3-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-06-30 16:45       ` David Miller
2017-06-30 12:39   ` [PATCH 4/8] signal/mips: " Eric W. Biederman
2017-06-30 12:39     ` Eric W. Biederman
2017-06-30 12:39   ` [PATCH 6/8] signal/x86: Fix SIGSYS handling in copy_siginfo_to_user32 Eric W. Biederman
2017-06-30 12:39     ` Eric W. Biederman
     [not found]   ` <87efu22set.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-06-30 12:38     ` [PATCH 1/8] signal/alpha: Document a conflict with SI_USER for SIGTRAP Eric W. Biederman
2017-06-30 12:39     ` [PATCH 2/8] signal/ia64: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
2017-06-30 12:39     ` [PATCH 3/8] signal/sparc: " Eric W. Biederman
2017-06-30 12:39     ` [PATCH 4/8] signal/mips: " Eric W. Biederman
2017-06-30 12:39     ` [PATCH 5/8] signal/testing: Don't look for __SI_FAULT in userspace Eric W. Biederman
2017-06-30 12:39       ` Eric W. Biederman
2017-06-30 12:39     ` [PATCH 6/8] signal/x86: Fix SIGSYS handling in copy_siginfo_to_user32 Eric W. Biederman
2017-06-30 12:39     ` [PATCH 7/8] fcntl: Don't use ambiguous SIG_POLL si_codes Eric W. Biederman
2017-06-30 12:39       ` Eric W. Biederman
2017-06-30 12:39     ` [PATCH 8/8] signal: Remove kernel interal si_code magic Eric W. Biederman
2017-06-30 12:39       ` Eric W. Biederman
     [not found]       ` <20170630123906.8865-8-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-07-12 22:36         ` Andrei Vagin
2017-07-12 22:36           ` Andrei Vagin
     [not found]           ` <20170712223557.GA21885-1ViLX0X+lBJGNQ1M2rI3KwRV3xvJKrda@public.gmane.org>
2017-07-12 23:08             ` Eric W. Biederman
2017-07-12 23:08           ` Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.