blob: 8524517cb6183ca484a7535b8254913e3892a1e5 [file] [log] [blame]
Brad Bishop26bdd442019-08-16 17:08:17 -04001From f4f9d24860e1b5cd4f6a014f3fda7cd33ebe5be7 Mon Sep 17 00:00:00 2001
2From: Petr Lautrbach <plautrba@redhat.com>
3Date: Sat, 27 Jul 2019 08:20:20 -0700
4Subject: [PATCH] libselinux: Do not define gettid() if glibc >= 2.30 is used
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Since version 2.30 glibc implements gettid() system call wrapper, see
10https://sourceware.org/bugzilla/show_bug.cgi?id=6399
11
12Fixes:
13cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I../include -D_GNU_SOURCE -DNO_ANDROID_BACKEND -c -o procattr.o procattr.c
14procattr.c:28:14: error: static declaration of gettid follows non-static declaration
15 28 | static pid_t gettid(void)
16 | ^~~~~~
17In file included from /usr/include/unistd.h:1170,
18 from procattr.c:2:
19/usr/include/bits/unistd_ext.h:34:16: note: previous declaration of gettid was here
20 34 | extern __pid_t gettid (void) __THROW;
21 | ^~~~~~
22
23Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
24Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
25Signed-off-by: Khem Raj <raj.khem@gmail.com>
26---
27 src/procattr.c | 14 +++++++++++++-
28 1 file changed, 13 insertions(+), 1 deletion(-)
29
30--- a/src/procattr.c
31+++ b/src/procattr.c
32@@ -8,7 +8,19 @@
33 #include "selinux_internal.h"
34 #include "policy.h"
35
36-#ifndef __BIONIC__
37+/* Bionic and glibc >= 2.30 declare gettid() system call wrapper in unistd.h and
38+ * has a definition for it */
39+#ifdef __BIONIC__
40+ #define OVERRIDE_GETTID 0
41+#elif !defined(__GLIBC_PREREQ)
42+ #define OVERRIDE_GETTID 1
43+#elif !__GLIBC_PREREQ(2,29)
44+ #define OVERRIDE_GETTID 1
45+#else
46+ #define OVERRIDE_GETTID 0
47+#endif
48+
49+#if OVERRIDE_GETTID
50 static pid_t gettid(void)
51 {
52 return syscall(__NR_gettid);