mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
ipc: move locking out of ipcctl_pre_down_nolock
This function currently acquires both the rw_mutex and the rcu lock on successful lookups, leaving the callers to explicitly unlock them, creating another two level locking situation. Make the callers (including those that still use ipcctl_pre_down()) explicitly lock and unlock the rwsem and rcu lock. Signed-off-by: Davidlohr Bueso <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Rik van Riel <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
cf9d5d78d0
commit
7b4cc5d841
4 changed files with 56 additions and 39 deletions
23
ipc/shm.c
23
ipc/shm.c
|
|
@ -757,31 +757,42 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd,
|
|||
return -EFAULT;
|
||||
}
|
||||
|
||||
down_write(&shm_ids(ns).rw_mutex);
|
||||
rcu_read_lock();
|
||||
|
||||
ipcp = ipcctl_pre_down(ns, &shm_ids(ns), shmid, cmd,
|
||||
&shmid64.shm_perm, 0);
|
||||
if (IS_ERR(ipcp))
|
||||
return PTR_ERR(ipcp);
|
||||
if (IS_ERR(ipcp)) {
|
||||
err = PTR_ERR(ipcp);
|
||||
/* the ipc lock is not held upon failure */
|
||||
goto out_unlock1;
|
||||
}
|
||||
|
||||
shp = container_of(ipcp, struct shmid_kernel, shm_perm);
|
||||
|
||||
err = security_shm_shmctl(shp, cmd);
|
||||
if (err)
|
||||
goto out_unlock;
|
||||
goto out_unlock0;
|
||||
|
||||
switch (cmd) {
|
||||
case IPC_RMID:
|
||||
/* do_shm_rmid unlocks the ipc object and rcu */
|
||||
do_shm_rmid(ns, ipcp);
|
||||
goto out_up;
|
||||
case IPC_SET:
|
||||
err = ipc_update_perm(&shmid64.shm_perm, ipcp);
|
||||
if (err)
|
||||
goto out_unlock;
|
||||
goto out_unlock0;
|
||||
shp->shm_ctim = get_seconds();
|
||||
break;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
}
|
||||
out_unlock:
|
||||
shm_unlock(shp);
|
||||
|
||||
out_unlock0:
|
||||
ipc_unlock_object(&shp->shm_perm);
|
||||
out_unlock1:
|
||||
rcu_read_unlock();
|
||||
out_up:
|
||||
up_write(&shm_ids(ns).rw_mutex);
|
||||
return err;
|
||||
|
|
|
|||
Loading…
Reference in a new issue