summaryrefslogtreecommitdiffstats
path: root/libiptc/libiptc.c
diff options
context:
space:
mode:
authorMaciej ┼╗enczykowski <maze@google.com>2012-03-21 00:52:00 +0000
committerPablo Neira Ayuso <pablo@netfilter.org>2012-03-23 11:24:30 +0100
commitc0aa38e22e8a09fcb1898ad0e042eaf6314d2d42 (patch)
tree6c4df30f78f66235cb610b018f4dbf8a5cee1621 /libiptc/libiptc.c
parent61b8f7ecb64b3b6fe04d2a6ad9598f66e42ceea8 (diff)
src: mark newly opened fds as FD_CLOEXEC (close on exec)
By default, Unix-like systems leak file descriptors after fork/exec call. I think this seem to result in SELinux spotting a strange AVC log messages according to what I can find on the web. Fedora 18 iptables source includes this change. Maciej says: "iptables does potentially fork/exec modprobe to load modules. That can cause a selinux 'domain'/'role'/whatever-it-is-called crossing. You can do automated inspection of what gets carried across such privilege changes and any unexpected open file descriptors flag problems, patches like this cut down on the noise." Signed-off-by: Maciej enczykowski <maze@google.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'libiptc/libiptc.c')
-rw-r--r--libiptc/libiptc.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index 13e41d52..63965e73 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -29,6 +29,8 @@
* - performance work: speedup initial ruleset parsing.
* - sponsored by ComX Networks A/S (http://www.comx.dk/)
*/
+#include <unistd.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdbool.h>
@@ -1316,6 +1318,12 @@ TC_INIT(const char *tablename)
if (sockfd < 0)
return NULL;
+ if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) == -1) {
+ fprintf(stderr, "Could not set close on exec: %s\n",
+ strerror(errno));
+ abort();
+ }
+
retry:
s = sizeof(info);