|author||Rafael Aquini <firstname.lastname@example.org>||2014-01-27 17:07:01 -0800|
|committer||Linus Torvalds <email@example.com>||2014-01-27 21:02:39 -0800|
|parent||ipc/sem.c: avoid overflow of semop undo (semadj) value (diff)|
ipc: introduce ipc_valid_object() helper to sort out IPC_RMID races
After the locking semantics for the SysV IPC API got improved, a couple of 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 <firstname.lastname@example.org> Acked-by: Rik van Riel <email@example.com> Acked-by: Greg Thelen <firstname.lastname@example.org> Reviewed-by: Davidlohr Bueso <email@example.com> Cc: Manfred Spraul <firstname.lastname@example.org> Signed-off-by: Andrew Morton <email@example.com> Signed-off-by: Linus Torvalds <firstname.lastname@example.org>
Diffstat (limited to 'ipc/util.h')
1 files changed, 13 insertions, 0 deletions
diff --git a/ipc/util.h b/ipc/util.h
index 59d78aa94987..d05b7085a887 100644
@@ -185,6 +185,19 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)
+ * ipc_valid_object() - helper to sort out IPC_RMID races for codepaths
+ * where the respective ipc_ids.rwsem is not being held down.
+ * Checks whether the ipc object is still around or if it's gone already, as
+ * ipc_rmid() may have already freed the ID while the ipc lock was spinning.
+ * Needs to be called with kern_ipc_perm.lock held -- exception made for one
+ * checkpoint case at sys_semtimedop() as noted in code commentary.
+static inline bool ipc_valid_object(struct kern_ipc_perm *perm)
+ return perm->deleted == 0;
struct kern_ipc_perm *ipc_obtain_object_check(struct ipc_ids *ids, int id);
int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
struct ipc_ops *ops, struct ipc_params *params);