From fb43d1a3163f224873196a4317a95aa4ed85d753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Thu, 25 Apr 2024 11:18:16 +0200 Subject: [PATCH 1/2] [Inet] Fix setting for SOCK_CLOEXEC The linux kernel allows to set the flag SOCK_CLOEXEC through the parameter type[1]. The implementation sets the flag through the parameter protocol and causes the call to socket()[2] to return -1 with EINVAL. This fixes the behaviour by OR-ing the flag SOCK_CLOEXEC to type instead of protocol. [1]: https://github.com/torvalds/linux/blob/v6.8/net/socket.c#L1655 [2]: https://man7.org/linux/man-pages/man2/socket.2.html --- src/inet/InetInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index db10bdba3ed769..ad186aec1dbf6a 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -500,7 +500,7 @@ int GetIOCTLSocket() { int s; #ifdef SOCK_CLOEXEC - s = socket(AF_INET, SOCK_STREAM, SOCK_CLOEXEC); + s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0); if (s < 0) #endif { From 7da2b18a4ddeee0bb42946311e3829d0d8909410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Thu, 25 Apr 2024 11:33:08 +0200 Subject: [PATCH 2/2] [Inet] Fix setting for O_CLOEXEC The macro O_CLOEXEC is a filedescriptor flag. The implemention sets the flag O_CLOEXEC as the parameter command given to function fcntl[1] and causes the call to fcntl to return -1 with EINVAL. The flag O_CLOEXEC intends to be set using the command F_SETFD. This fixes the behaviour by adding the missing command paramete F_SETFD before the optional argument O_CLOEXEC. [1]: https://man7.org/linux/man-pages/man2/fcntl.2.html --- src/inet/InetInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index ad186aec1dbf6a..af89de8cb96822 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -505,7 +505,7 @@ int GetIOCTLSocket() #endif { s = socket(AF_INET, SOCK_STREAM, 0); - fcntl(s, O_CLOEXEC); + fcntl(s, F_SETFD, O_CLOEXEC); } if (!__sync_bool_compare_and_swap(&sIOCTLSocket, -1, s))