Skip to content

Commit

Permalink
ipc/sem.c: fix race with concurrent semtimedop() timeouts and IPC_RMID
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: Harald Laabs <[email protected]>
Signed-off-by: Manfred Spraul <[email protected]>
Acked-by: Eric Dumazet <[email protected]>
Cc: <[email protected]>		[2.6.35+]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
manfred-colorfu authored and torvalds committed Jul 26, 2011
1 parent 8405b04 commit d694ad6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,15 +1450,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) {
Expand Down

0 comments on commit d694ad6

Please sign in to comment.