Commit 391c18cf authored by Dominique Martinet's avatar Dominique Martinet

9p/xen: check logical size for buffer size

trans_xen did not check the data fits into the buffer before copying
from the xen ring, but we probably should.
Add a check that just skips the request and return an error to
userspace if it did not fit
Tested-by: default avatarStefano Stabellini <sstabellini@kernel.org>
Reviewed-by: default avatarChristian Schoenebeck <linux_oss@crudebyte.com>
Link: https://lkml.kernel.org/r/20221118135542.63400-1-asmadeus@codewreck.orgSigned-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
parent 6854fadb
...@@ -208,6 +208,14 @@ static void p9_xen_response(struct work_struct *work) ...@@ -208,6 +208,14 @@ static void p9_xen_response(struct work_struct *work)
continue; continue;
} }
if (h.size > req->rc.capacity) {
dev_warn(&priv->dev->dev,
"requested packet size too big: %d for tag %d with capacity %zd\n",
h.size, h.tag, req->rc.capacity);
req->status = REQ_STATUS_ERROR;
goto recv_error;
}
memcpy(&req->rc, &h, sizeof(h)); memcpy(&req->rc, &h, sizeof(h));
req->rc.offset = 0; req->rc.offset = 0;
...@@ -217,6 +225,7 @@ static void p9_xen_response(struct work_struct *work) ...@@ -217,6 +225,7 @@ static void p9_xen_response(struct work_struct *work)
masked_prod, &masked_cons, masked_prod, &masked_cons,
XEN_9PFS_RING_SIZE(ring)); XEN_9PFS_RING_SIZE(ring));
recv_error:
virt_mb(); virt_mb();
cons += h.size; cons += h.size;
ring->intf->in_cons = cons; ring->intf->in_cons = cons;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment