cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtiofsd-drop-all-capabilities-in-the-wait-parent-p.patch

ddf19c
From 78152453940967f9ece9fe3ffc5017c669d6ec28 Mon Sep 17 00:00:00 2001
ddf19c
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
ddf19c
Date: Tue, 5 May 2020 16:36:00 +0100
ddf19c
Subject: [PATCH 9/9] virtiofsd: drop all capabilities in the wait parent
ddf19c
 process
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: <20200505163600.22956-8-dgilbert@redhat.com>
ddf19c
Patchwork-id: 96274
ddf19c
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 7/7] virtiofsd: drop all capabilities in the wait parent process
ddf19c
Bugzilla: 1817445
ddf19c
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ddf19c
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ddf19c
ddf19c
From: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
ddf19c
All this process does is wait for its child.  No capabilities are
ddf19c
needed.
ddf19c
ddf19c
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
ddf19c
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ddf19c
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ddf19c
(cherry picked from commit 66502bbca37ca7a3bfa57e82cfc03b89a7a11eae)
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 tools/virtiofsd/passthrough_ll.c | 13 +++++++++++++
ddf19c
 1 file changed, 13 insertions(+)
ddf19c
ddf19c
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
ddf19c
index 6358874..f41a6b0 100644
ddf19c
--- a/tools/virtiofsd/passthrough_ll.c
ddf19c
+++ b/tools/virtiofsd/passthrough_ll.c
ddf19c
@@ -2535,6 +2535,17 @@ static void print_capabilities(void)
ddf19c
 }
ddf19c
 
ddf19c
 /*
ddf19c
+ * Drop all Linux capabilities because the wait parent process only needs to
ddf19c
+ * sit in waitpid(2) and terminate.
ddf19c
+ */
ddf19c
+static void setup_wait_parent_capabilities(void)
ddf19c
+{
ddf19c
+    capng_setpid(syscall(SYS_gettid));
ddf19c
+    capng_clear(CAPNG_SELECT_BOTH);
ddf19c
+    capng_apply(CAPNG_SELECT_BOTH);
ddf19c
+}
ddf19c
+
ddf19c
+/*
ddf19c
  * Move to a new mount, net, and pid namespaces to isolate this process.
ddf19c
  */
ddf19c
 static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
ddf19c
@@ -2567,6 +2578,8 @@ static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
ddf19c
         pid_t waited;
ddf19c
         int wstatus;
ddf19c
 
ddf19c
+        setup_wait_parent_capabilities();
ddf19c
+
ddf19c
         /* The parent waits for the child */
ddf19c
         do {
ddf19c
             waited = waitpid(child, &wstatus, 0);
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c