]> git.karo-electronics.de Git - karo-tx-linux.git/commit
ipc/sem.c: fix return code race with semop vs. semop +semctl(IPC_RMID)
authorManfred Spraul <manfred@colorfullife.com>
Mon, 24 Oct 2011 15:00:05 +0000 (02:00 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 1 Nov 2011 08:41:44 +0000 (19:41 +1100)
commit19cc51e1c49d2af0b8990328becbb6eb1ae5a7f3
tree79b71e64faa94d64b8a739dc28ea4f2524c78cf9
parent3cf7acc42ad2a3af101bde123f1bb8b64cc1d041
ipc/sem.c: fix return code race with semop vs. semop +semctl(IPC_RMID)

sys_semtimedop() may return -EIDRM although the semaphore operation
completed successfully:

thread 1: thread 2:
semtimedop(), sleeps
semop():
* acquires sem_lock()
semtimedop() woken up due to timeout
sem_lock() loops
* notices that thread 2 could be completed.
* performs the operations that thread 2 is sleeping on.
* marks the semaphore operation as IN_WAKEUP
* drops sem_lock(), does wakeup, sets return code to 0
* thread delayed due to interrupt, whatever
* returns to user space
* thread still delayed
semctl(IPC_RMID)
* acquires sem_lock()
* ipc_rmid(), ipcp->deleted=1
* drops sem_lock()
* thread finally continues - but seem_lock()
  now fails due to ipcp->deleted == 1
* returns -EIDRM instead of 0

The fix is trivial: Always use the return code in queue.status.

In real world, the race probably doesn't matter:
If the semaphore array is destroyed, the app is probably not interested
if the last operation succeeded or was already cancelled.

Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Mike Galbraith <efault@gmx.de>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
ipc/sem.c