kernel-hacking-2024-linux-s.../ipc
Manfred Spraul 3c24783bb2 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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-11-02 16:07:01 -07:00
..
compat.c
compat_mq.c
ipc_sysctl.c ipc: introduce shm_rmid_forced sysctl 2011-07-26 16:49:44 -07:00
ipcns_notifier.c
Makefile
mq_sysctl.c
mqueue.c ipc/mqueue.c: fix wrong use of schedule_hrtimeout_range_clock() 2011-10-31 17:30:44 -07:00
msg.c Fix common misspellings 2011-03-31 11:26:23 -03:00
msgutil.c userns: add a user namespace owner of ipc ns 2011-03-23 19:47:07 -07:00
namespace.c ns proc: Add support for the ipc namespace 2011-05-10 14:35:47 -07:00
sem.c ipc/sem.c: fix return code race with semop vs. semop +semctl(IPC_RMID) 2011-11-02 16:07:01 -07:00
shm.c Do 'shm_init_ns()' in an early pure_initcall 2011-08-04 19:35:59 -10:00
syscall.c
util.c ipc,rcu: Convert call_rcu(ipc_immediate_free) to kfree_rcu() 2011-07-20 14:10:16 -07:00
util.h userns: user namespaces: convert several capable() calls 2011-03-23 19:47:08 -07:00