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