Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/process_vm_access.c |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Christopher Yeoh <cyeoh@au1.ibm.com>, IBM Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/uio.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/highmem.h> |
| 16 | #include <linux/ptrace.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/syscalls.h> |
| 19 | |
| 20 | #ifdef CONFIG_COMPAT |
| 21 | #include <linux/compat.h> |
| 22 | #endif |
| 23 | |
| 24 | /** |
| 25 | * process_vm_rw_pages - read/write pages from task specified |
| 26 | * @task: task to read/write from |
| 27 | * @mm: mm for task |
| 28 | * @process_pages: struct pages area that can store at least |
| 29 | * nr_pages_to_copy struct page pointers |
| 30 | * @pa: address of page in task to start copying from/to |
| 31 | * @start_offset: offset in page to start copying from/to |
| 32 | * @len: number of bytes to copy |
| 33 | * @lvec: iovec array specifying where to copy to/from |
| 34 | * @lvec_cnt: number of elements in iovec array |
| 35 | * @lvec_current: index in iovec array we are up to |
| 36 | * @lvec_offset: offset in bytes from current iovec iov_base we are up to |
| 37 | * @vm_write: 0 means copy from, 1 means copy to |
| 38 | * @nr_pages_to_copy: number of pages to copy |
| 39 | * @bytes_copied: returns number of bytes successfully copied |
| 40 | * Returns 0 on success, error code otherwise |
| 41 | */ |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 42 | static int process_vm_rw_pages(struct page **pages, |
| 43 | unsigned offset, |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 44 | size_t len, |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 45 | struct iov_iter *iter, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 46 | int vm_write, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 47 | ssize_t *bytes_copied) |
| 48 | { |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 49 | *bytes_copied = 0; |
| 50 | |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 51 | /* Do the copy for each page */ |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 52 | while (iov_iter_count(iter) && len) { |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 53 | struct page *page = *pages++; |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 54 | size_t copy = PAGE_SIZE - offset; |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 55 | size_t copied; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 56 | |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 57 | if (copy > len) |
| 58 | copy = len; |
| 59 | |
Al Viro | 240f390 | 2014-02-05 12:14:11 -0500 | [diff] [blame] | 60 | if (vm_write) { |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 61 | if (copy > iov_iter_count(iter)) |
| 62 | copy = iov_iter_count(iter); |
| 63 | copied = iov_iter_copy_from_user(page, iter, |
| 64 | offset, copy); |
| 65 | iov_iter_advance(iter, copied); |
Al Viro | 240f390 | 2014-02-05 12:14:11 -0500 | [diff] [blame] | 66 | set_page_dirty_lock(page); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 67 | } else { |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 68 | copied = copy_page_to_iter(page, offset, copy, iter); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 69 | } |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 70 | *bytes_copied += copied; |
| 71 | len -= copied; |
| 72 | if (copied < copy && iov_iter_count(iter)) |
| 73 | return -EFAULT; |
| 74 | offset = 0; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 75 | } |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 76 | return 0; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* Maximum number of pages kmalloc'd to hold struct page's during copy */ |
| 80 | #define PVM_MAX_KMALLOC_PAGES (PAGE_SIZE * 2) |
| 81 | |
| 82 | /** |
| 83 | * process_vm_rw_single_vec - read/write pages from task specified |
| 84 | * @addr: start memory address of target process |
| 85 | * @len: size of area to copy to/from |
| 86 | * @lvec: iovec array specifying where to copy to/from locally |
| 87 | * @lvec_cnt: number of elements in iovec array |
| 88 | * @lvec_current: index in iovec array we are up to |
| 89 | * @lvec_offset: offset in bytes from current iovec iov_base we are up to |
| 90 | * @process_pages: struct pages area that can store at least |
| 91 | * nr_pages_to_copy struct page pointers |
| 92 | * @mm: mm for task |
| 93 | * @task: task to read/write from |
| 94 | * @vm_write: 0 means copy from, 1 means copy to |
| 95 | * @bytes_copied: returns number of bytes successfully copied |
| 96 | * Returns 0 on success or on failure error code |
| 97 | */ |
| 98 | static int process_vm_rw_single_vec(unsigned long addr, |
| 99 | unsigned long len, |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 100 | struct iov_iter *iter, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 101 | struct page **process_pages, |
| 102 | struct mm_struct *mm, |
| 103 | struct task_struct *task, |
| 104 | int vm_write, |
| 105 | ssize_t *bytes_copied) |
| 106 | { |
| 107 | unsigned long pa = addr & PAGE_MASK; |
| 108 | unsigned long start_offset = addr - pa; |
| 109 | unsigned long nr_pages; |
| 110 | ssize_t bytes_copied_loop; |
| 111 | ssize_t rc = 0; |
| 112 | unsigned long nr_pages_copied = 0; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 113 | unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES |
| 114 | / sizeof(struct pages *); |
| 115 | |
| 116 | *bytes_copied = 0; |
| 117 | |
| 118 | /* Work out address and page range required */ |
| 119 | if (len == 0) |
| 120 | return 0; |
| 121 | nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1; |
| 122 | |
Al Viro | 240f390 | 2014-02-05 12:14:11 -0500 | [diff] [blame] | 123 | while ((nr_pages_copied < nr_pages) && iov_iter_count(iter)) { |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 124 | int nr_pages_to_copy; |
| 125 | int pages_pinned; |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 126 | size_t n; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 127 | nr_pages_to_copy = min(nr_pages - nr_pages_copied, |
| 128 | max_pages_per_loop); |
| 129 | |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 130 | /* Get the pages we're interested in */ |
| 131 | down_read(&mm->mmap_sem); |
| 132 | pages_pinned = get_user_pages(task, mm, pa, |
| 133 | nr_pages_to_copy, |
| 134 | vm_write, 0, process_pages, NULL); |
| 135 | up_read(&mm->mmap_sem); |
| 136 | |
| 137 | if (pages_pinned <= 0) |
| 138 | return -EFAULT; |
| 139 | |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 140 | n = pages_pinned * PAGE_SIZE - start_offset; |
| 141 | if (n > len) |
| 142 | n = len; |
| 143 | |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 144 | rc = process_vm_rw_pages(process_pages, |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 145 | start_offset, n, iter, |
| 146 | vm_write, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 147 | &bytes_copied_loop); |
Al Viro | e21345f | 2014-02-05 12:55:11 -0500 | [diff] [blame^] | 148 | len -= n; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 149 | start_offset = 0; |
| 150 | *bytes_copied += bytes_copied_loop; |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 151 | nr_pages_copied += pages_pinned; |
| 152 | pa += pages_pinned * PAGE_SIZE; |
| 153 | while (pages_pinned) |
| 154 | put_page(process_pages[--pages_pinned]); |
Al Viro | 70eca12 | 2014-02-05 12:44:24 -0500 | [diff] [blame] | 155 | if (rc < 0) |
| 156 | break; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | return rc; |
| 160 | } |
| 161 | |
| 162 | /* Maximum number of entries for process pages array |
| 163 | which lives on stack */ |
| 164 | #define PVM_MAX_PP_ARRAY_COUNT 16 |
| 165 | |
| 166 | /** |
| 167 | * process_vm_rw_core - core of reading/writing pages from task specified |
| 168 | * @pid: PID of process to read/write from/to |
| 169 | * @lvec: iovec array specifying where to copy to/from locally |
| 170 | * @liovcnt: size of lvec array |
| 171 | * @rvec: iovec array specifying where to copy to/from in the other process |
| 172 | * @riovcnt: size of rvec array |
| 173 | * @flags: currently unused |
| 174 | * @vm_write: 0 if reading from other process, 1 if writing to other process |
| 175 | * Returns the number of bytes read/written or error code. May |
| 176 | * return less bytes than expected if an error occurs during the copying |
| 177 | * process. |
| 178 | */ |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 179 | static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 180 | const struct iovec *rvec, |
| 181 | unsigned long riovcnt, |
| 182 | unsigned long flags, int vm_write) |
| 183 | { |
| 184 | struct task_struct *task; |
| 185 | struct page *pp_stack[PVM_MAX_PP_ARRAY_COUNT]; |
| 186 | struct page **process_pages = pp_stack; |
| 187 | struct mm_struct *mm; |
| 188 | unsigned long i; |
| 189 | ssize_t rc = 0; |
| 190 | ssize_t bytes_copied_loop; |
| 191 | ssize_t bytes_copied = 0; |
| 192 | unsigned long nr_pages = 0; |
| 193 | unsigned long nr_pages_iov; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 194 | ssize_t iov_len; |
| 195 | |
| 196 | /* |
| 197 | * Work out how many pages of struct pages we're going to need |
| 198 | * when eventually calling get_user_pages |
| 199 | */ |
| 200 | for (i = 0; i < riovcnt; i++) { |
| 201 | iov_len = rvec[i].iov_len; |
| 202 | if (iov_len > 0) { |
| 203 | nr_pages_iov = ((unsigned long)rvec[i].iov_base |
| 204 | + iov_len) |
| 205 | / PAGE_SIZE - (unsigned long)rvec[i].iov_base |
| 206 | / PAGE_SIZE + 1; |
| 207 | nr_pages = max(nr_pages, nr_pages_iov); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | if (nr_pages == 0) |
| 212 | return 0; |
| 213 | |
| 214 | if (nr_pages > PVM_MAX_PP_ARRAY_COUNT) { |
| 215 | /* For reliability don't try to kmalloc more than |
| 216 | 2 pages worth */ |
| 217 | process_pages = kmalloc(min_t(size_t, PVM_MAX_KMALLOC_PAGES, |
| 218 | sizeof(struct pages *)*nr_pages), |
| 219 | GFP_KERNEL); |
| 220 | |
| 221 | if (!process_pages) |
| 222 | return -ENOMEM; |
| 223 | } |
| 224 | |
| 225 | /* Get process information */ |
| 226 | rcu_read_lock(); |
| 227 | task = find_task_by_vpid(pid); |
| 228 | if (task) |
| 229 | get_task_struct(task); |
| 230 | rcu_read_unlock(); |
| 231 | if (!task) { |
| 232 | rc = -ESRCH; |
| 233 | goto free_proc_pages; |
| 234 | } |
| 235 | |
Christopher Yeoh | 8cdb878 | 2012-02-02 11:34:09 +1030 | [diff] [blame] | 236 | mm = mm_access(task, PTRACE_MODE_ATTACH); |
| 237 | if (!mm || IS_ERR(mm)) { |
| 238 | rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH; |
| 239 | /* |
| 240 | * Explicitly map EACCES to EPERM as EPERM is a more a |
| 241 | * appropriate error code for process_vw_readv/writev |
| 242 | */ |
| 243 | if (rc == -EACCES) |
| 244 | rc = -EPERM; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 245 | goto put_task_struct; |
| 246 | } |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 247 | |
Al Viro | 240f390 | 2014-02-05 12:14:11 -0500 | [diff] [blame] | 248 | for (i = 0; i < riovcnt && iov_iter_count(iter); i++) { |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 249 | rc = process_vm_rw_single_vec( |
| 250 | (unsigned long)rvec[i].iov_base, rvec[i].iov_len, |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 251 | iter, process_pages, mm, task, vm_write, |
| 252 | &bytes_copied_loop); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 253 | bytes_copied += bytes_copied_loop; |
| 254 | if (rc != 0) { |
| 255 | /* If we have managed to copy any data at all then |
| 256 | we return the number of bytes copied. Otherwise |
| 257 | we return the error code */ |
| 258 | if (bytes_copied) |
| 259 | rc = bytes_copied; |
| 260 | goto put_mm; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | rc = bytes_copied; |
| 265 | put_mm: |
| 266 | mmput(mm); |
| 267 | |
| 268 | put_task_struct: |
| 269 | put_task_struct(task); |
| 270 | |
| 271 | free_proc_pages: |
| 272 | if (process_pages != pp_stack) |
| 273 | kfree(process_pages); |
| 274 | return rc; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * process_vm_rw - check iovecs before calling core routine |
| 279 | * @pid: PID of process to read/write from/to |
| 280 | * @lvec: iovec array specifying where to copy to/from locally |
| 281 | * @liovcnt: size of lvec array |
| 282 | * @rvec: iovec array specifying where to copy to/from in the other process |
| 283 | * @riovcnt: size of rvec array |
| 284 | * @flags: currently unused |
| 285 | * @vm_write: 0 if reading from other process, 1 if writing to other process |
| 286 | * Returns the number of bytes read/written or error code. May |
| 287 | * return less bytes than expected if an error occurs during the copying |
| 288 | * process. |
| 289 | */ |
| 290 | static ssize_t process_vm_rw(pid_t pid, |
| 291 | const struct iovec __user *lvec, |
| 292 | unsigned long liovcnt, |
| 293 | const struct iovec __user *rvec, |
| 294 | unsigned long riovcnt, |
| 295 | unsigned long flags, int vm_write) |
| 296 | { |
| 297 | struct iovec iovstack_l[UIO_FASTIOV]; |
| 298 | struct iovec iovstack_r[UIO_FASTIOV]; |
| 299 | struct iovec *iov_l = iovstack_l; |
| 300 | struct iovec *iov_r = iovstack_r; |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 301 | struct iov_iter iter; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 302 | ssize_t rc; |
| 303 | |
| 304 | if (flags != 0) |
| 305 | return -EINVAL; |
| 306 | |
| 307 | /* Check iovecs */ |
| 308 | if (vm_write) |
| 309 | rc = rw_copy_check_uvector(WRITE, lvec, liovcnt, UIO_FASTIOV, |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 310 | iovstack_l, &iov_l); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 311 | else |
| 312 | rc = rw_copy_check_uvector(READ, lvec, liovcnt, UIO_FASTIOV, |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 313 | iovstack_l, &iov_l); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 314 | if (rc <= 0) |
| 315 | goto free_iovecs; |
| 316 | |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 317 | iov_iter_init(&iter, iov_l, liovcnt, rc, 0); |
| 318 | |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 319 | rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, |
| 320 | iovstack_r, &iov_r); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 321 | if (rc <= 0) |
| 322 | goto free_iovecs; |
| 323 | |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 324 | rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 325 | |
| 326 | free_iovecs: |
| 327 | if (iov_r != iovstack_r) |
| 328 | kfree(iov_r); |
| 329 | if (iov_l != iovstack_l) |
| 330 | kfree(iov_l); |
| 331 | |
| 332 | return rc; |
| 333 | } |
| 334 | |
| 335 | SYSCALL_DEFINE6(process_vm_readv, pid_t, pid, const struct iovec __user *, lvec, |
| 336 | unsigned long, liovcnt, const struct iovec __user *, rvec, |
| 337 | unsigned long, riovcnt, unsigned long, flags) |
| 338 | { |
| 339 | return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 0); |
| 340 | } |
| 341 | |
| 342 | SYSCALL_DEFINE6(process_vm_writev, pid_t, pid, |
| 343 | const struct iovec __user *, lvec, |
| 344 | unsigned long, liovcnt, const struct iovec __user *, rvec, |
| 345 | unsigned long, riovcnt, unsigned long, flags) |
| 346 | { |
| 347 | return process_vm_rw(pid, lvec, liovcnt, rvec, riovcnt, flags, 1); |
| 348 | } |
| 349 | |
| 350 | #ifdef CONFIG_COMPAT |
| 351 | |
| 352 | asmlinkage ssize_t |
| 353 | compat_process_vm_rw(compat_pid_t pid, |
| 354 | const struct compat_iovec __user *lvec, |
| 355 | unsigned long liovcnt, |
| 356 | const struct compat_iovec __user *rvec, |
| 357 | unsigned long riovcnt, |
| 358 | unsigned long flags, int vm_write) |
| 359 | { |
| 360 | struct iovec iovstack_l[UIO_FASTIOV]; |
| 361 | struct iovec iovstack_r[UIO_FASTIOV]; |
| 362 | struct iovec *iov_l = iovstack_l; |
| 363 | struct iovec *iov_r = iovstack_r; |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 364 | struct iov_iter iter; |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 365 | ssize_t rc = -EFAULT; |
| 366 | |
| 367 | if (flags != 0) |
| 368 | return -EINVAL; |
| 369 | |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 370 | if (vm_write) |
| 371 | rc = compat_rw_copy_check_uvector(WRITE, lvec, liovcnt, |
| 372 | UIO_FASTIOV, iovstack_l, |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 373 | &iov_l); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 374 | else |
| 375 | rc = compat_rw_copy_check_uvector(READ, lvec, liovcnt, |
| 376 | UIO_FASTIOV, iovstack_l, |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 377 | &iov_l); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 378 | if (rc <= 0) |
| 379 | goto free_iovecs; |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 380 | iov_iter_init(&iter, iov_l, liovcnt, rc, 0); |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 381 | rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 382 | UIO_FASTIOV, iovstack_r, |
Christopher Yeoh | ac34ebb | 2012-05-31 16:26:42 -0700 | [diff] [blame] | 383 | &iov_r); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 384 | if (rc <= 0) |
| 385 | goto free_iovecs; |
| 386 | |
Al Viro | 9f78bdf | 2014-02-05 11:51:53 -0500 | [diff] [blame] | 387 | rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 388 | |
| 389 | free_iovecs: |
| 390 | if (iov_r != iovstack_r) |
| 391 | kfree(iov_r); |
| 392 | if (iov_l != iovstack_l) |
| 393 | kfree(iov_l); |
Christopher Yeoh | fcf6340 | 2011-10-31 17:06:39 -0700 | [diff] [blame] | 394 | return rc; |
| 395 | } |
| 396 | |
| 397 | asmlinkage ssize_t |
| 398 | compat_sys_process_vm_readv(compat_pid_t pid, |
| 399 | const struct compat_iovec __user *lvec, |
| 400 | unsigned long liovcnt, |
| 401 | const struct compat_iovec __user *rvec, |
| 402 | unsigned long riovcnt, |
| 403 | unsigned long flags) |
| 404 | { |
| 405 | return compat_process_vm_rw(pid, lvec, liovcnt, rvec, |
| 406 | riovcnt, flags, 0); |
| 407 | } |
| 408 | |
| 409 | asmlinkage ssize_t |
| 410 | compat_sys_process_vm_writev(compat_pid_t pid, |
| 411 | const struct compat_iovec __user *lvec, |
| 412 | unsigned long liovcnt, |
| 413 | const struct compat_iovec __user *rvec, |
| 414 | unsigned long riovcnt, |
| 415 | unsigned long flags) |
| 416 | { |
| 417 | return compat_process_vm_rw(pid, lvec, liovcnt, rvec, |
| 418 | riovcnt, flags, 1); |
| 419 | } |
| 420 | |
| 421 | #endif |