diff options
-rw-r--r-- | include/linux/shm.h | 3 | ||||
-rw-r--r-- | ipc/shm.c | 27 |
2 files changed, 23 insertions, 7 deletions
diff --git a/include/linux/shm.h b/include/linux/shm.h index 7d27ffde0190..92808b86703b 100644 --- a/include/linux/shm.h +++ b/include/linux/shm.h | |||
@@ -95,6 +95,9 @@ struct shmid_kernel /* private to the kernel */ | |||
95 | pid_t shm_cprid; | 95 | pid_t shm_cprid; |
96 | pid_t shm_lprid; | 96 | pid_t shm_lprid; |
97 | struct user_struct *mlock_user; | 97 | struct user_struct *mlock_user; |
98 | |||
99 | /* The task created the shm object. NULL if the task is dead. */ | ||
100 | struct task_struct *shm_creator; | ||
98 | }; | 101 | }; |
99 | 102 | ||
100 | /* shm_mode upper byte flags */ | 103 | /* shm_mode upper byte flags */ |
@@ -239,7 +239,23 @@ static int shm_try_destroy_current(int id, void *p, void *data) | |||
239 | if (IS_ERR(shp)) | 239 | if (IS_ERR(shp)) |
240 | return 0; | 240 | return 0; |
241 | 241 | ||
242 | if (shp->shm_cprid != task_tgid_vnr(current)) { | 242 | if (shp->shm_creator != current) { |
243 | shm_unlock(shp); | ||
244 | return 0; | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Mark it as orphaned to destroy the segment when | ||
249 | * kernel.shm_rmid_forced is changed. | ||
250 | * It is noop if the following shm_may_destroy() returns true. | ||
251 | */ | ||
252 | shp->shm_creator = NULL; | ||
253 | |||
254 | /* | ||
255 | * Don't even try to destroy it. If shm_rmid_forced=0 and IPC_RMID | ||
256 | * is not set, it shouldn't be deleted here. | ||
257 | */ | ||
258 | if (!ns->shm_rmid_forced) { | ||
243 | shm_unlock(shp); | 259 | shm_unlock(shp); |
244 | return 0; | 260 | return 0; |
245 | } | 261 | } |
@@ -255,7 +271,6 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data) | |||
255 | { | 271 | { |
256 | struct ipc_namespace *ns = data; | 272 | struct ipc_namespace *ns = data; |
257 | struct shmid_kernel *shp = shm_lock(ns, id); | 273 | struct shmid_kernel *shp = shm_lock(ns, id); |
258 | struct task_struct *task; | ||
259 | 274 | ||
260 | if (IS_ERR(shp)) | 275 | if (IS_ERR(shp)) |
261 | return 0; | 276 | return 0; |
@@ -263,11 +278,8 @@ static int shm_try_destroy_orphaned(int id, void *p, void *data) | |||
263 | /* | 278 | /* |
264 | * We want to destroy segments without users and with already | 279 | * We want to destroy segments without users and with already |
265 | * exit'ed originating process. | 280 | * exit'ed originating process. |
266 | * | ||
267 | * XXX: the originating process may exist in another pid namespace. | ||
268 | */ | 281 | */ |
269 | task = find_task_by_vpid(shp->shm_cprid); | 282 | if (shp->shm_creator != NULL) { |
270 | if (task != NULL) { | ||
271 | shm_unlock(shp); | 283 | shm_unlock(shp); |
272 | return 0; | 284 | return 0; |
273 | } | 285 | } |
@@ -295,7 +307,7 @@ void exit_shm(struct task_struct *task) | |||
295 | if (!nsp) | 307 | if (!nsp) |
296 | return; | 308 | return; |
297 | ns = nsp->ipc_ns; | 309 | ns = nsp->ipc_ns; |
298 | if (!ns || !ns->shm_rmid_forced) | 310 | if (!ns) |
299 | return; | 311 | return; |
300 | 312 | ||
301 | /* Destroy all already created segments, but not mapped yet */ | 313 | /* Destroy all already created segments, but not mapped yet */ |
@@ -494,6 +506,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) | |||
494 | shp->shm_segsz = size; | 506 | shp->shm_segsz = size; |
495 | shp->shm_nattch = 0; | 507 | shp->shm_nattch = 0; |
496 | shp->shm_file = file; | 508 | shp->shm_file = file; |
509 | shp->shm_creator = current; | ||
497 | /* | 510 | /* |
498 | * shmid gets reported as "inode#" in /proc/pid/maps. | 511 | * shmid gets reported as "inode#" in /proc/pid/maps. |
499 | * proc-ps tools use this. Changing this will break them. | 512 | * proc-ps tools use this. Changing this will break them. |