All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
	Olivia Mackall <olivia@selenic.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Amos Kong <akong@redhat.com>,
	virtualization@lists.linux.dev, linux-crypto@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwrng: virtio - prevent use-after-free after a failed restore
Date: Sun, 18 Oct 2026 22:37:22 +0200	[thread overview]
Message-ID: <atUuAsxE42s8NGEY@kernel.org> (raw)
In-Reply-To: <CANc+2y7ruqmfO+D_nfdc9rnBE0uSSnZR9UJY2Dvc5Nez9U-61Q@mail.gmail.com>

Hi PrasannaKumar,

On Sun, Oct 18, 2026 at 10:30:08PM +0530, PrasannaKumar Muralidharan wrote:
> Hi Thorsten,
> 
> On Fri, 16 Oct 2026 at 16:16, Thorsten Blum <blum@kernel.org> wrote:
> >
> > remove_common() frees the driver data during freeze, but does not clear
> > vdev->priv, which points to freed memory. If probe_common() then fails
> > during restore, a later remove or freeze can dereference the dangling
> > pointer.
> >
> > Clear vdev->priv on the probe_common() error cleanup path and before
> > freeing the driver data in remove_common(). Also reset the device and
> > return early from remove_common() if vdev->priv is already NULL for a
> > safe teardown after a failed restore.
> >
> > Fixes: 08e53fbdb85c ("virtio-rng: support multiple virtio-rng devices")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Thorsten Blum <blum@kernel.org>
> > ---
> >  drivers/char/hw_random/virtio-rng.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
> > index 5e83ffa105e4..a9ff520975a7 100644
> > --- a/drivers/char/hw_random/virtio-rng.c
> > +++ b/drivers/char/hw_random/virtio-rng.c
> > @@ -190,6 +190,7 @@ static int probe_common(struct virtio_device *vdev)
> >  err_find:
> >         ida_free(&rng_index_ida, index);
> >  err_ida:
> > +       vdev->priv = NULL;
> >         kfree(vi);
> >         return err;
> >  }
> > @@ -198,6 +199,11 @@ static void remove_common(struct virtio_device *vdev)
> >  {
> >         struct virtrng_info *vi = vdev->priv;
> >
> > +       if (!vi) {
> > +               virtio_reset_device(vdev);
> > +               return;
> > +       }
> > +
> 
> The virtio_reset_device() is always called before setting vdev->priv
> to NULL. So the virtio device is already quiesced, no need to do early
> return. Isn't it?

The check is still needed.

For example, during hibernation or suspend, .freeze (virtrng_freeze() ->
remove_common()) frees vi and sets vdev->priv to NULL.

On resume, .restore (virtrng_restore()) calls probe_common(), which
could fail and leave vdev->priv NULL. A later .freeze or .remove calls
remove_common() again, which would dereference NULL without the check.

Best regards,
Thorsten

  reply	other threads:[~2026-10-18 20:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 10:36 [PATCH] hwrng: virtio - prevent use-after-free after a failed restore Thorsten Blum
2026-10-16 10:47 ` sashiko-bot
2026-10-18 17:00 ` PrasannaKumar Muralidharan
2026-10-18 20:37   ` Thorsten Blum [this message]
2026-10-19 13:00     ` PrasannaKumar Muralidharan

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=atUuAsxE42s8NGEY@kernel.org \
    --to=blum@kernel.org \
    --cc=akong@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=olivia@selenic.com \
    --cc=prasannatsmkumar@gmail.com \
    --cc=rusty@rustcorp.com.au \
    --cc=virtualization@lists.linux.dev \
    /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.