1d442bb
From: Stefan Hajnoczi <stefanha@redhat.com>
1d442bb
Date: Mon, 27 Jan 2020 19:01:28 +0000
1d442bb
Subject: [PATCH] virtiofsd: move to an empty network namespace
1d442bb
MIME-Version: 1.0
1d442bb
Content-Type: text/plain; charset=UTF-8
1d442bb
Content-Transfer-Encoding: 8bit
1d442bb
1d442bb
If the process is compromised there should be no network access.  Use an
1d442bb
empty network namespace to sandbox networking.
1d442bb
1d442bb
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442bb
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442bb
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442bb
(cherry picked from commit d74830d12ae233186ff74ddf64c552d26bb39e50)
1d442bb
---
1d442bb
 tools/virtiofsd/passthrough_ll.c | 14 ++++++++++++++
1d442bb
 1 file changed, 14 insertions(+)
1d442bb
1d442bb
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
1d442bb
index 0570453eef..27ab328722 100644
1d442bb
--- a/tools/virtiofsd/passthrough_ll.c
1d442bb
+++ b/tools/virtiofsd/passthrough_ll.c
1d442bb
@@ -1944,6 +1944,19 @@ static void print_capabilities(void)
1d442bb
     printf("}\n");
1d442bb
 }
1d442bb
 
1d442bb
+/*
1d442bb
+ * Called after our UNIX domain sockets have been created, now we can move to
1d442bb
+ * an empty network namespace to prevent TCP/IP and other network activity in
1d442bb
+ * case this process is compromised.
1d442bb
+ */
1d442bb
+static void setup_net_namespace(void)
1d442bb
+{
1d442bb
+    if (unshare(CLONE_NEWNET) != 0) {
1d442bb
+        fuse_log(FUSE_LOG_ERR, "unshare(CLONE_NEWNET): %m\n");
1d442bb
+        exit(1);
1d442bb
+    }
1d442bb
+}
1d442bb
+
1d442bb
 /* This magic is based on lxc's lxc_pivot_root() */
1d442bb
 static void setup_pivot_root(const char *source)
1d442bb
 {
1d442bb
@@ -2035,6 +2048,7 @@ static void setup_mount_namespace(const char *source)
1d442bb
  */
1d442bb
 static void setup_sandbox(struct lo_data *lo)
1d442bb
 {
1d442bb
+    setup_net_namespace();
1d442bb
     setup_mount_namespace(lo->source);
1d442bb
 }
1d442bb