Skip to content

Commit 1680cbe

Browse files
author
David Sommerseth
committed
Force O_CLOEXEC on the NETLINK socket
To avoid that the NETLINK socket is available to forked children, set the FD_CLOEXEC flag on the NETLINK socket. This also avoids SELinux from complaining on Fedora 14. For more information: https://bugzilla.redhat.com/show_bug.cgi?id=689843 Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent 9f0d17a commit 1680cbe

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

python-ethtool/etherinfo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string.h>
2222
#include <sys/types.h>
2323
#include <unistd.h>
24+
#include <fcntl.h>
2425
#include <stdlib.h>
2526
#include <asm/types.h>
2627
#include <sys/socket.h>
@@ -382,6 +383,13 @@ int open_netlink(struct etherinfo_obj_data *data)
382383
*data->nlc = nl_handle_alloc();
383384
nl_connect(*data->nlc, NETLINK_ROUTE);
384385
if( (*data->nlc != NULL) ) {
386+
/* Force O_CLOEXEC flag on the NETLINK socket */
387+
if( fcntl(nl_socket_get_fd(*data->nlc), F_SETFD, FD_CLOEXEC) == -1 ) {
388+
fprintf(stderr,
389+
"**WARNING** Failed to set O_CLOEXEC on NETLINK socket: %s\n",
390+
strerror(errno));
391+
}
392+
385393
/* Tag this object as an active user */
386394
pthread_mutex_lock(&nlc_counter_mtx);
387395
(*data->nlc_users)++;

0 commit comments

Comments
 (0)