um: virtio_uml: fix heap overflow in vhost_user_get_config()
PATCH 1/1 um: virtio_uml: fix heap overflow in vhost_user_get_config()
vhost_user_get_config() sizes its reply buffer from header + payload:
size_t payload_size = sizeof(msg->payload.config) + cfg_size; size_t msg_size = sizeof(msg->header) + payload_size; ... msg = kzalloc(msg_size, GFP_KERNEL);
but then receives the response with msg_size as the payload cap:
rc = vhost_user_recv_resp(vu_dev, msg, msg_size);
vhost_user_recv() reads the header, then full_read()s header.size bytes into &msg->payload after checking only "size > max_payload_size". The payload area is msg_size - sizeof(msg->header) == payload_size bytes, so passing msg_size as the cap lets a peer set header.size up to msg_size and write sizeof(struct vhost_user_msg_header) (12) bytes past the end of the kzalloc(msg_size) buffer -- a slab out-of-bounds write of peer-controlled content.
Pass payload_size, which is the size the payload area was allocated for.
A malicious or compromised vhost-user backend triggers this during device probe (vu_get -> vhost_user_get_config) with no guest action, which matters in the confidential-computing model where the guest does not trust the device backend.
---
Reproduced on a UML KASAN build (ARCH=um, CONFIG_KASAN=y) off this base. A stub vhost-user backend that answers GET_CONFIG with header.size set to the full msg_size makes vhost_user_recv() full_read() 12 bytes past the kzalloc'd reply buffer; KASAN reports a slab-out-of-bounds write in vhost_user_get_config(). With this patch the oversized reply is rejected (-EPROTO) and KASAN is clean. Benign control: a correctly-sized GET_CONFIG reply succeeds on both stock and patched. Before/after logs available on request.
arch/um/drivers/virtio_uml.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/drivers/virtio_uml.c +1 -1
@@ -568,7 +568,7 @@ static void vhost_user_get_config(struct virtio_uml_device *vu_dev, goto free; } - rc =vhost_user_recv_resp (vu_dev, msg, msg_size); + rc =vhost_user_recv_resp (vu_dev, msg, payload_size);if (rc) { vu_err(vu_dev, "receiving VHOST_USER_GET_CONFIG response failed: %d\n",
base-commit: ef0c9f75a19532d7675384708fc8621e10850104
Signature · 1 line
2.53.0
Quoted 41 lines · Michael Bommarito
vhost_user_get_config()sizes its reply buffer from header + payload:size_t payload_size = sizeof(msg->payload.config) + cfg_size; size_t msg_size = sizeof(msg->header) + payload_size; ... msg = kzalloc(msg_size, GFP_KERNEL);but then receives the response with
msg_sizeas the payload cap:rc = vhost_user_recv_resp(vu_dev, msg, msg_size);
vhost_user_recv()reads the header, then full_read()s header.size bytes into&msg->payloadafter checking only "size >max_payload_size". The payload area ismsg_size-sizeof(msg->header)==payload_sizebytes, so passingmsg_sizeas the cap lets a peer set header.size up tomsg_sizeand writesizeof(struct vhost_user_msg_header)(12) bytes past the end of thekzalloc(msg_size)buffer -- a slab out-of-bounds write of peer-controlled content.Pass
payload_size, which is the size the payload area was allocated for.A malicious or compromised vhost-user backend triggers this during device probe (
vu_get->vhost_user_get_config) with no guest action, which matters in the confidential-computing model where the guest does not trust the device backend.Fixes 5d38f324993f ("um: drivers: Add virtio vhost-user driver")Assisted-by Claude:claude-opus-4-8Signed-off-by Michael Bommarito <[email protected]>---
Reproduced on a UML KASAN build (ARCH=um,CONFIG_KASAN=y) off this base. A stub vhost-user backend that answersGET_CONFIGwith header.size set to the fullmsg_sizemakesvhost_user_recv()full_read()12 bytes past the kzalloc'd reply buffer; KASAN reports a slab-out-of-bounds write invhost_user_get_config(). With this patch the oversized reply is rejected (-EPROTO) and KASAN is clean. Benign control: a correctly-sizedGET_CONFIGreply succeeds on both stock and patched. Before/after logs available on request.
Quoted 1 line
arch/um/drivers/virtio_uml.c | 2 +-
Signature · 2 lines
Thanks, //richard