diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-09-30 19:48:40 +0300 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2015-10-13 05:46:12 +0300 |
commit | 2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89 (patch) | |
tree | 8a5b7f4e97d14301cd67fb10894a8954f75fb9c5 /ipc/shm.c | |
parent | 0bdf1e820160cdeb16cba1c5ea6892ae982a6587 (diff) | |
download | linux-2ef259c0f5b2f3ca28ccb7bf126a0a2177012f89.tar.xz |
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/shm.c')
-rw-r--r-- | ipc/shm.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/ipc/shm.c b/ipc/shm.c index 326a20bdba3a..16b1f9ec0398 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -498,12 +498,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) if (IS_ERR(file)) goto no_file; - id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); - if (id < 0) { - error = id; - goto no_id; - } - shp->shm_cprid = task_tgid_vnr(current); shp->shm_lprid = 0; shp->shm_atim = shp->shm_dtim = 0; @@ -512,6 +506,13 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) shp->shm_nattch = 0; shp->shm_file = file; shp->shm_creator = current; + + id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); + if (id < 0) { + error = id; + goto no_id; + } + /* * shmid gets reported as "inode#" in /proc/pid/maps. * proc-ps tools use this. Changing this will break them. |