Skip to content

Commit

Permalink
sysvipc: fix the ipc structures initialization
Browse files Browse the repository at this point in the history
A problem was found while reviewing the code after Bugzilla bug
http://bugzilla.kernel.org/show_bug.cgi?id=11796.

In ipc_addid(), the newly allocated ipc structure is inserted into the
ipcs tree (i.e made visible to readers) without locking it.  This is not
correct since its initialization continues after it has been inserted in
the tree.

This patch moves the ipc structure lock initialization + locking before
the actual insertion.

Signed-off-by: Nadia Derbey <[email protected]>
Reported-by: Clement Calmels <[email protected]>
Cc: Manfred Spraul <[email protected]>
Cc: <[email protected]>		[2.6.27.x]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Nadia Derbey authored and torvalds committed Nov 20, 2008
1 parent cf7b9a1 commit e00b4ff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ipc/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,17 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
if (ids->in_use >= size)
return -ENOSPC;

spin_lock_init(&new->lock);
new->deleted = 0;
rcu_read_lock();
spin_lock(&new->lock);

err = idr_get_new(&ids->ipcs_idr, new, &id);
if (err)
if (err) {
spin_unlock(&new->lock);
rcu_read_unlock();
return err;
}

ids->in_use++;

Expand All @@ -280,10 +288,6 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
ids->seq = 0;

new->id = ipc_buildid(id, new->seq);
spin_lock_init(&new->lock);
new->deleted = 0;
rcu_read_lock();
spin_lock(&new->lock);
return id;
}

Expand Down

0 comments on commit e00b4ff

Please sign in to comment.