Skip to content

lib: free pagelist on error in iov_iter_extract_pages()#1359

Open
vfsci-bot[bot] wants to merge 1 commit intovfs.base.cifrom
pw/1091576/vfs.base.ci
Open

lib: free pagelist on error in iov_iter_extract_pages()#1359
vfsci-bot[bot] wants to merge 1 commit intovfs.base.cifrom
pw/1091576/vfs.base.ci

Conversation

@vfsci-bot
Copy link
Copy Markdown

@vfsci-bot vfsci-bot Bot commented May 8, 2026

Series: https://patchwork.kernel.org/project/linux-fsdevel/list/?series=1091576
Submitter: Dmitry Antipov
Version: 1
Patches: 1/1
Message-ID: <20260508111329.329943-1-dmantipov@yandex.ru>
Base: vfs.base.ci
Lore: https://lore.kernel.org/linux-fsdevel/20260508111329.329943-1-dmantipov@yandex.ru


Automated by ml2pr

Since 'iov_iter_extract_pages()' may allocate new pagelist if the passed
one isn't large enough, the worst-case scenario may be:

...
struct page *stack_pages[SMALL];
struct page **pages = stack_pages;
...
if (iov_iter_extract_pages(i..., &pages, ...) <= 0) {
        /* Even in case of error, new pagelist may be allocated */
        if (pages != stack_pages)
                kvfree(pages);                                  [1]
        /* The rest of error handling and return */
}
/* Regular flow */
...
if (pages != stack_pages)
        kvfree(pages);
...
return 0;

If you're unlucky so SMALL amount of pages wasn't enough and new
pagelist was allocated, missing [1] causes the memory leak similar
to one I've recently observed and fixed for 6.12 in [2]. So adjust
'iov_iter_extract_pages()' to make such a cleanup itself rather than
rely on caller's handling on error paths, thus making [1] not needed.

[2] https://lore.kernel.org/stable/20260505094529.406783-1-dmantipov@yandex.ru/T/#u

Suggested-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant