aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/ipc_namespace.h5
-rw-r--r--ipc/msg.c28
-rw-r--r--ipc/namespace.c30
-rw-r--r--ipc/sem.c27
-rw-r--r--ipc/shm.c27
5 files changed, 50 insertions, 67 deletions
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
index 6db5522eef51..e4451d1da753 100644
--- a/include/linux/ipc_namespace.h
+++ b/include/linux/ipc_namespace.h
@@ -43,7 +43,10 @@ extern struct ipc_namespace init_ipc_ns;
43#if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS) 43#if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
44extern void free_ipc_ns(struct kref *kref); 44extern void free_ipc_ns(struct kref *kref);
45extern struct ipc_namespace *copy_ipcs(unsigned long flags, 45extern struct ipc_namespace *copy_ipcs(unsigned long flags,
46 struct ipc_namespace *ns); 46 struct ipc_namespace *ns);
47extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
48 void (*free)(struct ipc_namespace *,
49 struct kern_ipc_perm *));
47 50
48static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns) 51static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
49{ 52{
diff --git a/ipc/msg.c b/ipc/msg.c
index ab0c38b29533..46585a05473e 100644
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -72,7 +72,7 @@ struct msg_sender {
72#define msg_unlock(msq) ipc_unlock(&(msq)->q_perm) 72#define msg_unlock(msq) ipc_unlock(&(msq)->q_perm)
73#define msg_buildid(id, seq) ipc_buildid(id, seq) 73#define msg_buildid(id, seq) ipc_buildid(id, seq)
74 74
75static void freeque(struct ipc_namespace *, struct msg_queue *); 75static void freeque(struct ipc_namespace *, struct kern_ipc_perm *);
76static int newque(struct ipc_namespace *, struct ipc_params *); 76static int newque(struct ipc_namespace *, struct ipc_params *);
77#ifdef CONFIG_PROC_FS 77#ifdef CONFIG_PROC_FS
78static int sysvipc_msg_proc_show(struct seq_file *s, void *it); 78static int sysvipc_msg_proc_show(struct seq_file *s, void *it);
@@ -91,26 +91,7 @@ void msg_init_ns(struct ipc_namespace *ns)
91#ifdef CONFIG_IPC_NS 91#ifdef CONFIG_IPC_NS
92void msg_exit_ns(struct ipc_namespace *ns) 92void msg_exit_ns(struct ipc_namespace *ns)
93{ 93{
94 struct msg_queue *msq; 94 free_ipcs(ns, &msg_ids(ns), freeque);
95 struct kern_ipc_perm *perm;
96 int next_id;
97 int total, in_use;
98
99 down_write(&msg_ids(ns).rw_mutex);
100
101 in_use = msg_ids(ns).in_use;
102
103 for (total = 0, next_id = 0; total < in_use; next_id++) {
104 perm = idr_find(&msg_ids(ns).ipcs_idr, next_id);
105 if (perm == NULL)
106 continue;
107 ipc_lock_by_ptr(perm);
108 msq = container_of(perm, struct msg_queue, q_perm);
109 freeque(ns, msq);
110 total++;
111 }
112
113 up_write(&msg_ids(ns).rw_mutex);
114} 95}
115#endif 96#endif
116 97
@@ -274,9 +255,10 @@ static void expunge_all(struct msg_queue *msq, int res)
274 * msg_ids.rw_mutex (writer) and the spinlock for this message queue are held 255 * msg_ids.rw_mutex (writer) and the spinlock for this message queue are held
275 * before freeque() is called. msg_ids.rw_mutex remains locked on exit. 256 * before freeque() is called. msg_ids.rw_mutex remains locked on exit.
276 */ 257 */
277static void freeque(struct ipc_namespace *ns, struct msg_queue *msq) 258static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
278{ 259{
279 struct list_head *tmp; 260 struct list_head *tmp;
261 struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm);
280 262
281 expunge_all(msq, -EIDRM); 263 expunge_all(msq, -EIDRM);
282 ss_wakeup(&msq->q_senders, 1); 264 ss_wakeup(&msq->q_senders, 1);
@@ -582,7 +564,7 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)
582 break; 564 break;
583 } 565 }
584 case IPC_RMID: 566 case IPC_RMID:
585 freeque(ns, msq); 567 freeque(ns, &msq->q_perm);
586 break; 568 break;
587 } 569 }
588 err = 0; 570 err = 0;
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 1fed8922d475..1b967655eb35 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -44,6 +44,36 @@ struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
44 return new_ns; 44 return new_ns;
45} 45}
46 46
47/*
48 * free_ipcs - free all ipcs of one type
49 * @ns: the namespace to remove the ipcs from
50 * @ids: the table of ipcs to free
51 * @free: the function called to free each individual ipc
52 *
53 * Called for each kind of ipc when an ipc_namespace exits.
54 */
55void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
56 void (*free)(struct ipc_namespace *, struct kern_ipc_perm *))
57{
58 struct kern_ipc_perm *perm;
59 int next_id;
60 int total, in_use;
61
62 down_write(&ids->rw_mutex);
63
64 in_use = ids->in_use;
65
66 for (total = 0, next_id = 0; total < in_use; next_id++) {
67 perm = idr_find(&ids->ipcs_idr, next_id);
68 if (perm == NULL)
69 continue;
70 ipc_lock_by_ptr(perm);
71 free(ns, perm);
72 total++;
73 }
74 up_write(&ids->rw_mutex);
75}
76
47void free_ipc_ns(struct kref *kref) 77void free_ipc_ns(struct kref *kref)
48{ 78{
49 struct ipc_namespace *ns; 79 struct ipc_namespace *ns;
diff --git a/ipc/sem.c b/ipc/sem.c
index 1f7e28d1d25d..0b45a4d383c6 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -94,7 +94,7 @@
94#define sem_buildid(id, seq) ipc_buildid(id, seq) 94#define sem_buildid(id, seq) ipc_buildid(id, seq)
95 95
96static int newary(struct ipc_namespace *, struct ipc_params *); 96static int newary(struct ipc_namespace *, struct ipc_params *);
97static void freeary(struct ipc_namespace *, struct sem_array *); 97static void freeary(struct ipc_namespace *, struct kern_ipc_perm *);
98#ifdef CONFIG_PROC_FS 98#ifdef CONFIG_PROC_FS
99static int sysvipc_sem_proc_show(struct seq_file *s, void *it); 99static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
100#endif 100#endif
@@ -129,25 +129,7 @@ void sem_init_ns(struct ipc_namespace *ns)
129#ifdef CONFIG_IPC_NS 129#ifdef CONFIG_IPC_NS
130void sem_exit_ns(struct ipc_namespace *ns) 130void sem_exit_ns(struct ipc_namespace *ns)
131{ 131{
132 struct sem_array *sma; 132 free_ipcs(ns, &sem_ids(ns), freeary);
133 struct kern_ipc_perm *perm;
134 int next_id;
135 int total, in_use;
136
137 down_write(&sem_ids(ns).rw_mutex);
138
139 in_use = sem_ids(ns).in_use;
140
141 for (total = 0, next_id = 0; total < in_use; next_id++) {
142 perm = idr_find(&sem_ids(ns).ipcs_idr, next_id);
143 if (perm == NULL)
144 continue;
145 ipc_lock_by_ptr(perm);
146 sma = container_of(perm, struct sem_array, sem_perm);
147 freeary(ns, sma);
148 total++;
149 }
150 up_write(&sem_ids(ns).rw_mutex);
151} 133}
152#endif 134#endif
153 135
@@ -542,10 +524,11 @@ static int count_semzcnt (struct sem_array * sma, ushort semnum)
542 * as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex 524 * as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex
543 * remains locked on exit. 525 * remains locked on exit.
544 */ 526 */
545static void freeary(struct ipc_namespace *ns, struct sem_array *sma) 527static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
546{ 528{
547 struct sem_undo *un; 529 struct sem_undo *un;
548 struct sem_queue *q; 530 struct sem_queue *q;
531 struct sem_array *sma = container_of(ipcp, struct sem_array, sem_perm);
549 532
550 /* Invalidate the existing undo structures for this semaphore set. 533 /* Invalidate the existing undo structures for this semaphore set.
551 * (They will be freed without any further action in exit_sem() 534 * (They will be freed without any further action in exit_sem()
@@ -926,7 +909,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid, int semnum,
926 909
927 switch(cmd){ 910 switch(cmd){
928 case IPC_RMID: 911 case IPC_RMID:
929 freeary(ns, sma); 912 freeary(ns, ipcp);
930 err = 0; 913 err = 0;
931 break; 914 break;
932 case IPC_SET: 915 case IPC_SET:
diff --git a/ipc/shm.c b/ipc/shm.c
index fe92471e19c7..c47e87278a92 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -83,8 +83,11 @@ void shm_init_ns(struct ipc_namespace *ns)
83 * Called with shm_ids.rw_mutex (writer) and the shp structure locked. 83 * Called with shm_ids.rw_mutex (writer) and the shp structure locked.
84 * Only shm_ids.rw_mutex remains locked on exit. 84 * Only shm_ids.rw_mutex remains locked on exit.
85 */ 85 */
86static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp) 86static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
87{ 87{
88 struct shmid_kernel *shp;
89 shp = container_of(ipcp, struct shmid_kernel, shm_perm);
90
88 if (shp->shm_nattch){ 91 if (shp->shm_nattch){
89 shp->shm_perm.mode |= SHM_DEST; 92 shp->shm_perm.mode |= SHM_DEST;
90 /* Do not find it any more */ 93 /* Do not find it any more */
@@ -97,25 +100,7 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
97#ifdef CONFIG_IPC_NS 100#ifdef CONFIG_IPC_NS
98void shm_exit_ns(struct ipc_namespace *ns) 101void shm_exit_ns(struct ipc_namespace *ns)
99{ 102{
100 struct shmid_kernel *shp; 103 free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
101 struct kern_ipc_perm *perm;
102 int next_id;
103 int total, in_use;
104
105 down_write(&shm_ids(ns).rw_mutex);
106
107 in_use = shm_ids(ns).in_use;
108
109 for (total = 0, next_id = 0; total < in_use; next_id++) {
110 perm = idr_find(&shm_ids(ns).ipcs_idr, next_id);
111 if (perm == NULL)
112 continue;
113 ipc_lock_by_ptr(perm);
114 shp = container_of(perm, struct shmid_kernel, shm_perm);
115 do_shm_rmid(ns, shp);
116 total++;
117 }
118 up_write(&shm_ids(ns).rw_mutex);
119} 104}
120#endif 105#endif
121 106
@@ -832,7 +817,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
832 if (err) 817 if (err)
833 goto out_unlock_up; 818 goto out_unlock_up;
834 819
835 do_shm_rmid(ns, shp); 820 do_shm_rmid(ns, &shp->shm_perm);
836 up_write(&shm_ids(ns).rw_mutex); 821 up_write(&shm_ids(ns).rw_mutex);
837 goto out; 822 goto out;
838 } 823 }