From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 155E428ED for ; Mon, 12 Dec 2022 13:20:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FCCBC433D2; Mon, 12 Dec 2022 13:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670851238; bh=0xXbsxiMPlFyZEbS3ZNMvu5qgWqcrJYiqoe5lSqqVj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REzSAaaD9EsoC27MCLGOgIO4pJSp1t35RPLV4XITl0nzcCoKNbl4W0mjo/LRdNqrP Ub5MKlh1f4Q7yPhVMtcbR1dxFXCgxD/Z6Qwvx7M/YqeFWoLUdUpz3qbIoi+ZGd1Wbb rrnuyKwyrgwDhMIVk01BhVnwOetjkL01McWhqCmA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Stefano Stabellini , Christian Schoenebeck , Dominique Martinet , Sasha Levin Subject: [PATCH 5.4 15/67] 9p/xen: check logical size for buffer size Date: Mon, 12 Dec 2022 14:16:50 +0100 Message-Id: <20221212130918.350790650@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212130917.599345531@linuxfoundation.org> References: <20221212130917.599345531@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Dominique Martinet [ 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 Reviewed-by: Christian Schoenebeck Link: https://lkml.kernel.org/r/20221118135542.63400-1-asmadeus@codewreck.org Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin --- net/9p/trans_xen.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c index 2779ec1053a0..f043938ae782 100644 --- a/net/9p/trans_xen.c +++ b/net/9p/trans_xen.c @@ -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; -- 2.35.1