diff options
| -rw-r--r-- | ipc/shm.c | 28 |
1 files changed, 23 insertions, 5 deletions
| @@ -208,15 +208,18 @@ static void shm_open(struct vm_area_struct *vma) | |||
| 208 | */ | 208 | */ |
| 209 | static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) | 209 | static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) |
| 210 | { | 210 | { |
| 211 | struct file *shm_file; | ||
| 212 | |||
| 213 | shm_file = shp->shm_file; | ||
| 214 | shp->shm_file = NULL; | ||
| 211 | ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; | 215 | ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 212 | shm_rmid(ns, shp); | 216 | shm_rmid(ns, shp); |
| 213 | shm_unlock(shp); | 217 | shm_unlock(shp); |
| 214 | if (!is_file_hugepages(shp->shm_file)) | 218 | if (!is_file_hugepages(shm_file)) |
| 215 | shmem_lock(shp->shm_file, 0, shp->mlock_user); | 219 | shmem_lock(shm_file, 0, shp->mlock_user); |
| 216 | else if (shp->mlock_user) | 220 | else if (shp->mlock_user) |
| 217 | user_shm_unlock(file_inode(shp->shm_file)->i_size, | 221 | user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user); |
| 218 | shp->mlock_user); | 222 | fput(shm_file); |
| 219 | fput (shp->shm_file); | ||
| 220 | ipc_rcu_putref(shp, shm_rcu_free); | 223 | ipc_rcu_putref(shp, shm_rcu_free); |
| 221 | } | 224 | } |
| 222 | 225 | ||
| @@ -983,6 +986,13 @@ SYSCALL_DEFINE3(shmctl, int, shmid, int, cmd, struct shmid_ds __user *, buf) | |||
| 983 | } | 986 | } |
| 984 | 987 | ||
| 985 | shm_file = shp->shm_file; | 988 | shm_file = shp->shm_file; |
| 989 | |||
| 990 | /* check if shm_destroy() is tearing down shp */ | ||
| 991 | if (shm_file == NULL) { | ||
| 992 | err = -EIDRM; | ||
| 993 | goto out_unlock0; | ||
| 994 | } | ||
| 995 | |||
| 986 | if (is_file_hugepages(shm_file)) | 996 | if (is_file_hugepages(shm_file)) |
| 987 | goto out_unlock0; | 997 | goto out_unlock0; |
| 988 | 998 | ||
| @@ -1101,6 +1111,14 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr, | |||
| 1101 | goto out_unlock; | 1111 | goto out_unlock; |
| 1102 | 1112 | ||
| 1103 | ipc_lock_object(&shp->shm_perm); | 1113 | ipc_lock_object(&shp->shm_perm); |
| 1114 | |||
| 1115 | /* check if shm_destroy() is tearing down shp */ | ||
| 1116 | if (shp->shm_file == NULL) { | ||
| 1117 | ipc_unlock_object(&shp->shm_perm); | ||
| 1118 | err = -EIDRM; | ||
| 1119 | goto out_unlock; | ||
| 1120 | } | ||
| 1121 | |||
| 1104 | path = shp->shm_file->f_path; | 1122 | path = shp->shm_file->f_path; |
| 1105 | path_get(&path); | 1123 | path_get(&path); |
| 1106 | shp->shm_nattch++; | 1124 | shp->shm_nattch++; |
