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

Message ID 20220310125059.30562-2-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [1/2] vhost: fix queue number check when setting inflight FD |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

David Marchand March 10, 2022, 12:50 p.m. UTC
  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")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/vhost/vhost_user.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Maxime Coquelin March 10, 2022, 1 p.m. UTC | #1
On 3/10/22 13:50, David Marchand wrote:
> 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")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>   lib/vhost/vhost_user.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 1ec4357bee..1d390677fa 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -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",

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
David Marchand March 10, 2022, 3:32 p.m. UTC | #2
On Thu, Mar 10, 2022 at 2:00 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
> On 3/10/22 13:50, David Marchand wrote:
> > 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")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Series applied, thanks.
  

Patch

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 1ec4357bee..1d390677fa 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -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",