|
|
a41c76 |
From f08dc7e622b398b00d6916ead44a8c9058b5a17e Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <f08dc7e622b398b00d6916ead44a8c9058b5a17e@dist-git>
|
|
|
a41c76 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
Date: Tue, 25 Feb 2020 11:24:51 +0100
|
|
|
a41c76 |
Subject: [PATCH] security: Don't remember seclabel for paths we haven't locked
|
|
|
a41c76 |
successfully
|
|
|
a41c76 |
|
|
|
a41c76 |
There are some cases where we want to remember the original owner
|
|
|
a41c76 |
of a file but we fail to lock it for XATTR change (e.g. root
|
|
|
a41c76 |
squashed NFS). If that is the case we error out and refuse to
|
|
|
a41c76 |
start a domain. Well, we can do better if we disable remembering
|
|
|
a41c76 |
for paths we haven't locked successfully.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 5fddf61351f44e4186c0313d81907024c574201b)
|
|
|
a41c76 |
|
|
|
a41c76 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1804672
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
Message-Id: <4c2586a6da3b01adce09573a6123a15b3aea5ae6.1582626185.git.mprivozn@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/security/security_dac.c | 14 ++++++++++++++
|
|
|
a41c76 |
src/security/security_manager.c | 7 -------
|
|
|
a41c76 |
src/security/security_manager.h | 6 ++++++
|
|
|
a41c76 |
src/security/security_selinux.c | 14 ++++++++++++++
|
|
|
a41c76 |
4 files changed, 34 insertions(+), 7 deletions(-)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
|
|
|
a41c76 |
index 2561ee440e..0cfe3626d4 100644
|
|
|
a41c76 |
--- a/src/security/security_dac.c
|
|
|
a41c76 |
+++ b/src/security/security_dac.c
|
|
|
a41c76 |
@@ -240,6 +240,20 @@ virSecurityDACTransactionRun(pid_t pid G_GNUC_UNUSED,
|
|
|
a41c76 |
|
|
|
a41c76 |
if (!(state = virSecurityManagerMetadataLock(list->manager, paths, npaths)))
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < list->nItems; i++) {
|
|
|
a41c76 |
+ virSecurityDACChownItemPtr item = list->items[i];
|
|
|
a41c76 |
+ size_t j;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (j = 0; j < state->nfds; j++) {
|
|
|
a41c76 |
+ if (STREQ_NULLABLE(item->path, state->paths[j]))
|
|
|
a41c76 |
+ break;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* If path wasn't locked, don't try to remember its label. */
|
|
|
a41c76 |
+ if (j == state->nfds)
|
|
|
a41c76 |
+ item->remember = false;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
for (i = 0; i < list->nItems; i++) {
|
|
|
a41c76 |
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
|
|
|
a41c76 |
index 05d20e36af..9d06316a99 100644
|
|
|
a41c76 |
--- a/src/security/security_manager.c
|
|
|
a41c76 |
+++ b/src/security/security_manager.c
|
|
|
a41c76 |
@@ -1245,13 +1245,6 @@ virSecurityManagerRestoreTPMLabels(virSecurityManagerPtr mgr,
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
-struct _virSecurityManagerMetadataLockState {
|
|
|
a41c76 |
- size_t nfds; /* Captures size of both @fds and @paths */
|
|
|
a41c76 |
- int *fds;
|
|
|
a41c76 |
- const char **paths;
|
|
|
a41c76 |
-};
|
|
|
a41c76 |
-
|
|
|
a41c76 |
-
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
cmpstringp(const void *p1, const void *p2)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
diff --git a/src/security/security_manager.h b/src/security/security_manager.h
|
|
|
a41c76 |
index f835356b7e..b92ea5dc87 100644
|
|
|
a41c76 |
--- a/src/security/security_manager.h
|
|
|
a41c76 |
+++ b/src/security/security_manager.h
|
|
|
a41c76 |
@@ -203,6 +203,12 @@ int virSecurityManagerRestoreTPMLabels(virSecurityManagerPtr mgr,
|
|
|
a41c76 |
|
|
|
a41c76 |
typedef struct _virSecurityManagerMetadataLockState virSecurityManagerMetadataLockState;
|
|
|
a41c76 |
typedef virSecurityManagerMetadataLockState *virSecurityManagerMetadataLockStatePtr;
|
|
|
a41c76 |
+struct _virSecurityManagerMetadataLockState {
|
|
|
a41c76 |
+ size_t nfds; /* Captures size of both @fds and @paths */
|
|
|
a41c76 |
+ int *fds;
|
|
|
a41c76 |
+ const char **paths;
|
|
|
a41c76 |
+};
|
|
|
a41c76 |
+
|
|
|
a41c76 |
|
|
|
a41c76 |
virSecurityManagerMetadataLockStatePtr
|
|
|
a41c76 |
virSecurityManagerMetadataLock(virSecurityManagerPtr mgr,
|
|
|
a41c76 |
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
|
|
|
a41c76 |
index 21279e7622..d7362327e6 100644
|
|
|
a41c76 |
--- a/src/security/security_selinux.c
|
|
|
a41c76 |
+++ b/src/security/security_selinux.c
|
|
|
a41c76 |
@@ -271,6 +271,20 @@ virSecuritySELinuxTransactionRun(pid_t pid G_GNUC_UNUSED,
|
|
|
a41c76 |
|
|
|
a41c76 |
if (!(state = virSecurityManagerMetadataLock(list->manager, paths, npaths)))
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < list->nItems; i++) {
|
|
|
a41c76 |
+ virSecuritySELinuxContextItemPtr item = list->items[i];
|
|
|
a41c76 |
+ size_t j;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (j = 0; j < state->nfds; j++) {
|
|
|
a41c76 |
+ if (STREQ_NULLABLE(item->path, state->paths[j]))
|
|
|
a41c76 |
+ break;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* If path wasn't locked, don't try to remember its label. */
|
|
|
a41c76 |
+ if (j == state->nfds)
|
|
|
a41c76 |
+ item->remember = false;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
rv = 0;
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.1
|
|
|
a41c76 |
|