Skip to content

Commit 12a2e88

Browse files
ordexcron2
authored andcommitted
sitnl: set FD_CLOEXEC on socket to prevent abuse
Since OpenVPN spawns various child processes, it is important that sockets are closed after calling exec. The sitnl socket didn't have the right flag set, resulting in it surviving in, for example, connect/disconnect scripts and giving the latter a chance to abuse the socket. Ensure this doesn't happen by setting FD_CLOEXEC on this socket right after creation. Reported-by: Joshua Rogers <contact@joshua.hu> Found-by: ZeroPath (https://zeropath.com/) Change-Id: I54845bf4dd17d06cfc3b402f188795f74f4b1d3e Signed-off-by: Antonio Quartulli <antonio@mandelbit.com> Acked-by: Gert Doering <gert@greenie.muc.de> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1314 Message-Id: <20251028162843.18189-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33952.html Signed-off-by: Gert Doering <gert@greenie.muc.de> (cherry picked from commit b9b5470)
1 parent e83c63f commit 12a2e88

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ if (BUILD_TESTING)
711711
src/openvpn/crypto_mbedtls.c
712712
src/openvpn/crypto_openssl.c
713713
src/openvpn/crypto.c
714+
src/openvpn/fdmisc.c
714715
src/openvpn/otime.c
715716
src/openvpn/packet_id.c
716717
)

src/openvpn/networking_sitnl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "dco.h"
3030
#include "errlevel.h"
31+
#include "fdmisc.h"
3132
#include "buffer.h"
3233
#include "misc.h"
3334
#include "networking.h"
@@ -166,6 +167,9 @@ sitnl_socket(void)
166167
return fd;
167168
}
168169

170+
/* set close on exec to avoid child processes access the socket */
171+
set_cloexec(fd);
172+
169173
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0)
170174
{
171175
msg(M_WARN | M_ERRNO, "%s: SO_SNDBUF", __func__);

tests/unit_tests/openvpn/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ networking_testdriver_SOURCES = test_networking.c mock_msg.c \
130130
$(top_srcdir)/src/openvpn/crypto.c \
131131
$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
132132
$(top_srcdir)/src/openvpn/crypto_openssl.c \
133+
$(top_srcdir)/src/openvpn/fdmisc.c \
133134
$(top_srcdir)/src/openvpn/otime.c \
134135
$(top_srcdir)/src/openvpn/packet_id.c \
135136
$(top_srcdir)/src/openvpn/platform.c

0 commit comments

Comments
 (0)