]> git.baikalelectronics.ru Git - kernel.git/commitdiff
9p/xen: check logical size for buffer size
authorDominique Martinet <asmadeus@codewreck.org>
Fri, 18 Nov 2022 13:44:41 +0000 (22:44 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Dec 2022 10:30:41 +0000 (11:30 +0100)
[ Upstream commit 391c18cf776eb4569ecda1f7794f360fe0a45a26 ]

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: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Link: https://lkml.kernel.org/r/20221118135542.63400-1-asmadeus@codewreck.org
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/9p/trans_xen.c

index 2779ec1053a022f0785c84c907dd9dac87c7eaf1..f043938ae782d0bbdff7218893b1793b0f13a1fe 100644 (file)
@@ -230,6 +230,14 @@ static void p9_xen_response(struct work_struct *work)
                        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));
                req->rc.offset = 0;
 
@@ -239,6 +247,7 @@ static void p9_xen_response(struct work_struct *work)
                                     masked_prod, &masked_cons,
                                     XEN_9PFS_RING_SIZE);
 
+recv_error:
                virt_mb();
                cons += h.size;
                ring->intf->in_cons = cons;