From: "Michael S. Tsirkin" <mst@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: "Cong Zhang" <cong.zhang@oss.qualcomm.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Jens Axboe" <axboe@kernel.dk>,
linux-arm-msm@vger.kernel.org, virtualization@lists.linux.dev,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
pavan.kondeti@oss.qualcomm.com
Subject: Re: [PATCH] virtio_blk: NULL out vqs to avoid double free on failed resume
Date: Wed, 22 Oct 2025 03:01:05 -0400 [thread overview]
Message-ID: <20251022030050-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20251022014453-mutt-send-email-mst@kernel.org>
On Wed, Oct 22, 2025 at 01:45:38AM -0400, Michael S. Tsirkin wrote:
> On Wed, Oct 22, 2025 at 12:19:19PM +0800, Jason Wang wrote:
> > On Tue, Oct 21, 2025 at 8:58 PM Michael S. Tsirkin <mst@redhat.com> wrote:
> > >
> > > On Tue, Oct 21, 2025 at 07:07:56PM +0800, Cong Zhang wrote:
> > > > The vblk->vqs releases during freeze. If resume fails before vblk->vqs
> > > > is allocated, later freeze/remove may attempt to free vqs again.
> > > > Set vblk->vqs to NULL after freeing to avoid double free.
> > > >
> > > > Signed-off-by: Cong Zhang <cong.zhang@oss.qualcomm.com>
> > > > ---
> > > > The patch fixes a double free issue that occurs in virtio_blk during
> > > > freeze/resume.
> > > > The issue is caused by:
> > > > 1. During the first freeze, vblk->vqs is freed but pointer is not set to
> > > > NULL.
> > > > 2. Virtio block device fails before vblk->vqs is allocated during resume.
> > > > 3. During the next freeze, vblk->vqs gets freed again, causing the
> > > > double free crash.
> > >
> > > this part I don't get. if restore fails, how can freeze be called
> > > again?
> >
> > For example, could it be triggered by the user?
> >
> > Thanks
>
> I don't know - were you able to trigger it? how?
Sorry I mean the submitter of course.
>
> > >
> > > > ---
> > > > drivers/block/virtio_blk.c | 13 ++++++++++++-
> > > > 1 file changed, 12 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> > > > index f061420dfb10c40b21765b173fab7046aa447506..746795066d7f56a01c9a9c0344d24f9fa06841eb 100644
> > > > --- a/drivers/block/virtio_blk.c
> > > > +++ b/drivers/block/virtio_blk.c
> > > > @@ -1026,8 +1026,13 @@ static int init_vq(struct virtio_blk *vblk)
> > > > out:
> > > > kfree(vqs);
> > > > kfree(vqs_info);
> > > > - if (err)
> > > > + if (err) {
> > > > kfree(vblk->vqs);
> > > > + /*
> > > > + * Set to NULL to prevent freeing vqs again during freezing.
> > > > + */
> > > > + vblk->vqs = NULL;
> > > > + }
> > > > return err;
> > > > }
> > > >
> > >
> > > > @@ -1598,6 +1603,12 @@ static int virtblk_freeze_priv(struct virtio_device *vdev)
> > > >
> > > > vdev->config->del_vqs(vdev);
> > > > kfree(vblk->vqs);
> > > > + /*
> > > > + * Set to NULL to prevent freeing vqs again after a failed vqs
> > > > + * allocation during resume. Note that kfree() already handles NULL
> > > > + * pointers safely.
> > > > + */
> > > > + vblk->vqs = NULL;
> > > >
> > > > return 0;
> > > > }
> > > >
> > > > ---
> > > > base-commit: 8e2755d7779a95dd61d8997ebce33ff8b1efd3fb
> > > > change-id: 20250926-virtio_double_free-7ab880d82a17
> > > >
> > > > Best regards,
> > > > --
> > > > Cong Zhang <cong.zhang@oss.qualcomm.com>
> > >
next prev parent reply other threads:[~2025-10-22 7:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 11:07 [PATCH] virtio_blk: NULL out vqs to avoid double free on failed resume Cong Zhang
2025-10-21 12:57 ` Michael S. Tsirkin
2025-10-22 4:19 ` Jason Wang
2025-10-22 5:45 ` Michael S. Tsirkin
2025-10-22 7:01 ` Michael S. Tsirkin [this message]
2025-10-22 8:02 ` Cong Zhang
2025-11-05 8:56 ` Cong Zhang
2025-11-06 4:06 ` Jason Wang
2025-11-06 23:33 ` Jens Axboe
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=20251022030050-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=axboe@kernel.dk \
--cc=cong.zhang@oss.qualcomm.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavan.kondeti@oss.qualcomm.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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.