After the locking semantics for the SysV IPC API got improved, a couple ofa) sysv ipc is lockless whereever possible, without writing to any shared cachelines.
IPC_RMID race windows were opened because we ended up dropping the
'kern_ipc_perm.deleted' check performed way down in ipc_lock().
The spotted races got sorted out by re-introducing the old test within
the racy critical sections.
This patch introduces ipc_valid_object() to consolidate the way we cope with
IPC_RMID races by using the same abstraction across the API implementation.
Signed-off-by: Rafael Aquini <aquini@xxxxxxxxxx>
Acked-by: Rik van Riel <riel@xxxxxxxxxx>
Acked-by: Greg Thelen <gthelen@xxxxxxxxxx>
---
Changelog:
* v2:
- drop assert_spin_locked() from ipc_valid_object() for less overhead
@@ -1846,7 +1846,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,simple semtimedop() operation do not acquire sem_perm.lock, they only acquire the per-semaphore lock and check that sem_perm.lock is not held. This is sufficient to prevent races with RMID.
error = -EIDRM;
locknum = sem_lock(sma, sops, nsops);
- if (sma->sem_perm.deleted)
+ if (!ipc_valid_object(&sma->sem_perm))
goto out_unlock_free;
@@ -1116,7 +1116,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,Please mention the change from "shm_file == NULL" to perm.deleted in the changelog.
ipc_lock_object(&shp->shm_perm);
/* check if shm_destroy() is tearing down shp */
- if (shp->shm_file == NULL) {
+ if (!ipc_valid_object(&shp->shm_perm)) {
ipc_unlock_object(&shp->shm_perm);
err = -EIDRM;
goto out_unlock;