mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fix copy_sighand() vs do_sigaction() race
@ 2006-02-08 18:08 Oleg Nesterov
       [not found] ` <43EA3611.3F4BC29D@tv-sign.ru>
  0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2006-02-08 18:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton

copy_sighand() should hold ->sighand->siglock while copying
->sighand->action, another thread may be doing sigaction().

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- RC-1/kernel/fork.c~	2006-02-07 01:41:14.000000000 +0300
+++ RC-1/kernel/fork.c	2006-02-08 23:38:56.000000000 +0300
@@ -766,7 +766,9 @@ static inline int copy_sighand(unsigned 
 		return -ENOMEM;
 	spin_lock_init(&sig->siglock);
 	atomic_set(&sig->count, 1);
+	spin_lock_irq(&current->sighand->siglock);
 	memcpy(sig->action, current->sighand->action, sizeof(sig->action));
+	spin_unlock_irq(&current->sighand->siglock);
 	return 0;
 }

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

* [PATCH] sys_signal: initialize ->sa_mask
       [not found]   ` <Pine.LNX.4.64.0602080907460.2458@g5.osdl.org>
@ 2006-02-09 19:41     ` Oleg Nesterov
  2006-02-09 19:41     ` [PATCH] do_sigaction: cleanup ->sa_mask manipulation Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2006-02-09 19:41 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linus Torvalds, linux-kernel, Tony Luck

Pointed out by Linus Torvalds.

sys_signal() forgets to initialize ->sa_mask.

( I suspect arch/ia64/ia32/ia32_signal.c:sys32_signal()
  also needs this fix )

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- RC-1/kernel/signal.c~	2006-02-01 23:38:20.000000000 +0300
+++ RC-1/kernel/signal.c	2006-02-09 23:17:54.000000000 +0300
@@ -2702,6 +2702,7 @@ sys_signal(int sig, __sighandler_t handl
 
 	new_sa.sa.sa_handler = handler;
 	new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK;
+	sigemptyset(&new_sa.sa.sa_mask);
 
 	ret = do_sigaction(sig, &new_sa, &old_sa);

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

* [PATCH] do_sigaction: cleanup ->sa_mask manipulation
       [not found]   ` <Pine.LNX.4.64.0602080907460.2458@g5.osdl.org>
  2006-02-09 19:41     ` [PATCH] sys_signal: initialize ->sa_mask Oleg Nesterov
@ 2006-02-09 19:41     ` Oleg Nesterov
  1 sibling, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2006-02-09 19:41 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linus Torvalds, linux-kernel

Clear unblockable signals beforehand.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- RC-1/include/linux/sched.h~SAKILL	2006-02-07 01:40:51.000000000 +0300
+++ RC-1/include/linux/sched.h	2006-02-10 00:15:19.000000000 +0300
@@ -1097,7 +1097,7 @@ extern struct sigqueue *sigqueue_alloc(v
 extern void sigqueue_free(struct sigqueue *);
 extern int send_sigqueue(int, struct sigqueue *,  struct task_struct *);
 extern int send_group_sigqueue(int, struct sigqueue *,  struct task_struct *);
-extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
+extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
 extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
 
 /* These can be the second arg to send_sig_info/send_group_sig_info.  */
--- RC-1/kernel/signal.c~SAKILL	2006-02-09 23:17:54.000000000 +0300
+++ RC-1/kernel/signal.c	2006-02-10 00:17:43.000000000 +0300
@@ -2430,7 +2430,7 @@ sys_rt_sigqueueinfo(int pid, int sig, si
 }
 
 int
-do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
+do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
 {
 	struct k_sigaction *k;
 	sigset_t mask;
@@ -2454,6 +2454,8 @@ do_sigaction(int sig, const struct k_sig
 		*oact = *k;
 
 	if (act) {
+		sigdelsetmask(&act->sa.sa_mask,
+			      sigmask(SIGKILL) | sigmask(SIGSTOP));
 		/*
 		 * POSIX 3.3.1.3:
 		 *  "Setting a signal action to SIG_IGN for a signal that is
@@ -2479,8 +2481,6 @@ do_sigaction(int sig, const struct k_sig
 			read_lock(&tasklist_lock);
 			spin_lock_irq(&t->sighand->siglock);
 			*k = *act;
-			sigdelsetmask(&k->sa.sa_mask,
-				      sigmask(SIGKILL) | sigmask(SIGSTOP));
 			sigemptyset(&mask);
 			sigaddset(&mask, sig);
 			rm_from_queue_full(&mask, &t->signal->shared_pending);
@@ -2495,8 +2495,6 @@ do_sigaction(int sig, const struct k_sig
 		}
 
 		*k = *act;
-		sigdelsetmask(&k->sa.sa_mask,
-			      sigmask(SIGKILL) | sigmask(SIGSTOP));
 	}
 
 	spin_unlock_irq(&current->sighand->siglock);

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

end of thread, other threads:[~2006-02-09 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 18:08 [PATCH] fix copy_sighand() vs do_sigaction() race Oleg Nesterov
     [not found] ` <43EA3611.3F4BC29D@tv-sign.ru>
     [not found]   ` <Pine.LNX.4.64.0602080907460.2458@g5.osdl.org>
2006-02-09 19:41     ` [PATCH] sys_signal: initialize ->sa_mask Oleg Nesterov
2006-02-09 19:41     ` [PATCH] do_sigaction: cleanup ->sa_mask manipulation Oleg Nesterov

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

Powered by JetHome