DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] vhost: improve truncated messages handling
@ 2023-01-27 13:57 Maxime Coquelin
  2023-01-27 16:30 ` Maxime Coquelin
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Coquelin @ 2023-01-27 13:57 UTC (permalink / raw)
  To: dev, david.marchand, chenbo.xia; +Cc: Maxime Coquelin

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@redhat.com>
---
 lib/vhost/socket.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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)) {
-- 
2.39.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] vhost: improve truncated messages handling
  2023-01-27 13:57 [PATCH] vhost: improve truncated messages handling Maxime Coquelin
@ 2023-01-27 16:30 ` Maxime Coquelin
  0 siblings, 0 replies; 2+ messages in thread
From: Maxime Coquelin @ 2023-01-27 16:30 UTC (permalink / raw)
  To: dev, david.marchand, chenbo.xia



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@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)) {


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-27 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27 13:57 [PATCH] vhost: improve truncated messages handling Maxime Coquelin
2023-01-27 16:30 ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).