patch 'vhost: fix possible FD leaks' has been queued to stable release 22.11.2

Xueming Li xuemingl at nvidia.com
Mon Feb 27 07:59:53 CET 2023


Hi,

FYI, your patch has been queued to stable release 22.11.2

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 03/01/23. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging

This queued commit can be viewed at:
https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=eab1940f972ccb8b4abc045254693e268b5a0fcf

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From eab1940f972ccb8b4abc045254693e268b5a0fcf Mon Sep 17 00:00:00 2001
From: Maxime Coquelin <maxime.coquelin at redhat.com>
Date: Tue, 7 Feb 2023 17:22:39 +0100
Subject: [PATCH] vhost: fix possible FD leaks
Cc: Xueming Li <xuemingl at nvidia.com>

[ upstream commit 585283f9a703fcd994dbf9aca07dea9445319862 ]

On failure, read_vhost_message() only closed the message
FDs if the header size was unexpected, but there are other
cases where it is required. For example in the case the
payload size read from the header is greater than the
expected maximum payload size.

This patch fixes this by closing all messages FDs in all
error cases. It also improve error logging by displaying
the request name when failure happens if possible.

Fixes: bf472259dde6 ("vhost: fix possible denial of service by leaking FDs")

Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
Signed-off-by: David Marchand <david.marchand at redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>
---
 lib/vhost/vhost_user.c | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 76058c3ee5..8df66e68b3 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2817,29 +2817,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct  vhu_msg_context *

 	ret = read_fd_message(dev->ifname, sockfd, (char *)&ctx->msg, VHOST_USER_HDR_SIZE,
 		ctx->fds, VHOST_MEMORY_MAX_NREGIONS, &ctx->fd_num);
-	if (ret <= 0) {
-		return ret;
-	} else if (ret != VHOST_USER_HDR_SIZE) {
+	if (ret <= 0)
+		goto out;
+
+	if (ret != VHOST_USER_HDR_SIZE) {
 		VHOST_LOG_CONFIG(dev->ifname, ERR, "Unexpected header size read\n");
-		close_msg_fds(ctx);
-		return -1;
+		ret = -1;
+		goto out;
 	}

 	if (ctx->msg.size) {
 		if (ctx->msg.size > sizeof(ctx->msg.payload)) {
 			VHOST_LOG_CONFIG(dev->ifname, ERR, "invalid msg size: %d\n",
 				ctx->msg.size);
-			return -1;
+			ret = -1;
+			goto out;
 		}
 		ret = read(sockfd, &ctx->msg.payload, ctx->msg.size);
 		if (ret <= 0)
-			return ret;
+			goto out;
 		if (ret != (int)ctx->msg.size) {
 			VHOST_LOG_CONFIG(dev->ifname, ERR, "read control message failed\n");
-			return -1;
+			ret = -1;
+			goto out;
 		}
 	}

+out:
+	if (ret <= 0)
+		close_msg_fds(ctx);
+
 	return ret;
 }

@@ -2987,13 +2994,10 @@ vhost_user_msg_handler(int vid, int fd)
 		}
 	}

+	ctx.msg.request.master = VHOST_USER_NONE;
 	ret = read_vhost_message(dev, fd, &ctx);
-	if (ret <= 0) {
-		if (ret < 0)
-			VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost read message failed\n");
-		else
-			VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n");
-
+	if (ret == 0) {
+		VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n");
 		return -1;
 	}

@@ -3003,6 +3007,14 @@ vhost_user_msg_handler(int vid, int fd)
 	else
 		msg_handler = NULL;

+	if (ret < 0) {
+		VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost read message %s%s%sfailed\n",
+				msg_handler != NULL ? "for " : "",
+				msg_handler != NULL ? msg_handler->description : "",
+				msg_handler != NULL ? " " : "");
+		return -1;
+	}
+
 	if (msg_handler != NULL && msg_handler->description != NULL) {
 		if (request != VHOST_USER_IOTLB_MSG)
 			VHOST_LOG_CONFIG(dev->ifname, INFO,
--
2.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-02-27 14:08:43.654922800 +0800
+++ 0086-vhost-fix-possible-FD-leaks.patch	2023-02-27 14:08:40.809237000 +0800
@@ -1 +1 @@
-From 585283f9a703fcd994dbf9aca07dea9445319862 Mon Sep 17 00:00:00 2001
+From eab1940f972ccb8b4abc045254693e268b5a0fcf Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 585283f9a703fcd994dbf9aca07dea9445319862 ]
@@ -17 +19,0 @@
-Cc: stable at dpdk.org
@@ -27 +29 @@
-index b4236820a2..d702d082dd 100644
+index 76058c3ee5..8df66e68b3 100644
@@ -30 +32 @@
-@@ -2831,29 +2831,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct  vhu_msg_context *
+@@ -2817,29 +2817,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct  vhu_msg_context *
@@ -75 +77 @@
-@@ -3031,13 +3038,10 @@ vhost_user_msg_handler(int vid, int fd)
+@@ -2987,13 +2994,10 @@ vhost_user_msg_handler(int vid, int fd)
@@ -92 +94 @@
-@@ -3047,6 +3051,14 @@ vhost_user_msg_handler(int vid, int fd)
+@@ -3003,6 +3007,14 @@ vhost_user_msg_handler(int vid, int fd)


More information about the stable mailing list