|
|
17b0f1 |
From 2d30914ae86e9f40c02d80e0ef5c01e54efbbbc9 Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Michal Sekletar <msekleta@redhat.com>
|
|
|
17b0f1 |
Date: Tue, 1 Sep 2015 16:02:58 +0200
|
|
|
17b0f1 |
Subject: [PATCH] selinux: always use *_raw API from libselinux
|
|
|
17b0f1 |
|
|
|
17b0f1 |
When mcstransd* is running non-raw functions will return translated SELinux
|
|
|
17b0f1 |
context. Problem is that libselinux will cache this information and in the
|
|
|
17b0f1 |
future it will return same context even though mcstransd maybe not running at
|
|
|
17b0f1 |
that time. If you then check with such context against SELinux policy then
|
|
|
17b0f1 |
selinux_check_access may fail depending on whether mcstransd is running or not.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
To workaround this problem/bug in libselinux, we should always get raw context
|
|
|
17b0f1 |
instead. Most users will not notice because they don't use MCS/MLS policy
|
|
|
17b0f1 |
anyway. Others will most likely not notice as well because result of access
|
|
|
17b0f1 |
check is logged only in debug mode.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
* Service which translates labels to human readable form
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Resolves: #1256888
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
src/core/selinux-access.c | 4 ++--
|
|
|
17b0f1 |
src/shared/selinux-util.c | 10 +++++-----
|
|
|
17b0f1 |
2 files changed, 7 insertions(+), 7 deletions(-)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
|
|
|
17b0f1 |
index f11247c092..297372d126 100644
|
|
|
17b0f1 |
--- a/src/core/selinux-access.c
|
|
|
17b0f1 |
+++ b/src/core/selinux-access.c
|
|
|
17b0f1 |
@@ -219,13 +219,13 @@ int mac_selinux_generic_access_check(
|
|
|
17b0f1 |
if (path && !system) {
|
|
|
17b0f1 |
/* Get the file context of the unit file */
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = getfilecon(path, &fcon);
|
|
|
17b0f1 |
+ r = getfilecon_raw(path, &fcon);
|
|
|
17b0f1 |
if (r < 0) {
|
|
|
17b0f1 |
r = sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Failed to get file context on %s.", path);
|
|
|
17b0f1 |
goto finish;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
} else {
|
|
|
17b0f1 |
- r = getcon(&fcon);
|
|
|
17b0f1 |
+ r = getcon_raw(&fcon);
|
|
|
17b0f1 |
if (r < 0) {
|
|
|
17b0f1 |
r = sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Failed to get current context.");
|
|
|
17b0f1 |
goto finish;
|
|
|
17b0f1 |
diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c
|
|
|
17b0f1 |
index a46ddf8498..4c2e1b0b47 100644
|
|
|
17b0f1 |
--- a/src/shared/selinux-util.c
|
|
|
17b0f1 |
+++ b/src/shared/selinux-util.c
|
|
|
17b0f1 |
@@ -200,11 +200,11 @@ int mac_selinux_get_create_label_from_exe(const char *exe, char **label) {
|
|
|
17b0f1 |
if (!mac_selinux_use())
|
|
|
17b0f1 |
return -EOPNOTSUPP;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = getcon(&mycon);
|
|
|
17b0f1 |
+ r = getcon_raw(&mycon);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return -errno;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = getfilecon(exe, &fcon);
|
|
|
17b0f1 |
+ r = getfilecon_raw(exe, &fcon);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return -errno;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -226,7 +226,7 @@ int mac_selinux_get_our_label(char **label) {
|
|
|
17b0f1 |
if (!mac_selinux_use())
|
|
|
17b0f1 |
return -EOPNOTSUPP;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = getcon(label);
|
|
|
17b0f1 |
+ r = getcon_raw(label);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return -errno;
|
|
|
17b0f1 |
#endif
|
|
|
17b0f1 |
@@ -250,7 +250,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
|
|
|
17b0f1 |
if (!mac_selinux_use())
|
|
|
17b0f1 |
return -EOPNOTSUPP;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = getcon(&mycon);
|
|
|
17b0f1 |
+ r = getcon_raw(&mycon);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return -errno;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -261,7 +261,7 @@ int mac_selinux_get_child_mls_label(int socket_fd, const char *exe, const char *
|
|
|
17b0f1 |
if (!exec_label) {
|
|
|
17b0f1 |
/* If there is no context set for next exec let's use context
|
|
|
17b0f1 |
of target executable */
|
|
|
17b0f1 |
- r = getfilecon(exe, &fcon);
|
|
|
17b0f1 |
+ r = getfilecon_raw(exe, &fcon);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
return -errno;
|
|
|
17b0f1 |
}
|