From: Joshua Rogers Date: Tue, 21 Oct 2025 17:20:52 +0000 (+0800) Subject: tcp: apply CLOEXEC to accepted socket, not listener X-Git-Tag: v2.7_rc1~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c0d96fd8732bd903ab390bb5047a13880cdcac9b;p=thirdparty%2Fopenvpn.git tcp: apply CLOEXEC to accepted socket, not listener The accept path calls set_cloexec(sd) after accept(). That re-flags the listening socket, which is already CLOEXEC from create_socket_tcp(), and leaves new_sd inheritable. As a result, client-connect and auth scripts spawned after accept can inherit the connected socket and read or write the raw TCP stream. This defeats the stated intent to prevent scripts from accessing the client socket. This bug was found using ZeroPath. Signed-off-by: Joshua Rogers Acked-by: Gert Doering Message-Id: <-MNw5Hu8h0rHV18x36ISt7V0UHchIO4i-JoAeV_wlxS1AmDIAe7YVYNput3_r2hiu3HhwxkhGyUhv4-iH_E7mf7nGjvocmGXlDq7Tjly5cE=@joshua.hu> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33823.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 40a86fbb6..8eac96dd0 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -836,7 +836,7 @@ socket_do_accept(socket_descriptor_t sd, struct link_socket_actual *act, const b { /* set socket file descriptor to not pass across execs, so that * scripts don't have access to it */ - set_cloexec(sd); + set_cloexec(new_sd); } return new_sd; }