FAILED: patch "[PATCH] hwrng: virtio - prevent use-after-free after a failed restore" failed to apply to 5.10-stable tree
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74 Mon Sep 17 00:00:00 2001
From: Thorsten Blum <[email protected]>
Date: Fri, 16 Oct 2026 12:36:40 +0200
Subject: [PATCH] hwrng: virtio - prevent use-after-free after a failed restore
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.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
@@ -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 ; + } + vi->hwrng_removed = true; vi->data_avail =0 ; vi->data_idx =0 ;
@@ -207,6 +213,7 @@ static void remove_common(struct virtio_device *vdev)virtio_reset_device (vdev); vdev->config->del_vqs (vdev);ida_free (&rng_index_ida, vi->index); + vdev->priv =NULL ;kfree (vi); }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 hwrng: virtio - prevent use-after-free after a failed restore
From: Thorsten Blum <[email protected]>
[ Upstream commit 0f7bf47f5a0cc26320aa4b14f4504d03a07f4b74 ]
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.
Message-ID: <[email protected]>
--- drivers/char/hw_random/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/hw_random/virtio-rng.c +7 -0
@@ -186,6 +186,7 @@ static int probe_common(struct virtio_device *vdev) err_find:ida_simple_remove (&rng_index_ida, index); err_ida: + vdev->priv =NULL ;kfree (vi);return err; }
@@ -194,6 +195,11 @@ static void remove_common(struct virtio_device *vdev) {struct virtrng_info *vi = vdev->priv; +if (!vi) { + vdev->config->reset (vdev); +return ; + } + vi->hwrng_removed = true; vi->data_avail =0 ; vi->data_idx =0 ;
@@ -203,6 +209,7 @@ static void remove_common(struct virtio_device *vdev)hwrng_unregister (&vi->hwrng); vdev->config->del_vqs (vdev);ida_simple_remove (&rng_index_ida, vi->index); + vdev->priv =NULL ;kfree (vi); }
Signature · 1 line
2.53.0