io_uring/net: commit partial buffers on retry
authorJens Axboe <axboe@kernel.dk>
Tue, 12 Aug 2025 14:30:11 +0000 (08:30 -0600)
committerJens Axboe <axboe@kernel.dk>
Tue, 12 Aug 2025 19:41:26 +0000 (13:41 -0600)
commit41b70df5b38bc80967d2e0ed55cc3c3896bba781
treeebe93432c3e63f9122cea4755e3cce49d39f3924
parent8f5ae30d69d7543eee0d70083daf4de8fe15d585
io_uring/net: commit partial buffers on retry

Ring provided buffers are potentially only valid within the single
execution context in which they were acquired. io_uring deals with this
and invalidates them on retry. But on the networking side, if
MSG_WAITALL is set, or if the socket is of the streaming type and too
little was processed, then it will hang on to the buffer rather than
recycle or commit it. This is problematic for two reasons:

1) If someone unregisters the provided buffer ring before a later retry,
   then the req->buf_list will no longer be valid.

2) If multiple sockers are using the same buffer group, then multiple
   receives can consume the same memory. This can cause data corruption
   in the application, as either receive could land in the same
   userspace buffer.

Fix this by disallowing partial retries from pinning a provided buffer
across multiple executions, if ring provided buffers are used.

Cc: stable@vger.kernel.org
Reported-by: pt x <superman.xpt@gmail.com>
Fixes: c56e022c0a27 ("io_uring: add support for user mapped provided buffer ring")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/net.c