diff options
-rw-r--r-- | ipc/shm.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -1229,6 +1229,7 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1229 | int retval = -EINVAL; | 1229 | int retval = -EINVAL; |
1230 | #ifdef CONFIG_MMU | 1230 | #ifdef CONFIG_MMU |
1231 | loff_t size = 0; | 1231 | loff_t size = 0; |
1232 | struct file *file; | ||
1232 | struct vm_area_struct *next; | 1233 | struct vm_area_struct *next; |
1233 | #endif | 1234 | #endif |
1234 | 1235 | ||
@@ -1245,7 +1246,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1245 | * started at address shmaddr. It records it's size and then unmaps | 1246 | * started at address shmaddr. It records it's size and then unmaps |
1246 | * it. | 1247 | * it. |
1247 | * - Then it unmaps all shm vmas that started at shmaddr and that | 1248 | * - Then it unmaps all shm vmas that started at shmaddr and that |
1248 | * are within the initially determined size. | 1249 | * are within the initially determined size and that are from the |
1250 | * same shm segment from which we determined the size. | ||
1249 | * Errors from do_munmap are ignored: the function only fails if | 1251 | * 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 | 1252 | * 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, | 1253 | * a part of a vma. Both calls in this function are for full vmas, |
@@ -1271,8 +1273,14 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1271 | if ((vma->vm_ops == &shm_vm_ops) && | 1273 | if ((vma->vm_ops == &shm_vm_ops) && |
1272 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) { | 1274 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) { |
1273 | 1275 | ||
1274 | 1276 | /* | |
1275 | size = file_inode(vma->vm_file)->i_size; | 1277 | * Record the file of the shm segment being |
1278 | * unmapped. With mremap(), someone could place | ||
1279 | * page from another segment but with equal offsets | ||
1280 | * in the range we are unmapping. | ||
1281 | */ | ||
1282 | file = vma->vm_file; | ||
1283 | size = file_inode(file)->i_size; | ||
1276 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); | 1284 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); |
1277 | /* | 1285 | /* |
1278 | * We discovered the size of the shm segment, so | 1286 | * We discovered the size of the shm segment, so |
@@ -1298,8 +1306,8 @@ SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) | |||
1298 | 1306 | ||
1299 | /* finding a matching vma now does not alter retval */ | 1307 | /* finding a matching vma now does not alter retval */ |
1300 | if ((vma->vm_ops == &shm_vm_ops) && | 1308 | if ((vma->vm_ops == &shm_vm_ops) && |
1301 | (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) | 1309 | ((vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) && |
1302 | 1310 | (vma->vm_file == file)) | |
1303 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); | 1311 | do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); |
1304 | vma = next; | 1312 | vma = next; |
1305 | } | 1313 | } |