[PATCH] vhost: improve truncated messages handling

Maxime Coquelin maxime.coquelin at redhat.com
Fri Jan 27 17:30:15 CET 2023



On 1/27/23 14:57, Maxime Coquelin wrote:
> This patch improves truncated messages logging to ease
> debugging.
> 
> First, it differentiates between message's buffer
> truncation and control data truncation. Indeed, MSG_CTRUNC
> can happen even if enough room was provided, in case LSM
> detects access rights issue.
> 
> Then, it does not return directly in case of truncation,
> but returns normally to let a chance to display request
> type in Vhost-user protocol layer logs.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
>   lib/vhost/socket.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)

Discussing with David, there was/is a possible FDs leak when
truncation happens, a V2 is coming to handle these properly.

> diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
> index 863a6f6d52..669c322e12 100644
> --- a/lib/vhost/socket.c
> +++ b/lib/vhost/socket.c
> @@ -129,10 +129,12 @@ read_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int m
>   		return ret;
>   	}
>   
> -	if (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
> +	if (msgh.msg_flags & MSG_TRUNC)
>   		VHOST_LOG_CONFIG(ifname, ERR, "truncated msg (fd %d)\n", sockfd);
> -		return -1;
> -	}
> +
> +	/* MSG_CTRUNC may be caused by LSM misconfiguration */
> +	if (msgh.msg_flags & MSG_CTRUNC)
> +		VHOST_LOG_CONFIG(ifname, ERR, "truncated control data (fd %d)\n", sockfd);
>   
>   	for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
>   		cmsg = CMSG_NXTHDR(&msgh, cmsg)) {



More information about the dev mailing list