hw/virtio-rng: Fix host use-after-free (CVE-2026-50624)
PATCH 1/1 hw/virtio-rng: Fix host use-after-free (CVE-2026-50624)
Fix a heap-use-after-free in the virtio-rng frontend when a delayed rng-random backend completion arrives after the virtio-rng device has been hot-unplugged.
Fixes: CVE-2026-50624
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3917
--- backends/rng.c | 16 ++++++++++++++++ hw/virtio/virtio-rng.c | 2 ++ include/system/rng.h | 14 ++++++++++++++ 3 files changed, 32 insertions(+)
backends/rng.c +16 -0
@@ -68,6 +68,22 @@ static void rng_backend_free_request(RngRequest *req)g_free (req); } +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque) +{ +RngRequest *req, *next; + + QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) { +if (req->receive_entropy != receive_entropy || + req->opaque != opaque) { +continue ; + } +QSIMPLEQ_REMOVE (&s->requests, req, RngRequest, next); +rng_backend_free_request (req); + } +} +static void rng_backend_free_requests (RngBackend *s) {RngRequest *req, *next;
hw/virtio/virtio-rng.c +2 -0
@@ -234,6 +234,8 @@ static void virtio_rng_device_unrealize(DeviceState *dev)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIORNG *vrng =VIRTIO_RNG (dev); +rng_backend_cancel_request_entropy (vrng->rng, chr_read, vrng); +qemu_del_vm_change_state_handler (vrng->vmstate);timer_free (vrng->rate_limit_timer);virtio_del_queue (vdev,0 );
include/system/rng.h +14 -0
@@ -86,4 +86,18 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,* deleted. */ void rng_backend_finalize_request (RngBackend *s,RngRequest *req); + +/** +* rng_backend_cancel_request_entropy: +* @s: the backend that created the request +* @receive_entropy: the function invoked when entropy is available +* @opaque: data passed to @receive_entropy +* +* This function is used by the front-end to cancel all requests to a +* given backend. Requests to cancel are identified by the receive_entropy +* function and the data passed to the function. +*/ +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque);#endif
Signature · 1 line
2.54.0
Ping
Quoted 77 lines · Laurent Vivier
Fix a heap-use-after-free in the virtio-rng frontend when a delayed rng-random backend completion arrives after the virtio-rng device has been hot-unplugged.
Fixes: CVE-2026-50624
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3917Reported-by Jia Jia <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- backends/rng.c | 16 ++++++++++++++++ hw/virtio/virtio-rng.c | 2 ++ include/system/rng.h | 14 ++++++++++++++ 3 files changed, 32 insertions(+)backends/rng.c +16
-0@@ -68,6 +68,22 @@ static void rng_backend_free_request(RngRequest *req)g_free (req); } +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque) +{ +RngRequest *req, *next; + + QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) { +if (req->receive_entropy != receive_entropy || + req->opaque != opaque) { +continue ; + } +QSIMPLEQ_REMOVE (&s->requests, req, RngRequest, next); +rng_backend_free_request (req); + } +} +static void rng_backend_free_requests (RngBackend *s) {RngRequest *req, *next;hw/virtio/virtio-rng.c +2
-0@@ -234,6 +234,8 @@ static void virtio_rng_device_unrealize(DeviceState *dev)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIORNG *vrng =VIRTIO_RNG (dev); +rng_backend_cancel_request_entropy (vrng->rng, chr_read, vrng); +qemu_del_vm_change_state_handler (vrng->vmstate);timer_free (vrng->rate_limit_timer);virtio_del_queue (vdev,0 );include/system/rng.h +14
-0@@ -86,4 +86,18 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,* deleted. */ void rng_backend_finalize_request (RngBackend *s,RngRequest *req); + +/** +* rng_backend_cancel_request_entropy: +* @s: the backend that created the request +* @receive_entropy: the function invoked when entropy is available +* @opaque: data passed to @receive_entropy +* +* This function is used by the front-end to cancel all requests to a +* given backend. Requests to cancel are identified by the receive_entropy +* function and the data passed to the function. +*/ +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque);#endif
Quoted 66 lines · Laurent Vivier
Fix a heap-use-after-free in the virtio-rng frontend when a delayed rng-random backend completion arrives after the virtio-rng device has been hot-unplugged.
Fixes: CVE-2026-50624
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3917Reported-by Jia Jia <[email protected]>Signed-off-by Laurent Vivier <[email protected]>--- backends/rng.c | 16 ++++++++++++++++ hw/virtio/virtio-rng.c | 2 ++ include/system/rng.h | 14 ++++++++++++++ 3 files changed, 32 insertions(+)backends/rng.c +16
-0@@ -68,6 +68,22 @@ static void rng_backend_free_request(RngRequest *req)g_free (req); } +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque) +{ +RngRequest *req, *next; + + QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) { +if (req->receive_entropy != receive_entropy || + req->opaque != opaque) { +continue ; + } +QSIMPLEQ_REMOVE (&s->requests, req, RngRequest, next); +rng_backend_free_request (req); + } +} +static void rng_backend_free_requests (RngBackend *s) {RngRequest *req, *next;hw/virtio/virtio-rng.c +2
-0@@ -234,6 +234,8 @@ static void virtio_rng_device_unrealize(DeviceState *dev)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIORNG *vrng =VIRTIO_RNG (dev); +rng_backend_cancel_request_entropy (vrng->rng, chr_read, vrng); +qemu_del_vm_change_state_handler (vrng->vmstate);timer_free (vrng->rate_limit_timer);virtio_del_queue (vdev,0 );include/system/rng.h +4
-0@@ -86,4 +86,18 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,* deleted. */ void rng_backend_finalize_request (RngBackend *s,RngRequest *req); + +/** +* rng_backend_cancel_request_entropy: +* @s: the backend that created the request
include/system/rng.h void rng_backend_request_entropy(RngBackend *s, size_t size, · line 102
Quoted 10 lines
include/system/rng.h +10
-0+* @receive_entropy: the function invoked when entropy is available +* @opaque: data passed to @receive_entropy +* +* This function is used by the front-end to cancel all requests to a +* given backend. Requests to cancel are identified by the receive_entropy +* function and the data passed to the function. +*/ +void rng_backend_cancel_request_entropy (RngBackend *s, +EntropyReceiveFunc *receive_entropy, +void *opaque);
I'd simply name it rng_backend_cancel_requests(), and make the argument const:
void rng_backend_cancel_requests(RngBackend *s,
const EntropyReceiveFunc*receive_entropy,
const void *opaque);
I suppose we should implement spapr_rng_unrealize() calling this helper.
For this patch (preferably renamed):
Quoted 78 lines · Philippe Mathieu-Daudé
Quoted 64 lines · Laurent Vivier
Fix a heap-use-after-free in the virtio-rng frontend when a delayed rng-random backend completion arrives after the virtio-rng device has been hot-unplugged.
Fixes: CVE-2026-50624
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3917Reported-by Jia Jia <[email protected]>Signed-off-by Laurent Vivier <[email protected]>---
backends/rng.c | 16 ++++++++++++++++
hw/virtio/virtio-rng.c| 2 ++
include/system/rng.h | 14 ++++++++++++++3 files changed, 32 insertions(+)backends/rng.c +16
-0@@ -68,6 +68,22 @@ static void rng_backend_free_request(RngRequest *req) g_free(req); } +void rng_backend_cancel_request_entropy (RngBackend *s, + EntropyReceiveFunc *receive_entropy, + void *opaque) +{ + RngRequest *req, *next; + + QSIMPLEQ_FOREACH_SAFE(req, &s->requests, next, next) { + if (req->receive_entropy != receive_entropy || + req->opaque != opaque) { + continue; + } + QSIMPLEQ_REMOVE(&s->requests, req, RngRequest, next); + rng_backend_free_request(req); + } +} + static void rng_backend_free_requests(RngBackend *s) { RngRequest *req, *next;hw/virtio/virtio-rng.c +2
-0@@ -234,6 +234,8 @@ static void virtio_rng_device_unrealize(DeviceState *dev) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIORNG *vrng = VIRTIO_RNG(dev); + rng_backend_cancel_request_entropy(vrng->rng, chr_read, vrng); + qemu_del_vm_change_state_handler(vrng->vmstate); timer_free(vrng->rate_limit_timer); virtio_del_queue(vdev, 0);include/system/rng.h +4
-0@@ -86,4 +86,18 @@ void rng_backend_request_entropy(RngBackend *s, size_t size,* deleted. */ void rng_backend_finalize_request(RngBackend *s, RngRequest *req); + +/** +* rng_backend_cancel_request_entropy: +* @s: the backend that created the request include/system/rng.h void rng_backend_request_entropy(RngBackend *s, size_t size, · line 102
Quoted 10 lines
include/system/rng.h +10
-0+* @receive_entropy: the function invoked when entropy is available +* @opaque: data passed to @receive_entropy +* +* This function is used by the front-end to cancel all requests to a +* given backend. Requests to cancel are identified by the receive_entropy +* function and the data passed to the function. +*/ +void rng_backend_cancel_request_entropy (RngBackend *s, + EntropyReceiveFunc *receive_entropy, + void *opaque);I'd simply name it
rng_backend_cancel_requests(), and make the argument const:
Quoted 3 lines
void rng_backend_cancel_requests(RngBackend *s,
const EntropyReceiveFunc*receive_entropy, const void *opaque);
I agree
Quoted 2 lines
I suppose we should implement
spapr_rng_unrealize()calling this helper.
I don't think this is needed (at least for the CVE case) as rng_backend_request_entropy() here is synchronous and spapr_rng is not hotpluggable.
Quoted 4 lines
For this patch (preferably renamed):
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
Laurent