summaryrefslogtreecommitdiffstats
path: root/recipes-security/selinux/policycoreutils/policycoreutils-make-O_CLOEXEC-optional.patch
blob: aaaa1e596d8a76b0d3b345b2bd99813011493594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From dca6a89058d818827d6f1c80c9b6abb46002b855 Mon Sep 17 00:00:00 2001
From: Joe MacDonald <joe.macdonald@windriver.com>
Date: Fri, 11 Oct 2013 09:55:43 -0400
Subject: [PATCH 1/2] policycoreutils: make O_CLOEXEC optional

Various commits in the selinux tree in the current release added O_CLOEXEC
to open() calls in an attempt to address file descriptor leaks as
described:

   http://danwalsh.livejournal.com/53603.html

However O_CLOEXEC isn't available on all platforms, so make it a
compile-time option and generate a warning when it is not available.  The
actual impact of leaking these file descriptors is minimal, though it does
produce curious AVC Denied messages.

Uptream-Status: Inappropriate [O_CLOEXEC has been in Linux since 2007 and POSIX since 2008]

Signed-off-by: Joe MacDonald <joe.macdonald@windriver.com>
---
 restorecond/user.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/restorecond/user.c b/restorecond/user.c
index 00a646f..50f3ab6 100644
--- a/restorecond/user.c
+++ b/restorecond/user.c
@@ -201,7 +201,13 @@ static int local_server() {
 			perror("asprintf");
 		return -1;
 	}
-	int fd = open(ptr, O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, S_IRUSR | S_IWUSR);
+	int fd = open(ptr, O_CREAT | O_WRONLY | O_NOFOLLOW 
+#ifdef O_CLOEXEC
+                 | O_CLOEXEC
+#else
+#warning O_CLOEXEC undefined on this platform, this may leak file descriptors
+#endif
+                 , S_IRUSR | S_IWUSR);
 	if (debug_mode)
 		g_warning ("Lock file: %s", ptr);
 
-- 
1.7.10.4