From: Alex Williamson <alex@shazbot.org>
To: Hungyu Lin <dennylin0707@gmail.com>
Cc: yishaih@nvidia.com, jgg@ziepe.ca, skolothumtho@nvidia.com,
kevin.tian@intel.com, leon@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, alex@shazbot.org
Subject: Re: [PATCH] vfio/mlx5: Fix an unwind issue in mlx5vf_add_pages()
Date: Wed, 25 Nov 2026 22:49:07 -0700 [thread overview]
Message-ID: <20261125224907.13d1fb8d@shazbot.org> (raw)
In-Reply-To: <20261116030131.15346-1-dennylin0707@gmail.com>
On Mon, 16 Nov 2026 03:01:30 +0000
Hungyu Lin <dennylin0707@gmail.com> wrote:
> mlx5vf_add_pages() gets a pointer to the page list of its caller. If
> alloc_pages_bulk() fails after some of the pages were allocated, the
> unwind flow frees them with
>
> __free_page(*page_list[i]);
>
> The index is applied to page_list before it is dereferenced, so only
> the first page is freed. For the other pages the code reads the memory
> that follows the page list pointer of the caller and dereferences it.
> In both callers this is a dma_iova_state that is still zeroed, which
> ends in a NULL pointer dereference, and the pages are leaked.
>
> The pages are allocated with GFP_KERNEL_ACCOUNT, so the allocation can
> fail, for example when the memory cgroup of the task is out of memory.
>
> Dereference page_list before indexing it.
>
> Fixes: 089803c40193 ("vfio/mlx5: Enable the DMA link API")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
> drivers/vfio/pci/mlx5/cmd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vfio/pci/mlx5/cmd.c b/drivers/vfio/pci/mlx5/cmd.c
> index 04180035a7fe..8e8514f2660f 100644
> --- a/drivers/vfio/pci/mlx5/cmd.c
> +++ b/drivers/vfio/pci/mlx5/cmd.c
> @@ -518,7 +518,7 @@ static int mlx5vf_add_pages(struct page ***page_list, unsigned int npages)
>
> err:
> for (i = 0; i < done; i++)
> - __free_page(*page_list[i]);
> + __free_page((*page_list)[i]);
>
> kvfree(*page_list);
> *page_list = NULL;
Applied to vfio next branch for v7.5. Thanks,
Alex
prev parent reply other threads:[~2026-11-26 5:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 3:01 [PATCH] vfio/mlx5: Fix an unwind issue in mlx5vf_add_pages() Hungyu Lin
2026-11-23 9:55 ` Yishai Hadas
2026-11-26 5:49 ` Alex Williamson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125224907.13d1fb8d@shazbot.org \
--to=alex@shazbot.org \
--cc=dennylin0707@gmail.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=skolothumtho@nvidia.com \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.