diff options
Diffstat (limited to 'ipc/shm.c')
-rw-r--r-- | ipc/shm.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -219,7 +219,8 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) | |||
219 | if (!is_file_hugepages(shm_file)) | 219 | if (!is_file_hugepages(shm_file)) |
220 | shmem_lock(shm_file, 0, shp->mlock_user); | 220 | shmem_lock(shm_file, 0, shp->mlock_user); |
221 | else if (shp->mlock_user) | 221 | else if (shp->mlock_user) |
222 | user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user); | 222 | user_shm_unlock(i_size_read(file_inode(shm_file)), |
223 | shp->mlock_user); | ||
223 | fput(shm_file); | 224 | fput(shm_file); |
224 | ipc_rcu_putref(shp, shm_rcu_free); | 225 | ipc_rcu_putref(shp, shm_rcu_free); |
225 | } | 226 | } |
@@ -1229,6 +1230,7 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1229 | int retval = -EINVAL; | 1230 | int retval = -EINVAL; |
1230 | #ifdef CONFIG_MMU | 1231 | #ifdef CONFIG_MMU |
1231 | loff_t size = 0; | 1232 | loff_t size = 0; |
1233 | struct file *file; | ||
1232 | struct vm_area_struct *next; | 1234 | struct vm_area_struct *next; |
1233 | #endif | 1235 | #endif |
1234 | 1236 | ||
@@ -1245,7 +1247,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1245 | * started at address shmaddr. It records it's size and then unmaps | 1247 | * started at address shmaddr. It records it's size and then unmaps |
1246 | * it. | 1248 | * it. |
1247 | * - Then it unmaps all shm vmas that started at shmaddr and that | 1249 | * - Then it unmaps all shm vmas that started at shmaddr and that |
1248 | * are within the initially determined size. | 1250 | * are within the initially determined size and that are from the |
1251 | * same shm segment from which we determined the size. | ||
1249 | * Errors from do_munmap are ignored: the function only fails if | 1252 | * Errors from do_munmap are ignored: the function only fails if |
1250 | * it's called with invalid parameters or if it's called to unmap | 1253 | * it's called with invalid parameters or if it's called to unmap |
1251 | * a part of a vma. Both calls in this function are for full vmas, | 1254 | * a part of a vma. Both calls in this function are for full vmas, |
@@ -1271,8 +1274,14 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1271 | if ((vma->vm_ops == &shm_vm_ops) && | 1274 | if ((vma->vm_ops == &shm_vm_ops) && |
1272 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) { | 1275 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) { |
1273 | 1276 | ||
1274 | 1277 | /* | |
1275 | size = file_inode(vma->vm_file)->i_size; | 1278 | * Record the file of the shm segment being |
1279 | * unmapped. With mremap(), someone could place | ||
1280 | * page from another segment but with equal offsets | ||
1281 | * in the range we are unmapping. | ||
1282 | */ | ||
1283 | file = vma->vm_file; | ||
1284 | size = i_size_read(file_inode(vma->vm_file)); | ||
1276 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); | 1285 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); |
1277 | /* | 1286 | /* |
1278 | * We discovered the size of the shm segment, so | 1287 | * We discovered the size of the shm segment, so |
@@ -1298,8 +1307,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1298 | 1307 | ||
1299 | /* finding a matching vma now does not alter retval */ | 1308 | /* finding a matching vma now does not alter retval */ |
1300 | if ((vma->vm_ops == &shm_vm_ops) && | 1309 | if ((vma->vm_ops == &shm_vm_ops) && |
1301 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) | 1310 | ((vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) && |
1302 | 1311 | (vma->vm_file == file)) | |
1303 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); | 1312 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); |
1304 | vma = next; | 1313 | vma = next; |
1305 | } | 1314 | } |