Skip to content

Commit

Permalink
vhost: fix FD leak with inflight messages
Browse files Browse the repository at this point in the history
[ upstream commit af74f7d ]

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: d87f1a1 ("vhost: support inflight info sharing")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
david-marchand authored and bluca committed Mar 15, 2022
1 parent 9bac6ad commit 8c32692
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/librte_vhost/vhost_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,9 @@ vhost_user_get_inflight_fd(struct virtio_net **pdev,
int fd, i, j;
void *addr;

if (validate_msg_fds(msg, 0) != 0)
return RTE_VHOST_MSG_RESULT_ERR;

if (msg->size != sizeof(msg->payload.inflight)) {
VHOST_LOG_CONFIG(ERR,
"invalid get_inflight_fd message size is %d\n",
Expand Down Expand Up @@ -1543,6 +1546,9 @@ vhost_user_set_inflight_fd(struct virtio_net **pdev, VhostUserMsg *msg,
void *addr;
int fd, i;

if (validate_msg_fds(msg, 1) != 0)
return RTE_VHOST_MSG_RESULT_ERR;

fd = msg->fds[0];
if (msg->size != sizeof(msg->payload.inflight) || fd < 0) {
VHOST_LOG_CONFIG(ERR,
Expand Down

0 comments on commit 8c32692

Please sign in to comment.