aboutsummaryrefslogtreecommitdiffstats
path: root/main/fprobe-ulog/fix-setuser.patch
blob: 0b10a9e7f8e1094992969c85cf315a5c700517f6 (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: Timo Teräs <timo.teras@iki.fi>

Fix setre[gu]id handling for uclibc. uclibc may have non-compliant
setre[gu]id implementation calling directly the syscall. This causes
per-thread functionality instead of the specified per-process functinality.

Fix potential race condition by doing setgroups() only in the main
and doing it early. Later call setre[gu]id in all threads.

diff -ru fprobe-ulog-1.1.orig/src/fprobe-ulog.c fprobe-ulog-1.1/src/fprobe-ulog.c
--- fprobe-ulog-1.1.orig/src/fprobe-ulog.c	2014-07-30 14:13:32.089399841 -0300
+++ fprobe-ulog-1.1/src/fprobe-ulog.c	2014-07-30 14:12:13.626065731 -0300
@@ -625,7 +625,6 @@
 	Try to change EUID independently of main thread
 	*/
 	if (pw) {
-		setgroups(0, NULL);
 		setregid(pw->pw_gid, pw->pw_gid);
 		setreuid(pw->pw_uid, pw->pw_uid);
 	}
@@ -1382,6 +1381,13 @@
 		}
 	}
 
+	if (pw) {
+		if (setgroups(0, NULL)) {
+			my_log(LOG_CRIT, "setgroups(): %s", strerror(errno));
+			exit(1);
+		}
+	}
+
 	schedp.sched_priority = schedp.sched_priority - THREADS + 2;
 	pthread_attr_init(&tattr);
 	for (i = 0; i < THREADS - 1; i++) {
@@ -1401,10 +1407,6 @@
 	}
 
 	if (pw) {
-		if (setgroups(0, NULL)) {
-			my_log(LOG_CRIT, "setgroups(): %s", strerror(errno));
-			exit(1);
-		}
 		if (setregid(pw->pw_gid, pw->pw_gid)) {
 			my_log(LOG_CRIT, "setregid(%u): %s", pw->pw_gid, strerror(errno));
 			exit(1);