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.coque...@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

Reply via email to