Skip to content

Commit 19dfd03

Browse files
Davidlohr Buesogregkh
authored andcommitted
ipc,shm: shorten critical region for shmat
commit c2c737a upstream. Similar to other system calls, acquire the kern_ipc_perm lock after doing the initial permission and security checks. [sasha.levin@oracle.com: dont leave do_shmat with rcu lock held] Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com> Tested-by: Sedat Dilek <sedat.dilek@gmail.com> Cc: Rik van Riel <riel@redhat.com> Cc: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dbb563e commit 19dfd03

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎ipc/shm.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* namespaces support
2020
* OpenVZ, SWsoft Inc.
2121
* Pavel Emelianov <xemul@openvz.org>
22+
*
23+
* Better ipc lock (kern_ipc_perm.lock) handling
24+
* Davidlohr Bueso <davidlohr.bueso@hp.com>, June 2013.
2225
*/
2326

2427
#include <linux/slab.h>
@@ -1093,10 +1096,11 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
10931096
* additional creator id...
10941097
*/
10951098
ns = current->nsproxy->ipc_ns;
1096-
shp = shm_lock_check(ns, shmid);
1099+
rcu_read_lock();
1100+
shp = shm_obtain_object_check(ns, shmid);
10971101
if (IS_ERR(shp)) {
10981102
err = PTR_ERR(shp);
1099-
goto out;
1103+
goto out_unlock;
11001104
}
11011105

11021106
err = -EACCES;
@@ -1107,11 +1111,13 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
11071111
if (err)
11081112
goto out_unlock;
11091113

1114+
ipc_lock_object(&shp->shm_perm);
11101115
path = shp->shm_file->f_path;
11111116
path_get(&path);
11121117
shp->shm_nattch++;
11131118
size = i_size_read(path.dentry->d_inode);
1114-
shm_unlock(shp);
1119+
ipc_unlock_object(&shp->shm_perm);
1120+
rcu_read_unlock();
11151121

11161122
err = -ENOMEM;
11171123
sfd = kzalloc(sizeof(*sfd), GFP_KERNEL);
@@ -1182,7 +1188,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
11821188
return err;
11831189

11841190
out_unlock:
1185-
shm_unlock(shp);
1191+
rcu_read_unlock();
11861192
out:
11871193
return err;
11881194
}

0 commit comments

Comments
 (0)