diff options
author | Manfred Spraul <manfred@colorfullife.com> | 2011-07-25 20:11:47 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-08-05 00:58:41 -0400 |
commit | e73ff29041b5f8991ef81669a1a9f0553d14766a (patch) | |
tree | 87b0a35ac9488b06d7bcad27125f723e08298703 | |
parent | 9f78aa15dc4b47ca0bc6269c7c0e4f2345a66580 (diff) |
ipc/sem.c: fix race with concurrent semtimedop() timeouts and IPC_RMID
commit d694ad62bf539dbb20a0899ac2a954555f9e4a83 upstream.
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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | ipc/sem.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1456,15 +1456,24 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, | |||
1456 | } | 1456 | } |
1457 | 1457 | ||
1458 | sma = sem_lock(ns, semid); | 1458 | sma = sem_lock(ns, semid); |
1459 | |||
1460 | /* | ||
1461 | * Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing. | ||
1462 | */ | ||
1463 | error = get_queue_result(&queue); | ||
1464 | |||
1465 | /* | ||
1466 | * Array removed? If yes, leave without sem_unlock(). | ||
1467 | */ | ||
1459 | if (IS_ERR(sma)) { | 1468 | if (IS_ERR(sma)) { |
1460 | error = -EIDRM; | 1469 | error = -EIDRM; |
1461 | goto out_free; | 1470 | goto out_free; |
1462 | } | 1471 | } |
1463 | 1472 | ||
1464 | error = get_queue_result(&queue); | ||
1465 | 1473 | ||
1466 | /* | 1474 | /* |
1467 | * If queue.status != -EINTR we are woken up by another process | 1475 | * If queue.status != -EINTR we are woken up by another process. |
1476 | * Leave without unlink_queue(), but with sem_unlock(). | ||
1468 | */ | 1477 | */ |
1469 | 1478 | ||
1470 | if (error != -EINTR) { | 1479 | if (error != -EINTR) { |