All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yishai Hadas <yishaih@nvidia.com>
To: Qican Ma <goonsomeway@gmail.com>, <alex@shazbot.org>
Cc: <jgg@ziepe.ca>, <skolothumtho@nvidia.com>, <kevin.tian@intel.com>,
	<kvm@vger.kernel.org>
Subject: Re: [PATCH v3] vfio/mlx5: Read the resume buffer pointers under migf->lock
Date: Tue, 24 Nov 2026 14:17:08 +0200	[thread overview]
Message-ID: <a92b82de-bf82-4bc9-9403-6ec23fdcb5ca@nvidia.com> (raw)
In-Reply-To: <179551955962.71139.3396358892015584482@gmail.com>

On 24/11/2026 13:25, Qican Ma wrote:
> mlx5vf_resume_write() reads migf->buf[0] and migf->buf_header[0]
> before taking migf->lock. The migration file is opened with
> stream_open(), so concurrent writes are not serialized by f_pos_lock.
> A racing writer may free and reallocate these buffers in PREP_IMAGE or
> PREP_HEADER_DATA, leaving the other writer with a freed pointer.
> 
> Read the buffer pointers under migf->lock, after the
> MLX5_MIGF_STATE_ERROR check.
> 
> While at it, move the f_pos check under the lock as well, as f_pos is
> protected by it. This is not a functional change, as f_pos is never
> negative and can't get close to an overflow.
> 
> Found with an LLM-assisted code review tool and verified by inspection on
> v7.4-rc4 (b6a9fa34ce4). Build-tested only due to lack of mlx5 VF
> live-migration hardware.
> 
> Fixes: 34e2f27143d1 ("vfio/mlx5: Introduce multiple loads")
> Cc: stable@vger.kernel.org
> Signed-off-by: Qican Ma <goonsomeway@gmail.com>

Reviewed-by: Yishai Hadas <yishaih@nvidia.com>

Yishai

> ---
> v3: correct Fixes: tag to 34e2f27143d1 and rework the commit message per
>      Yishai's review; no code changes.
> v2: resend via direct SMTP without line-wrapping corruption in the diff.
> 
>   drivers/vfio/pci/mlx5/main.c | 17 +++++++++++------
>   1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
> index 18a6d224b1f..ebcc22bcb75 100644
> --- a/drivers/vfio/pci/mlx5/main.c
> +++ b/drivers/vfio/pci/mlx5/main.c
> @@ -884,8 +884,8 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
>   				   size_t len, loff_t *pos)
>   {
>   	struct mlx5_vf_migration_file *migf = filp->private_data;
> -	struct mlx5_vhca_data_buffer *vhca_buf = migf->buf[0];
> -	struct mlx5_vhca_data_buffer *vhca_buf_header = migf->buf_header[0];
> +	struct mlx5_vhca_data_buffer *vhca_buf;
> +	struct mlx5_vhca_data_buffer *vhca_buf_header;
>   	loff_t requested_length;
>   	bool has_work = false;
>   	ssize_t done = 0;
> @@ -895,10 +895,6 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
>   		return -ESPIPE;
>   	pos = &filp->f_pos;
>   
> -	if (*pos < 0 ||
> -	    check_add_overflow((loff_t)len, *pos, &requested_length))
> -		return -EINVAL;
> -
>   	mutex_lock(&migf->mvdev->state_mutex);
>   	mutex_lock(&migf->lock);
>   	if (migf->state == MLX5_MIGF_STATE_ERROR) {
> @@ -906,6 +902,15 @@ static ssize_t mlx5vf_resume_write(struct file *filp, const char __user *buf,
>   		goto out_unlock;
>   	}
>   
> +	if (*pos < 0 ||
> +	    check_add_overflow((loff_t)len, *pos, &requested_length)) {
> +		done = -EINVAL;
> +		goto out_unlock;
> +	}
> +
> +	vhca_buf = migf->buf[0];
> +	vhca_buf_header = migf->buf_header[0];
> +
>   	while (len || has_work) {
>   		has_work = false;
>   		switch (migf->load_state) {


  reply	other threads:[~2026-11-24 12:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:25 [PATCH v3] vfio/mlx5: Read the resume buffer pointers under migf->lock Qican Ma
2026-11-24 12:17 ` Yishai Hadas [this message]
2026-11-26  5:49 ` Alex Williamson

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=a92b82de-bf82-4bc9-9403-6ec23fdcb5ca@nvidia.com \
    --to=yishaih@nvidia.com \
    --cc=alex@shazbot.org \
    --cc=goonsomeway@gmail.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=skolothumtho@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.