В ядре Linux устранена следующая уязвимость:
io_uring/cmd: исправлена утечка iovec, когда асинхронный cmd не перерабатывается.
io_async_cmd содержит массив iovec в ->vec.iovec, выделяемый при
vec должен расти и сохраняться при переработке через ctx->cmd_cache. На двух
пути ничего не освобождает, и kfree(req->async_data) io_clean_op() падает
io_async_cmd без него.
io_req_uring_cleanup() очищает флаги асинхронных данных только тогда, когда
io_alloc_cache_put() завершается успешно, и в кеше хранится IO_ALLOC_CACHE_MAX ==
128 записей, поэтому, как только он заполнится, пут не удастся, и вексель останется позади. Рабочая нагрузка NVMe passthrough проходит без каких-либо необычных действий:
nvme_uring_cmd_io() возвращает -EIOCBQUEUED, поэтому io_async_cmd остается
прикрепляется на время жизни команды и отслеживает количество живых объектов
глубина очереди.
Выше 128 пут-опционы начинают проигрывать.
->очистка — это последний шанс освободить унаследованный vec, поскольку
io_req_uring_cleanup() возвращается раньше для команды, выданной io-wq, и
вообще не вызывается, если он завершен, но так и не был выпущен. Но
io_clean_op() вызывает ->cleanup только в том случае, если установлен REQ_F_NEED_CLEANUP, и для
uring_cmd это происходит только там, где vec должен расти, поэтому команда
повторное использование достаточно большого кэшированного вектора никогда не устанавливает его. io_rw_alloc_async() и
io_msg_alloc_async() отмечает унаследованный vec именно по этой причине;
io_uring_cmd_prep() этого не делает. Пометьте унаследованный vec в io_uring_cmd_prep() и освободите его, когда
установка кэша не удалась, как это делает io_req_rw_cleanup().
Утечка незаметна под KASAN, где io_alloc_cache_vec_kasan() освобождает
век безоговорочно.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: io_uring/cmd: fix iovec leak when the async cmd is not recycled An io_async_cmd carries an iovec array in ->vec.iovec, allocated when the vec has to grow and kept across recycling through ctx->cmd_cache. On two paths nothing frees it and io_clean_op()'s kfree(req->async_data) drops the io_async_cmd without it. io_req_uring_cleanup() clears the async data flags only when io_alloc_cache_put() succeeds, and the cache holds IO_ALLOC_CACHE_MAX == 128 entries, so once it is full the put fails and the vec is left behind. An NVMe passthrough workload gets there without doing anything unusual: nvme_uring_cmd_io() returns -EIOCBQUEUED, so the io_async_cmd stays attached for the lifetime of the command and the live object count tracks the queue depth. Above 128 the puts start failing. ->cleanup is the last chance to free an inherited vec, since io_req_uring_cleanup() returns early for an io-wq issued command and is not called at all for one completed without ever being issued. But io_clean_op() calls ->cleanup only if REQ_F_NEED_CLEANUP is set, and for uring_cmd that happens only where the vec has to grow, so a command reusing a large enough cached vec never sets it. io_rw_alloc_async() and io_msg_alloc_async() flag an inherited vec for exactly this reason; io_uring_cmd_prep() does not. Flag an inherited vec in io_uring_cmd_prep(), and free the vec when the cache put fails, as io_req_rw_cleanup() does. The leak is invisible under KASAN, where io_alloc_cache_vec_kasan() frees the vec unconditionally.