aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/util.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-09-30 12:48:40 -0400
committerBen Hutchings <ben@decadent.org.uk>2015-10-13 03:46:12 +0100
commit2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89 (patch)
tree8a5b7f4e97d14301cd67fb10894a8954f75fb9c5 /ipc/util.c
parent0bdf1e820160cdeb16cba1c5ea6892ae982a6587 (diff)
downloadkernel_samsung_smdk4412-2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89.zip
kernel_samsung_smdk4412-2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89.tar.gz
kernel_samsung_smdk4412-2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89.tar.bz2
Initialize msg/shm IPC objects before doing ipc_addid()
commit b9a532277938798b53178d5a66af6e2915cb27cf upstream. As reported by Dmitry Vyukov, we really shouldn't do ipc_addid() before having initialized the IPC object state. Yes, we initialize the IPC object in a locked state, but with all the lockless RCU lookup work, that IPC object lock no longer means that the state cannot be seen. We already did this for the IPC semaphore code (see commit e8577d1f0329: "ipc/sem.c: fully initialize sem_array before making it visible") but we clearly forgot about msg and shm. Reported-by: Dmitry Vyukov <dvyukov@google.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: stable@vger.kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> [bwh: Backported to 3.2: - Adjust context - The error path being moved looks a little different] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'ipc/util.c')
-rw-r--r--ipc/util.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ipc/util.c b/ipc/util.c
index 75261a3..e4c9377 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -264,6 +264,10 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
rcu_read_lock();
spin_lock(&new->lock);
+ current_euid_egid(&euid, &egid);
+ new->cuid = new->uid = euid;
+ new->gid = new->cgid = egid;
+
err = idr_get_new(&ids->ipcs_idr, new, &id);
if (err) {
spin_unlock(&new->lock);
@@ -273,10 +277,6 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
ids->in_use++;
- current_euid_egid(&euid, &egid);
- new->cuid = new->uid = euid;
- new->gid = new->cgid = egid;
-
new->seq = ids->seq++;
if(ids->seq > ids->seq_max)
ids->seq = 0;