|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
From f37f36832bafdb4c8566298c554e335f55d23152 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
From: Michal Schmidt <mschmidt@redhat.com>
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
Date: Thu, 6 Nov 2014 16:48:11 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
Subject: [PATCH] shared: create files even if the SELinux policy has no
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
context for them
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
The SELinux policy defines no context for some files. E.g.:
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
$ matchpathcon /run/lock/subsys /dev/mqueue
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
/run/lock/subsys <<none>>
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
/dev/mqueue <<none>>
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
We still need to be able to create them.
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
In this case selabel_lookup_raw() returns ENOENT. We should then skip
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
setfscreatecon(), but still return success.
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
It was broken since c34255bdb2 ("label: unify code to make directories,
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
symlinks").
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
(cherry picked from commit 2d58aa4692e9fc47911bff5d064ba3e328c35369)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
src/shared/selinux-util.c | 8 ++++++--
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
index 1eddd17d27..6bd3bf1c80 100644
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
--- a/src/shared/selinux-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+++ b/src/shared/selinux-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
@@ -332,9 +332,13 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
r = selabel_lookup_raw(label_hnd, &filecon, newpath, mode);
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- if (r < 0 && errno != ENOENT)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ /* No context specified by the policy? Proceed without setting it. */
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ if (r < 0 && errno == ENOENT)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
r = -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
- else if (r == 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
+ else {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
r = setfscreatecon(filecon);
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
ea1976 |
log_enforcing("Failed to set SELinux security context %s for %s: %m", filecon, path);
|