SPARC and UltraSPARC platform development
 help / color / mirror / Atom feed
* [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found] <87efu22set.fsf@xmission.com>
@ 2017-06-30 12:39 ` Eric W. Biederman
  2017-06-30 16:45   ` David Miller
  0 siblings, 1 reply; 4+ 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] 4+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
  2017-06-30 12:39 ` [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
@ 2017-06-30 16:45   ` David Miller
       [not found]     ` <20170630.124505.736865959393416284.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 4+ 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] 4+ messages in thread

* Re: [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE
       [not found]     ` <20170630.124505.736865959393416284.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2017-06-30 18:13       ` Eric W. Biederman
       [not found]         ` <8737ahwdgr.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 4+ 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] 4+ 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; 4+ 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] 4+ messages in thread

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87efu22set.fsf@xmission.com>
2017-06-30 12:39 ` [PATCH 3/8] signal/sparc: Document a conflict with SI_USER with SIGFPE Eric W. Biederman
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
     [not found]         ` <8737ahwdgr.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2017-07-18 13:43           ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox