cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
ddf19c
From 19a16f26bdeb6302159736e182a18b06160a3f42 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Mon, 27 Jan 2020 19:01:28 +0100
ddf19c
Subject: [PATCH 057/116] virtiofsd: move to an empty network namespace
ddf19c
MIME-Version: 1.0
ddf19c
Content-Type: text/plain; charset=UTF-8
ddf19c
Content-Transfer-Encoding: 8bit
ddf19c
ddf19c
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
Message-id: <20200127190227.40942-54-dgilbert@redhat.com>
ddf19c
Patchwork-id: 93508
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 053/112] virtiofsd: move to an empty network namespace
ddf19c
Bugzilla: 1694164
ddf19c
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
ddf19c
ddf19c
From: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
If the process is compromised there should be no network access.  Use an
ddf19c
empty network namespace to sandbox networking.
ddf19c
ddf19c
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit d74830d12ae233186ff74ddf64c552d26bb39e50)
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 14 ++++++++++++++
ddf19c
 1 file changed, 14 insertions(+)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index 0570453..27ab328 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -1944,6 +1944,19 @@ static void print_capabilities(void)
ddf19c
     printf("}\n");
ddf19c
 }
ddf19c
 
ddf19c
+/*
ddf19c
+ * Called after our UNIX domain sockets have been created, now we can move to
ddf19c
+ * an empty network namespace to prevent TCP/IP and other network activity in
ddf19c
+ * case this process is compromised.
ddf19c
+ */
ddf19c
+static void setup_net_namespace(void)
ddf19c
+{
ddf19c
+    if (unshare(CLONE_NEWNET) != 0) {
ddf19c
+        fuse_log(FUSE_LOG_ERR, "unshare(CLONE_NEWNET): %m\n");
ddf19c
+        exit(1);
ddf19c
+    }
ddf19c
+}
ddf19c
+
ddf19c
 /* This magic is based on lxc's lxc_pivot_root() */
ddf19c
 static void setup_pivot_root(const char *source)
ddf19c
 {
ddf19c
@@ -2035,6 +2048,7 @@ static void setup_mount_namespace(const char *source)
ddf19c
  */
ddf19c
 static void setup_sandbox(struct lo_data *lo)
ddf19c
 {
ddf19c
+    setup_net_namespace();
ddf19c
     setup_mount_namespace(lo->source);
ddf19c
 }
ddf19c
 
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c