thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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