diff options
author | Pierre Peiffer <pierre.peiffer@bull.net> | 2008-04-29 04:00:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-29 11:06:14 -0400 |
commit | a5f75e7f256f75759ec3d6dbef0ba932f1b397d2 (patch) | |
tree | 89b2ed22547a9fca11f87eb6cba68bb84fcf1b8a /ipc/shm.c | |
parent | 8f4a3809c18ff3107bdbb1fabe3f4e5d2a928321 (diff) |
IPC: consolidate all xxxctl_down() functions
semctl_down(), msgctl_down() and shmctl_down() are used to handle the same set
of commands for each kind of IPC. They all start to do the same job (they
retrieve the ipc and do some permission checks) before handling the commands
on their own.
This patch proposes to consolidate this by moving these same pieces of code
into one common function called ipcctl_pre_down().
It simplifies a little these xxxctl_down() functions and increases a little
the maintainability.
Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Cc: Nadia Derbey <Nadia.Derbey@bull.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/shm.c')
-rw-r--r-- | ipc/shm.c | 42 |
1 files changed, 4 insertions, 38 deletions
@@ -126,18 +126,6 @@ static inline struct shmid_kernel *shm_lock_down(struct ipc_namespace *ns, | |||
126 | return container_of(ipcp, struct shmid_kernel, shm_perm); | 126 | return container_of(ipcp, struct shmid_kernel, shm_perm); |
127 | } | 127 | } |
128 | 128 | ||
129 | static inline struct shmid_kernel *shm_lock_check_down( | ||
130 | struct ipc_namespace *ns, | ||
131 | int id) | ||
132 | { | ||
133 | struct kern_ipc_perm *ipcp = ipc_lock_check_down(&shm_ids(ns), id); | ||
134 | |||
135 | if (IS_ERR(ipcp)) | ||
136 | return (struct shmid_kernel *)ipcp; | ||
137 | |||
138 | return container_of(ipcp, struct shmid_kernel, shm_perm); | ||
139 | } | ||
140 | |||
141 | /* | 129 | /* |
142 | * shm_lock_(check_) routines are called in the paths where the rw_mutex | 130 | * shm_lock_(check_) routines are called in the paths where the rw_mutex |
143 | * is not held. | 131 | * is not held. |
@@ -620,33 +608,11 @@ static int shmctl_down(struct ipc_namespace *ns, int shmid, int cmd, | |||
620 | return -EFAULT; | 608 | return -EFAULT; |
621 | } | 609 | } |
622 | 610 | ||
623 | down_write(&shm_ids(ns).rw_mutex); | 611 | ipcp = ipcctl_pre_down(&shm_ids(ns), shmid, cmd, &shmid64.shm_perm, 0); |
624 | shp = shm_lock_check_down(ns, shmid); | 612 | if (IS_ERR(ipcp)) |
625 | if (IS_ERR(shp)) { | 613 | return PTR_ERR(ipcp); |
626 | err = PTR_ERR(shp); | ||
627 | goto out_up; | ||
628 | } | ||
629 | |||
630 | ipcp = &shp->shm_perm; | ||
631 | |||
632 | err = audit_ipc_obj(ipcp); | ||
633 | if (err) | ||
634 | goto out_unlock; | ||
635 | |||
636 | if (cmd == IPC_SET) { | ||
637 | err = audit_ipc_set_perm(0, shmid64.shm_perm.uid, | ||
638 | shmid64.shm_perm.gid, | ||
639 | shmid64.shm_perm.mode); | ||
640 | if (err) | ||
641 | goto out_unlock; | ||
642 | } | ||
643 | 614 | ||
644 | if (current->euid != ipcp->uid && | 615 | shp = container_of(ipcp, struct shmid_kernel, shm_perm); |
645 | current->euid != ipcp->cuid && | ||
646 | !capable(CAP_SYS_ADMIN)) { | ||
647 | err = -EPERM; | ||
648 | goto out_unlock; | ||
649 | } | ||
650 | 616 | ||
651 | err = security_shm_shmctl(shp, cmd); | 617 | err = security_shm_shmctl(shp, cmd); |
652 | if (err) | 618 | if (err) |