[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-kernel
Subject:    [PATCH] Fix queued SIGIO
From:       Andi Kleen <ak () muc ! de>
Date:       2000-09-18 7:41:13
[Download RAW message or body]

Hallo Linus,

The siginfo signal sending uses SI_FROMUSER to see if it should look
at current to check if the sending process is allowed to send the
signal. Unfortunately SI_FROMUSER() is true for SI_SIGIO signals generated
by the network stack for queued SIGIO. This leads to the SIGIO behaviour
vary based on the process that runs by chance while the network softirq
is active (between queued SIGIO and fallback SIGIO -- fallback SIGIO
doesn't have that bug).

[this problem is not on Ted's list yet, but it would clearly belong there
because it makes the queued SIGIO interface near unusable]

The problem is really that SI_SIGIO is negative, but it should be positive
to make SI_FROMUSER return false on it. 

Changing it would unfortunately break binary compatibility. This patch
instead changes the definition of SI_FROMUSER/KERNEL to check explicitely
for SI_SIGIO and make it appear like a kernel generated signal type. This
prevents send_sig_info from looking at current .

It'll break programs that try to send SI_SIGIO (=-5) signals from userspace,
but I think that is ok.

Patch against 2.4.0test9pre1

-Andi


--- include/asm-alpha/siginfo.h-SIG	Mon Sep 11 16:06:54 2000
+++ include/asm-alpha/siginfo.h	Sun Sep 17 20:00:27 2000
@@ -108,8 +108,9 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-arm/siginfo.h-SIG	Mon Sep 11 16:06:55 2000
+++ include/asm-arm/siginfo.h	Sun Sep 17 20:00:39 2000
@@ -108,8 +108,8 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-i386/siginfo.h-SIG	Wed Sep 13 23:30:51 2000
+++ include/asm-i386/siginfo.h	Sun Sep 17 19:59:20 2000
@@ -108,8 +108,8 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-ia64/siginfo.h-SIG	Mon Sep 11 16:06:56 2000
+++ include/asm-ia64/siginfo.h	Sun Sep 17 20:00:59 2000
@@ -117,8 +117,8 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-m68k/siginfo.h-SIG	Mon Sep 11 16:06:57 2000
+++ include/asm-m68k/siginfo.h	Sun Sep 17 20:01:16 2000
@@ -108,8 +108,8 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-mips/siginfo.h-SIG	Mon Sep 11 16:06:59 2000
+++ include/asm-mips/siginfo.h	Sun Sep 17 20:01:39 2000
@@ -128,8 +128,9 @@
 #define SI_MESGQ	-4	/* sent by real time mesq state change */
 #define SI_SIGIO	-5	/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-mips64/siginfo.h-SIG	Mon Sep 11 16:07:02 2000
+++ include/asm-mips64/siginfo.h	Sun Sep 17 20:01:55 2000
@@ -128,8 +128,9 @@
 #define SI_MESGQ	-4	/* sent by real time mesq state change */
 #define SI_SIGIO	-5	/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-ppc/siginfo.h-SIG	Mon Sep 11 16:07:03 2000
+++ include/asm-ppc/siginfo.h	Sun Sep 17 20:02:18 2000
@@ -108,8 +108,9 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-s390/siginfo.h-SIG	Mon Sep 11 16:07:05 2000
+++ include/asm-s390/siginfo.h	Sun Sep 17 20:02:34 2000
@@ -97,8 +97,9 @@
 #define SI_ASYNCIO	-4	/* sent by AIO completion */
 #define SI_SIGIO	-5	/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-sh/siginfo.h-SIG	Mon Sep 11 16:07:07 2000
+++ include/asm-sh/siginfo.h	Sun Sep 17 20:02:48 2000
@@ -108,8 +108,9 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-sparc/siginfo.h-SIG	Mon Sep 11 16:07:08 2000
+++ include/asm-sparc/siginfo.h	Sun Sep 17 20:03:02 2000
@@ -113,8 +113,9 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- include/asm-sparc64/siginfo.h-SIG	Mon Sep 11 16:07:09 2000
+++ include/asm-sparc64/siginfo.h	Sun Sep 17 20:03:24 2000
@@ -173,8 +173,8 @@
 #define SI_ASYNCIO	-4		/* sent by AIO completion */
 #define SI_SIGIO	-5		/* sent by queued SIGIO */
 
-#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0)
-#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0)
+#define SI_FROMUSER(siptr)	((siptr)->si_code <= 0 && (siptr)->si_code != SI_SIGIO)
+#define SI_FROMKERNEL(siptr)	((siptr)->si_code > 0 || (siptr)->si_code == SI_SIGIO)
 
 /*
  * SIGILL si_codes
--- kernel/signal.c-SIG	Sat Sep 16 22:30:24 2000
+++ kernel/signal.c	Mon Sep 18 03:15:06 2000
@@ -1000,7 +1000,7 @@
 
 	/* Not even root can pretend to send signals from the kernel.
 	   Nor can they impersonate a kill(), which adds source info.  */
-	if (info.si_code >= 0)
+	if (!SI_FROMUSER(&info))
 		return -EPERM;
 	info.si_signo = sig;
 


-- 
This is like TV. I don't like TV.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic