|
Mark McLoughlin |
dc0cb0 |
From e700e17c3989d32e04ef98c63ac9b9414fefb366 Mon Sep 17 00:00:00 2001
|
|
Mark McLoughlin |
dc0cb0 |
From: Daniel P. Berrange <berrange@redhat.com>
|
|
Mark McLoughlin |
dc0cb0 |
Date: Fri, 3 Jul 2009 10:24:50 +0100
|
|
Mark McLoughlin |
dc0cb0 |
Subject: [PATCH 1/3] Re-label shared and readonly images
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
This patch was posted ages ago here:
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
https://bugzilla.redhat.com/493692
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
But was never posted upstream AFAICT.
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
|
|
Mark McLoughlin |
dc0cb0 |
---
|
|
Mark McLoughlin |
dc0cb0 |
src/security_selinux.c | 27 +++++++++++++++++----------
|
|
Mark McLoughlin |
dc0cb0 |
1 files changed, 17 insertions(+), 10 deletions(-)
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
diff --git a/src/security_selinux.c b/src/security_selinux.c
|
|
Mark McLoughlin |
dc0cb0 |
index ac317d7..db1c27d 100644
|
|
Mark McLoughlin |
dc0cb0 |
--- a/src/security_selinux.c
|
|
Mark McLoughlin |
dc0cb0 |
+++ b/src/security_selinux.c
|
|
Mark McLoughlin |
dc0cb0 |
@@ -24,11 +24,12 @@
|
|
Mark McLoughlin |
dc0cb0 |
#include "virterror_internal.h"
|
|
Mark McLoughlin |
dc0cb0 |
#include "util.h"
|
|
Mark McLoughlin |
dc0cb0 |
#include "memory.h"
|
|
Mark McLoughlin |
dc0cb0 |
-
|
|
Mark McLoughlin |
dc0cb0 |
+#include "logging.h"
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
#define VIR_FROM_THIS VIR_FROM_SECURITY
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
static char default_domain_context[1024];
|
|
Mark McLoughlin |
dc0cb0 |
+static char default_content_context[1024];
|
|
Mark McLoughlin |
dc0cb0 |
static char default_image_context[1024];
|
|
Mark McLoughlin |
dc0cb0 |
#define SECURITY_SELINUX_VOID_DOI "0"
|
|
Mark McLoughlin |
dc0cb0 |
#define SECURITY_SELINUX_NAME "selinux"
|
|
Mark McLoughlin |
dc0cb0 |
@@ -148,8 +149,13 @@ SELinuxInitialize(virConnectPtr conn)
|
|
Mark McLoughlin |
dc0cb0 |
close(fd);
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
ptr = strchrnul(default_image_context, '\n');
|
|
Mark McLoughlin |
dc0cb0 |
- *ptr = '\0';
|
|
Mark McLoughlin |
dc0cb0 |
-
|
|
Mark McLoughlin |
dc0cb0 |
+ if (*ptr == '\n') {
|
|
Mark McLoughlin |
dc0cb0 |
+ *ptr = '\0';
|
|
Mark McLoughlin |
dc0cb0 |
+ strcpy(default_content_context, ptr+1);
|
|
Mark McLoughlin |
dc0cb0 |
+ ptr = strchrnul(default_content_context, '\n');
|
|
Mark McLoughlin |
dc0cb0 |
+ if (*ptr == '\n')
|
|
Mark McLoughlin |
dc0cb0 |
+ *ptr = '\0';
|
|
Mark McLoughlin |
dc0cb0 |
+ }
|
|
Mark McLoughlin |
dc0cb0 |
return 0;
|
|
Mark McLoughlin |
dc0cb0 |
}
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
@@ -275,6 +281,8 @@ SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
|
|
Mark McLoughlin |
dc0cb0 |
{
|
|
Mark McLoughlin |
dc0cb0 |
char ebuf[1024];
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
+ VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
|
|
Mark McLoughlin |
dc0cb0 |
+
|
|
Mark McLoughlin |
dc0cb0 |
if(setfilecon(path, tcon) < 0) {
|
|
Mark McLoughlin |
dc0cb0 |
virSecurityReportError(conn, VIR_ERR_ERROR,
|
|
Mark McLoughlin |
dc0cb0 |
_("%s: unable to set security context "
|
|
Mark McLoughlin |
dc0cb0 |
@@ -299,9 +307,6 @@ SELinuxRestoreSecurityImageLabel(virConnectPtr conn,
|
|
Mark McLoughlin |
dc0cb0 |
char *newpath = NULL;
|
|
Mark McLoughlin |
dc0cb0 |
const char *path = disk->src;
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
- if (disk->readonly || disk->shared)
|
|
Mark McLoughlin |
dc0cb0 |
- return 0;
|
|
Mark McLoughlin |
dc0cb0 |
-
|
|
Mark McLoughlin |
dc0cb0 |
if ((err = virFileResolveLink(path, &newpath)) < 0) {
|
|
Mark McLoughlin |
dc0cb0 |
virReportSystemError(conn, err,
|
|
Mark McLoughlin |
dc0cb0 |
_("cannot resolve symlink %s"), path);
|
|
Mark McLoughlin |
dc0cb0 |
@@ -328,8 +333,13 @@ SELinuxSetSecurityImageLabel(virConnectPtr conn,
|
|
Mark McLoughlin |
dc0cb0 |
{
|
|
Mark McLoughlin |
dc0cb0 |
const virSecurityLabelDefPtr secdef = &vm->def->seclabel;
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
- if (secdef->imagelabel)
|
|
Mark McLoughlin |
dc0cb0 |
+ if (disk->shared) {
|
|
Mark McLoughlin |
dc0cb0 |
+ return SELinuxSetFilecon(conn, disk->src, default_image_context);
|
|
Mark McLoughlin |
dc0cb0 |
+ } else if (disk->readonly) {
|
|
Mark McLoughlin |
dc0cb0 |
+ return SELinuxSetFilecon(conn, disk->src, default_content_context);
|
|
Mark McLoughlin |
dc0cb0 |
+ } else if (secdef->imagelabel) {
|
|
Mark McLoughlin |
dc0cb0 |
return SELinuxSetFilecon(conn, disk->src, secdef->imagelabel);
|
|
Mark McLoughlin |
dc0cb0 |
+ }
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
return 0;
|
|
Mark McLoughlin |
dc0cb0 |
}
|
|
Mark McLoughlin |
dc0cb0 |
@@ -403,9 +413,6 @@ SELinuxSetSecurityLabel(virConnectPtr conn,
|
|
Mark McLoughlin |
dc0cb0 |
|
|
Mark McLoughlin |
dc0cb0 |
if (secdef->imagelabel) {
|
|
Mark McLoughlin |
dc0cb0 |
for (i = 0 ; i < vm->def->ndisks ; i++) {
|
|
Mark McLoughlin |
dc0cb0 |
- if (vm->def->disks[i]->readonly ||
|
|
Mark McLoughlin |
dc0cb0 |
- vm->def->disks[i]->shared) continue;
|
|
Mark McLoughlin |
dc0cb0 |
-
|
|
Mark McLoughlin |
dc0cb0 |
if (SELinuxSetSecurityImageLabel(conn, vm, vm->def->disks[i]) < 0)
|
|
Mark McLoughlin |
dc0cb0 |
return -1;
|
|
Mark McLoughlin |
dc0cb0 |
}
|
|
Mark McLoughlin |
dc0cb0 |
--
|
|
Mark McLoughlin |
dc0cb0 |
1.6.2.5
|
|
Mark McLoughlin |
dc0cb0 |
|