aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/sem.c
diff options
context:
space:
mode:
authorManfred Spraul <manfred@colorfullife.com>2011-07-25 20:11:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:57:07 -0400
commitd694ad62bf539dbb20a0899ac2a954555f9e4a83 (patch)
treefd3ddc3269b6ad40a448046e60560fec30fbb0c5 /ipc/sem.c
parent8405b044e5238afebd7248d927c1d261d2239767 (diff)
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. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=27142 Reported-by: Yuriy Yevtukhov <yuriy@ucoz.com> Reported-by: Harald Laabs <kernel@dasr.de> Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Acked-by: Eric Dumazet <eric.dumazet@gmail.com> Cc: <stable@kernel.org> [2.6.35+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/sem.c')
-rw-r--r--ipc/sem.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ipc/sem.c b/ipc/sem.c
index 8b929e6a6eda..c8e00f8b4be1 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1450,15 +1450,24 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
1450 } 1450 }
1451 1451
1452 sma = sem_lock(ns, semid); 1452 sma = sem_lock(ns, semid);
1453
1454 /*
1455 * Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing.
1456 */
1457 error = get_queue_result(&queue);
1458
1459 /*
1460 * Array removed? If yes, leave without sem_unlock().
1461 */
1453 if (IS_ERR(sma)) { 1462 if (IS_ERR(sma)) {
1454 error = -EIDRM; 1463 error = -EIDRM;
1455 goto out_free; 1464 goto out_free;
1456 } 1465 }
1457 1466
1458 error = get_queue_result(&queue);
1459 1467
1460 /* 1468 /*
1461 * If queue.status != -EINTR we are woken up by another process 1469 * If queue.status != -EINTR we are woken up by another process.
1470 * Leave without unlink_queue(), but with sem_unlock().
1462 */ 1471 */
1463 1472
1464 if (error != -EINTR) { 1473 if (error != -EINTR) {