Blame SOURCES/kvm-seccomp-set-the-seccomp-filter-to-all-threads.patch

73f313
From d01fad2a8757f4e3b449a888b93a0ba9fda54daa Mon Sep 17 00:00:00 2001
73f313
From: Eduardo Otubo <otubo@redhat.com>
73f313
Date: Thu, 5 Mar 2020 13:49:51 +0100
73f313
Subject: [PATCH 6/6] seccomp: set the seccomp filter to all threads
73f313
MIME-Version: 1.0
73f313
Content-Type: text/plain; charset=UTF-8
73f313
Content-Transfer-Encoding: 8bit
73f313
73f313
Message-id: <20200305134951.23851-1-otubo@redhat.com>
73f313
Patchwork-id: 94161
73f313
O-Subject: [RHEL-7.9 qemu-kvm PATCH] seccomp: set the seccomp filter to all threads
73f313
Bugzilla: 1618503
73f313
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
73f313
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
73f313
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
73f313
73f313
commit 70dfabeaa79ba4d7a3b699abe1a047c8012db114
73f313
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
73f313
Date:   Wed Aug 22 19:02:50 2018 +0200
73f313
73f313
    When using "-seccomp on", the seccomp policy is only applied to the
73f313
    main thread, the vcpu worker thread and other worker threads created
73f313
    after seccomp policy is applied; the seccomp policy is not applied to
73f313
    e.g. the RCU thread because it is created before the seccomp policy is
73f313
    applied and SECCOMP_FILTER_FLAG_TSYNC isn't used.
73f313
73f313
    This can be verified with
73f313
    for task in /proc/`pidof qemu`/task/*; do cat $task/status | grep Secc ; done
73f313
    Seccomp:	2
73f313
    Seccomp:	0
73f313
    Seccomp:	0
73f313
    Seccomp:	2
73f313
    Seccomp:	2
73f313
    Seccomp:	2
73f313
73f313
    Starting with libseccomp 2.2.0 and kernel >= 3.17, we can use
73f313
    seccomp_attr_set(ctx, > SCMP_FLTATR_CTL_TSYNC, 1) to update the policy
73f313
    on all threads.
73f313
73f313
    libseccomp requirement was bumped to 2.2.0 in previous patch.
73f313
    libseccomp should fail to set the filter if it can't honour
73f313
    SCMP_FLTATR_CTL_TSYNC (untested), and thus -sandbox will now fail on
73f313
    kernel < 3.17.
73f313
73f313
    Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
73f313
    Acked-by: Eduardo Otubo <otubo@redhat.com>
73f313
73f313
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
73f313
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
73f313
---
73f313
 qemu-seccomp.c | 5 +++++
73f313
 1 file changed, 5 insertions(+)
73f313
73f313
diff --git a/qemu-seccomp.c b/qemu-seccomp.c
73f313
index e947909..828083b 100644
73f313
--- a/qemu-seccomp.c
73f313
+++ b/qemu-seccomp.c
73f313
@@ -264,6 +264,11 @@ int seccomp_start(void)
73f313
         goto seccomp_return;
73f313
     }
73f313
 
73f313
+    rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1);
73f313
+    if (rc != 0) {
73f313
+        goto seccomp_return;
73f313
+    }
73f313
+
73f313
     for (i = 0; i < ARRAY_SIZE(seccomp_whitelist); i++) {
73f313
         rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, seccomp_whitelist[i].num, 0);
73f313
         if (rc < 0) {
73f313
-- 
73f313
1.8.3.1
73f313