[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] net/tap: fix FreeBSD portability problem receiving TAP FD
From: |
Daniel P . Berrangé |
Subject: |
[PATCH 1/2] net/tap: fix FreeBSD portability problem receiving TAP FD |
Date: |
Wed, 5 May 2021 13:12:35 +0100 |
The CMSG_LEN and CMSG_SPACE macros must not be assumed to return the
same value. The msg_controllen field must be initialized using
CMSG_SPACE when using SCM_RIGHTS.
This ought to fix any FD receive issues users might be hitting on
64-bit FeeBSD / NetBSD platforms. The flaw was noticed first in
GNULIB
https://lists.gnu.org/archive/html/bug-gnulib/2021-02/msg00066.html
and QEMU's code has the same logic bug.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
net/tap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/tap.c b/net/tap.c
index bae895e287..276a9077fc 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -467,7 +467,7 @@ static int recv_fd(int c)
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
- msg.msg_controllen = cmsg->cmsg_len;
+ msg.msg_controllen = CMSG_SPACE(sizeof(fd));
iov.iov_base = req;
iov.iov_len = sizeof(req);
--
2.31.1