[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1311230573-6244-1-git-send-email-manfred@colorfullife.com>
Date: Thu, 21 Jul 2011 08:42:53 +0200
From: Manfred Spraul <manfred@...orfullife.com>
To: LKML <linux-kernel@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: Manfred Spraul <manfred@...orfullife.com>
Subject: [PATCH] [ipc/sem.c] fix race with concurrent semtimedop() timeouts and IPC_RMID
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@...z.com>
Reported-by: Harald Laabs <kernel@...r.de>
Signed-off-by: Manfred Spraul <manfred@...orfullife.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists