Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: improve regbuf iov validation

Deduplicate io_buffer_validate() calls by moving the checks into
io_sqe_buffer_register(). Now we also don't need special handling in
io_buffer_validate() passing through buffer removal requests. I also
was using it as a cleanup before some other changes.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
2e02f9ef 046fcc83

+10 -21
+10 -21
io_uring/rsrc.c
··· 96 96 return 0; 97 97 } 98 98 99 - static int io_buffer_validate(struct iovec *iov) 100 - { 101 - /* 102 - * Don't impose further limits on the size and buffer 103 - * constraints here, we'll -EINVAL later when IO is 104 - * submitted if they are wrong. 105 - */ 106 - if (!iov->iov_base) 107 - return iov->iov_len ? -EFAULT : 0; 108 - 109 - return io_validate_user_buf_range((unsigned long)iov->iov_base, 110 - iov->iov_len); 111 - } 112 - 113 99 static void io_release_ubuf(void *priv) 114 100 { 115 101 struct io_mapped_ubuf *imu = priv; ··· 305 319 err = -EFAULT; 306 320 break; 307 321 } 308 - err = io_buffer_validate(iov); 309 - if (err) 310 - break; 311 322 node = io_sqe_buffer_register(ctx, iov, &last_hpage); 312 323 if (IS_ERR(node)) { 313 324 err = PTR_ERR(node); ··· 773 790 struct io_imu_folio_data data; 774 791 bool coalesced = false; 775 792 776 - if (!iov->iov_base) 793 + if (!iov->iov_base) { 794 + if (iov->iov_len) 795 + return ERR_PTR(-EFAULT); 796 + /* remove the buffer without installing a new one */ 777 797 return NULL; 798 + } 799 + 800 + ret = io_validate_user_buf_range((unsigned long)iov->iov_base, 801 + iov->iov_len); 802 + if (ret) 803 + return ERR_PTR(ret); 778 804 779 805 node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER); 780 806 if (!node) ··· 889 897 ret = PTR_ERR(iov); 890 898 break; 891 899 } 892 - ret = io_buffer_validate(iov); 893 - if (ret) 894 - break; 895 900 if (ctx->compat) 896 901 arg += sizeof(struct compat_iovec); 897 902 else