Skip to content

Commit edd4782

Browse files
isilenceaxboe
authored andcommitted
io_uring/rsrc: disallow multi-source reg buffers
If two or more mappings go back to back to each other they can be passed into io_uring to be registered as a single registered buffer. That would even work if mappings came from different sources, e.g. it's possible to mix in this way anon pages and pages from shmem or hugetlb. That is not a problem but it'd rather be less prone if we forbid such mixing. Cc: <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 9a1563d commit edd4782

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

io_uring/rsrc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,14 +1162,17 @@ struct page **io_pin_pages(unsigned long ubuf, unsigned long len, int *npages)
11621162
pret = pin_user_pages(ubuf, nr_pages, FOLL_WRITE | FOLL_LONGTERM,
11631163
pages, vmas);
11641164
if (pret == nr_pages) {
1165+
struct file *file = vmas[0]->vm_file;
1166+
11651167
/* don't support file backed memory */
11661168
for (i = 0; i < nr_pages; i++) {
1167-
struct vm_area_struct *vma = vmas[i];
1168-
1169-
if (vma_is_shmem(vma))
1169+
if (vmas[i]->vm_file != file) {
1170+
ret = -EINVAL;
1171+
break;
1172+
}
1173+
if (!file)
11701174
continue;
1171-
if (vma->vm_file &&
1172-
!is_file_hugepages(vma->vm_file)) {
1175+
if (!vma_is_shmem(vmas[i]) && !is_file_hugepages(file)) {
11731176
ret = -EOPNOTSUPP;
11741177
break;
11751178
}

0 commit comments

Comments
 (0)