Skip to contentSkip to conversation

vhost: fix queue number check when setting inflight FD

PATCH In review David Marchand 2 participants 5 messages Mar 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vhost: fix queue number check when setting inflight FD

From: Chenbo Xia <[email protected]>

In function vhost_user_set_inflight_fd, queue number in inflight message is used to access virtqueue. However, queue number could be larger than VHOST_MAX_VRING and cause write OOB as this number will be used to write inflight info in virtqueue structure. This patch checks the queue number to avoid the issue and also make sure virtqueues are allocated before setting inflight information.

Fixes ad0a4ae491fe ("vhost: checkout resubmit inflight information")
---
 lib/vhost/vhost_user.c | 3 +++
 1 file changed, 3 insertions(+)
lib/vhost/vhost_user.c +3 -0
index 589b950458..1ec4357bee 100644
@@ -2883,6 +2883,9 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
 	case VHOST_USER_SET_VRING_ADDR:
 		vring_idx = ctx->msg.payload.addr.index;
 		break;
+	case VHOST_USER_SET_INFLIGHT_FD:
+		vring_idx = ctx->msg.payload.inflight.num_queues - 1;
+		break;
 	default:
 		return 0;
 	}
Signature · 1 line
2.23.0
#1 lore raw

PATCH 2/2 vhost: fix FD leak with inflight messages

Even if unlikely, a buggy vhost-user master might attach fds to inflight messages. Add checks like for other types of vhost-user messages.

Fixes d87f1a1cb7b6 ("vhost: support inflight info sharing")
---
 lib/vhost/vhost_user.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/vhost/vhost_user.c +6 -0
index 1ec4357bee..1d390677fa 100644
@@ -1602,6 +1602,9 @@ vhost_user_get_inflight_fd(struct virtio_net **pdev,
 	int numa_node = SOCKET_ID_ANY;
 	void *addr;
 
+	if (validate_msg_fds(dev, ctx, 0) != 0)
+		return RTE_VHOST_MSG_RESULT_ERR;
+
 	if (ctx->msg.size != sizeof(ctx->msg.payload.inflight)) {
 		VHOST_LOG_CONFIG(ERR, "(%s) invalid get_inflight_fd message size is %d\n",
 			dev->ifname, ctx->msg.size);
@@ -1699,6 +1702,9 @@ vhost_user_set_inflight_fd(struct virtio_net **pdev,
 	int fd, i;
 	int numa_node = SOCKET_ID_ANY;
 
+	if (validate_msg_fds(dev, ctx, 1) != 0)
+		return RTE_VHOST_MSG_RESULT_ERR;
+
 	fd = ctx->fds[0];
 	if (ctx->msg.size != sizeof(ctx->msg.payload.inflight) || fd < 0) {
 		VHOST_LOG_CONFIG(ERR, "(%s) invalid set_inflight_fd message size is %d,fd is %d\n",
Signature · 1 line
2.23.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] vhost: fix FD leak with inflight messages

Quoted 26 lines · David Marchand

Even if unlikely, a buggy vhost-user master might attach fds to inflight messages. Add checks like for other types of vhost-user messages.

Fixes d87f1a1cb7b6 ("vhost: support inflight info sharing")
---
  lib/vhost/vhost_user.c | 6 ++++++
  1 file changed, 6 insertions(+)
lib/vhost/vhost_user.c +3 -0
index 1ec4357bee..1d390677fa 100644
@@ -1602,6 +1602,9 @@ vhost_user_get_inflight_fd(struct virtio_net **pdev,
  	int numa_node = SOCKET_ID_ANY;
  	void *addr;
 
+	if (validate_msg_fds(dev, ctx, 0) != 0)
+		return RTE_VHOST_MSG_RESULT_ERR;
+
  	if (ctx->msg.size != sizeof(ctx->msg.payload.inflight)) {
  		VHOST_LOG_CONFIG(ERR, "(%s) invalid get_inflight_fd message size is %d\n",
  			dev->ifname, ctx->msg.size);

lib/vhost/vhost_user.c vhost_user_set_inflight_fd(struct virtio_net **pdev, · line 1710

Quoted 9 lines
lib/vhost/vhost_user.c +3 -0
@@ -1699,6 +1702,9 @@ vhost_user_set_inflight_fd(struct virtio_net **pdev,
  	int fd, i;
  	int numa_node = SOCKET_ID_ANY;
 
+	if (validate_msg_fds(dev, ctx, 1) != 0)
+		return RTE_VHOST_MSG_RESULT_ERR;
+
  	fd = ctx->fds[0];
  	if (ctx->msg.size != sizeof(ctx->msg.payload.inflight) || fd < 0) {
  		VHOST_LOG_CONFIG(ERR, "(%s) invalid set_inflight_fd message size is %d,fd is %d\n",

Thanks,
Maxime

#3 lore raw

Re: [PATCH 2/2] vhost: fix FD leak with inflight messages

Quoted 9 lines · Maxime Coquelin
Quoted 7 lines · David Marchand

Even if unlikely, a buggy vhost-user master might attach fds to inflight messages. Add checks like for other types of vhost-user messages.

Fixes d87f1a1cb7b6 ("vhost: support inflight info sharing")

Series applied, thanks.

Signature · 1 line
David Marchand
Reviewed-by on v1 1/2
#4 lore raw
In reply to David Marchand
Quoted 23 lines · David Marchand

From: Chenbo Xia <[email protected]>

In function vhost_user_set_inflight_fd, queue number in inflight message is used to access virtqueue. However, queue number could be larger than VHOST_MAX_VRING and cause write OOB as this number will be used to write inflight info in virtqueue structure. This patch checks the queue number to avoid the issue and also make sure virtqueues are allocated before setting inflight information.

Fixes ad0a4ae491fe ("vhost: checkout resubmit inflight information")
---
  lib/vhost/vhost_user.c | 3 +++
  1 file changed, 3 insertions(+)
lib/vhost/vhost_user.c +0 -0
index 589b950458..1ec4357bee 100644

lib/vhost/vhost_user.c vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, · line 2891

Quoted 9 lines
lib/vhost/vhost_user.c +3 -0
@@ -2883,6 +2883,9 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
  	case VHOST_USER_SET_VRING_ADDR:
  		vring_idx = ctx->msg.payload.addr.index;
  		break;
+	case VHOST_USER_SET_INFLIGHT_FD:
+		vring_idx = ctx->msg.payload.inflight.num_queues - 1;
+		break;
  	default:
  		return 0;
  	}

Thanks,
Maxime