Public bug reported: After finding out https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2167919 I wanted to check if there are more incorrectly backported fixes in Noble kernel. While checking for other backports I found incorrectly resolved upstream commit c2c185be5c85d ("io_uring/kbuf: check if target buffer list is still legacy on recycle") in our 0c4f963808549 backport.
Our backport omitted cleanup when a selected legacy buffer cannot be returned to its original group. I would guess that it was resolved this way as this is how upstream did it for v6.6. Problem is, v6.8 is more like v6.18 (where the upstream fix landed) than v6.6 in this context. This is due to https://github.com/torvalds/linux/commit/b3a4dbc89d40 being introduced in v6.7 If you compare the io_destroy_buffers() in v6.6, it iterates over the ctx->io_buffers_pages (as it uses custom allocator which tracks all the pages is allocated) so it doesn't need pointers for individual "objects". This single "slot" in a page is not put into reusable list so the memory is kinda lost but not forever as it will be recovered when the whole page is deallocated eventually. The buffer pointer can be owned by one of 4 objects: - `ctx->io_buffers_cache` (initially or moved from `req->kbuf` in `__io_put_kbuf()` or from `ctx->io_buffers_comp` in `io_refill_buffer_cache()` - `ctx->io_buffers_comp` (moved from `req->kbuf` in `__io_put_kbuf()`) - `bl->buf_list` (moved from `ctx->io_buffers_cache` in `io_add_buffers()`) - `req->kbuf` (moved from `bl->buf_list` inside of `io_provided_buffer_select()`) Before that backported patch, the `io_kbuf_recycle_legacy` would always recycle the buffer by putting it back to the buf_list but now this may not happen and in this case the buffer is not present on any list anymore and `req->kbuf` is cleared so all the pointers for this buffer are lost. If you look at the io_destroy_buffers() in v6.6, it collects all buffers from `bl->buf_list` and from `ctx->io_buffers_comp` back to `ctx->io_buffers_cache` and then frees only buffers on `ctx->io_buffers_cache`. So before the loop is called, the io_buffers_cache consists of: - never used buffers (that were there always - the buffers moved from bl->buf_list - the buffers moved from io_buffers_cache So when io_kbuf_recycle_legacy is called, the buffer is owned by req->kbuf only and is not present on any of those lists. While previously the function would always move the buffer back to bl->buf_list before discarding it, the code can now (after backporting c2c185be5c85d) skip moving it but still clear req->kbuf which was the only reference to it creating a leak. ** Affects: linux (Ubuntu) Importance: Undecided Status: New -- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2174389 Title: Noble: incorrect backport of io_uring/kbuf: check if target buffer list is still legacy on recycle To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2174389/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
