Eliminate requirement on pthread library, by applying patch for Jakub Jelinek

Resolves #1013801
This commit is contained in:
Dan Walsh 2013-10-03 12:36:44 -04:00
parent 763f66c192
commit 0695b75fac
2 changed files with 147 additions and 10 deletions

View File

@ -508,7 +508,7 @@ index 948aff1..598dc94 100644
togglesebool \- flip the current value of a SELinux boolean
.
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index c4f5d4c..8f557a1 100644
index c4f5d4c..310177b 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -18,9 +18,7 @@ RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")'
@ -527,7 +527,7 @@ index c4f5d4c..8f557a1 100644
$(LIBSO): $(LOBJS)
- $(CC) $(CFLAGS) -shared -o $@ $^ -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+ $(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -lpthread -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+ $(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
ln -sf $@ $(TARGET)
$(LIBPC): $(LIBPC).in ../VERSION
@ -705,6 +705,32 @@ index 802a07f..6ff83a7 100644
return rc;
}
diff --git a/libselinux/src/fsetfilecon.c b/libselinux/src/fsetfilecon.c
index 309105c..0e9278e 100644
--- a/libselinux/src/fsetfilecon.c
+++ b/libselinux/src/fsetfilecon.c
@@ -9,8 +9,20 @@
int fsetfilecon_raw(int fd, const security_context_t context)
{
- return fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
+ int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
0);
+ if (rc < 0 && errno == ENOTSUP) {
+ security_context_t ccontext = NULL;
+ int err = errno;
+ if ((fgetfilecon_raw(fd, &ccontext) >= 0) &&
+ (strcmp(context,ccontext) == 0)) {
+ rc = 0;
+ } else {
+ errno = err;
+ }
+ freecon(ccontext);
+ }
+ return rc;
}
hidden_def(fsetfilecon_raw)
diff --git a/libselinux/src/get_context_list.c b/libselinux/src/get_context_list.c
index b9e8002..1d91123 100644
--- a/libselinux/src/get_context_list.c
@ -837,6 +863,32 @@ index 5f697f3..9b0d6b0 100644
ret = &spec_arr[i].lr;
finish:
diff --git a/libselinux/src/lsetfilecon.c b/libselinux/src/lsetfilecon.c
index 461e3f7..ab85155 100644
--- a/libselinux/src/lsetfilecon.c
+++ b/libselinux/src/lsetfilecon.c
@@ -9,8 +9,20 @@
int lsetfilecon_raw(const char *path, const security_context_t context)
{
- return lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
+ int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
0);
+ if (rc < 0 && errno == ENOTSUP) {
+ security_context_t ccontext = NULL;
+ int err = errno;
+ if ((lgetfilecon_raw(path, &ccontext) >= 0) &&
+ (strcmp(context,ccontext) == 0)) {
+ rc = 0;
+ } else {
+ errno = err;
+ }
+ freecon(ccontext);
+ }
+ return rc;
}
hidden_def(lsetfilecon_raw)
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
index 2d7369e..2a00807 100644
--- a/libselinux/src/matchpathcon.c
@ -859,10 +911,10 @@ index 2d7369e..2a00807 100644
}
diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
index 6c5b45a..f6b896e 100644
index 6c5b45a..ecaccc6 100644
--- a/libselinux/src/procattr.c
+++ b/libselinux/src/procattr.c
@@ -9,13 +9,15 @@
@@ -9,19 +9,30 @@
#include "selinux_internal.h"
#include "policy.h"
@ -883,7 +935,22 @@ index 6c5b45a..f6b896e 100644
static pthread_once_t once = PTHREAD_ONCE_INIT;
static pthread_key_t destructor_key;
@@ -29,11 +31,16 @@ static pid_t gettid(void)
static int destructor_key_initialized = 0;
static __thread char destructor_initialized;
+extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden")));
+extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *);
+
+static int __selinux_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void))
+{
+ return __register_atfork (prepare, parent, child,
+ &__dso_handle == NULL ? NULL : __dso_handle);
+}
+
static pid_t gettid(void)
{
return syscall(__NR_gettid);
@@ -29,11 +40,16 @@ static pid_t gettid(void)
static void procattr_thread_destructor(void __attribute__((unused)) *unused)
{
@ -905,7 +972,7 @@ index 6c5b45a..f6b896e 100644
}
static void free_procattr(void)
@@ -41,7 +48,7 @@ static void free_procattr(void)
@@ -41,7 +57,7 @@ static void free_procattr(void)
procattr_thread_destructor(NULL);
tid = 0;
cpid = getpid();
@ -914,7 +981,16 @@ index 6c5b45a..f6b896e 100644
}
void __attribute__((destructor)) procattr_destructor(void);
@@ -131,7 +138,7 @@ static int getprocattrcon_raw(security_context_t * context,
@@ -63,7 +79,7 @@ static inline void init_thread_destructor(void)
static void init_procattr(void)
{
if (__selinux_key_create(&destructor_key, procattr_thread_destructor) == 0) {
- pthread_atfork(NULL, NULL, free_procattr);
+ __selinux_atfork(NULL, NULL, free_procattr);
destructor_key_initialized = 1;
}
}
@@ -131,7 +147,7 @@ static int getprocattrcon_raw(security_context_t * context,
return -1;
};
@ -923,7 +999,7 @@ index 6c5b45a..f6b896e 100644
*context = strdup(prev_context);
if (!(*context)) {
return -1;
@@ -230,7 +237,8 @@ static int setprocattrcon_raw(security_context_t context,
@@ -230,7 +246,8 @@ static int setprocattrcon_raw(security_context_t context,
if (!context && !*prev_context)
return 0;
@ -933,7 +1009,7 @@ index 6c5b45a..f6b896e 100644
return 0;
fd = openattr(pid, attr, O_RDWR);
@@ -257,6 +265,8 @@ out:
@@ -257,6 +274,8 @@ out:
free(context);
return -1;
} else {
@ -1077,6 +1153,63 @@ index 359bd02..9884454 100644
/* Makes security_compute_user() return a Python list of contexts */
%typemap(argout) (security_context_t **con) {
PyObject* plist;
diff --git a/libselinux/src/setfilecon.c b/libselinux/src/setfilecon.c
index 7465c6a..9aaaa4b 100644
--- a/libselinux/src/setfilecon.c
+++ b/libselinux/src/setfilecon.c
@@ -9,8 +9,20 @@
int setfilecon_raw(const char *path, const security_context_t context)
{
- return setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
+ int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
0);
+ if (rc < 0 && errno == ENOTSUP) {
+ security_context_t ccontext = NULL;
+ int err = errno;
+ if ((getfilecon_raw(path, &ccontext) >= 0) &&
+ (strcmp(context,ccontext) == 0)) {
+ rc = 0;
+ } else {
+ errno = err;
+ }
+ freecon(ccontext);
+ }
+ return rc;
}
hidden_def(setfilecon_raw)
diff --git a/libselinux/src/setrans_client.c b/libselinux/src/setrans_client.c
index f9065bd..4ab7c2a 100644
--- a/libselinux/src/setrans_client.c
+++ b/libselinux/src/setrans_client.c
@@ -249,12 +249,12 @@ out:
static void setrans_thread_destructor(void __attribute__((unused)) *unused)
{
- free(prev_t2r_trans);
- free(prev_t2r_raw);
- free(prev_r2t_trans);
- free(prev_r2t_raw);
- free(prev_r2c_trans);
- free(prev_r2c_raw);
+ free(prev_t2r_trans); prev_t2r_trans = NULL;
+ free(prev_t2r_raw); prev_t2r_raw = NULL;
+ free(prev_r2t_trans); prev_r2t_trans = NULL;
+ free(prev_r2t_raw); prev_r2t_raw = NULL;
+ free(prev_r2c_trans); prev_r2c_trans = NULL;
+ free(prev_r2c_raw); prev_r2c_raw = NULL;
}
void __attribute__((destructor)) setrans_lib_destructor(void);
@@ -267,6 +267,7 @@ void hidden __attribute__((destructor)) setrans_lib_destructor(void)
static inline void init_thread_destructor(void)
{
+ setrans_thread_destructor(NULL);
if (destructor_initialized == 0) {
__selinux_setspecific(destructor_key, (void *)1);
destructor_initialized = 1;
diff --git a/libselinux/src/setrans_internal.h b/libselinux/src/setrans_internal.h
index a801ee8..b3bdca2 100644
--- a/libselinux/src/setrans_internal.h

View File

@ -10,7 +10,7 @@
Summary: SELinux library and simple utilities
Name: libselinux
Version: 2.1.13
Release: 19%{?dist}
Release: 20%{?dist}
License: Public Domain
Group: System Environment/Libraries
Source: %{name}-%{version}.tgz
@ -240,6 +240,10 @@ rm -rf %{buildroot}
%{ruby_sitearch}/selinux.so
%changelog
* Thu Oct 3 2013 Dan Walsh <dwalsh@redhat.com> - 2.1.13-20
- Eliminate requirement on pthread library, by applying patch for Jakub Jelinek
Resolves #1013801
* Mon Sep 16 2013 Dan Walsh <dwalsh@redhat.com> - 2.1.13-19
- Fix handling of libselinux getconlist with only one entry