mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] [ipc/sem.c] fix race with concurrent semtimedop() timeouts and IPC_RMID
@ 2011-07-21  6:42 Manfred Spraul
  2011-07-21  6:58 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Manfred Spraul @ 2011-07-21  6:42 UTC (permalink / raw)
  To: LKML, Andrew Morton; +Cc: Manfred Spraul

If a semaphore array is removed and in parallel a sleeping task is woken up
(signal or timeout, does not matter), then the woken up task does not wait
until wake_up_sem_queue_do() is completed. This will cause crashes, because
wake_up_sem_queue_do() will read from a stale pointer.

The fix is simple: Regardless of anything, always call get_queue_result().
This function waits until wake_up_sem_queue_do() has finished it's task.

Andrew, could you please take care of merging the patch?

Reported-by: Yuriy Yevtukhov <yuriy@ucoz.com>
Reported-by: Harald Laabs <kernel@dasr.de>
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
---
 ipc/sem.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ipc/sem.c b/ipc/sem.c
index 34193ed..add93d2 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1456,15 +1456,24 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
 	}
 
 	sma = sem_lock(ns, semid);
+
+	/*
+	 * Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing.
+	 */
+	error = get_queue_result(&queue);
+
+	/*
+	 * Array removed? If yes, leave without sem_unlock().
+	 */
 	if (IS_ERR(sma)) {
 		error = -EIDRM;
 		goto out_free;
 	}
 
-	error = get_queue_result(&queue);
 
 	/*
-	 * If queue.status != -EINTR we are woken up by another process
+	 * If queue.status != -EINTR we are woken up by another process.
+	 * Leave without unlink_queue(), but with sem_unlock().
 	 */
 
 	if (error != -EINTR) {
-- 
1.7.6


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

end of thread, other threads:[~2011-07-21  8:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21  6:42 [PATCH] [ipc/sem.c] fix race with concurrent semtimedop() timeouts and IPC_RMID Manfred Spraul
2011-07-21  6:58 ` Andrew Morton
2011-07-21  8:12   ` Eric Dumazet

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

all inboxes | Powered by JetHome®