The patch titled ipc/sem.c: fix race with concurrent semtimedop() timeouts and IPC_RMID has been added to the -mm tree. Its filename is ipc-semc-fix-race-with-concurrent-semtimedop-timeouts-and-ipc_rmid.patch
Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find out what to do about this The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/ ------------------------------------------------------ Subject: ipc/sem.c: fix race with concurrent semtimedop() timeouts and IPC_RMID From: Manfred Spraul <manf...@colorfullife.com> 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 <yu...@ucoz.com> Reported-by: Harald Laabs <ker...@dasr.de> Signed-off-by: Manfred Spraul <manf...@colorfullife.com> Cc: <sta...@kernel.org> Signed-off-by: Andrew Morton <a...@linux-foundation.org> --- ipc/sem.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff -puN ipc/sem.c~ipc-semc-fix-race-with-concurrent-semtimedop-timeouts-and-ipc_rmid ipc/sem.c --- a/ipc/sem.c~ipc-semc-fix-race-with-concurrent-semtimedop-timeouts-and-ipc_rmid +++ a/ipc/sem.c @@ -1456,15 +1456,24 @@ SYSCALL_DEFINE4(semtimedop, int, semid, } 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) { _ Patches currently in -mm which might be from manf...@colorfullife.com are ipc-semc-fix-race-with-concurrent-semtimedop-timeouts-and-ipc_rmid.patch ipc-mqueue-refactor-failure-handling.patch ipc-mqueue-fix-mq_open-return-value.patch slab-leaks3-default-y.patch _______________________________________________ stable mailing list stable@linux.kernel.org http://linux.kernel.org/mailman/listinfo/stable