From 67116c69052d27dbd6d6c066104850d4d53f0041 Mon Sep 17 00:00:00 2001 From: Dmitry Chagin Date: Sat, 29 Jul 2023 11:21:35 +0300 Subject: [PATCH] linux(4): Fix control message size calculation To determine the size in bytes needed to hold a control message and its contents of length len, CMSG_SPACE should be used. Reviewed by: Differential Revision: https://reviews.freebsd.org/D41224 MFC after: 1 week --- sys/compat/linux/linux_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index dd8d688a691..ac411aae1cb 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1852,7 +1852,7 @@ cont: if (error != 0) goto bad; - if (outlen + LINUX_CMSG_LEN(datalen) > maxlen) { + if (outlen + LINUX_CMSG_SPACE(datalen) > maxlen) { if (outlen == 0) { error = EMSGSIZE; goto err; @@ -1871,7 +1871,7 @@ cont: error = copyout(data, outbuf, datalen); if (error == 0) { outbuf += LINUX_CMSG_ALIGN(datalen); - outlen += LINUX_CMSG_LEN(datalen); + outlen += LINUX_CMSG_SPACE(datalen); } } err: