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

12991f
From 72b8c0856ace652a57145ea58b0bec9d67d23851 Mon Sep 17 00:00:00 2001
12991f
From: Eduardo Otubo <otubo@redhat.com>
12991f
Date: Tue, 7 Apr 2020 07:03:37 +0200
12991f
Subject: [PATCH] seccomp: set the seccomp filter to all threads
12991f
MIME-Version: 1.0
12991f
Content-Type: text/plain; charset=UTF-8
12991f
Content-Transfer-Encoding: 8bit
12991f
12991f
RH-Author: Eduardo Otubo <otubo@redhat.com>
12991f
Message-id: <20200305125537.4031-1-otubo@redhat.com>
12991f
Patchwork-id: 94159
12991f
O-Subject: [RHEL-7.9 qemu-kvm-rhev PATCH] seccomp: set the seccomp filter to all threads
12991f
Bugzilla: 1618504 1622976
12991f
RH-Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
12991f
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
12991f
RH-Acked-by: Mohammed Gamal <mgamal@redhat.com>
12991f
12991f
BZ: 1618504
12991f
BRANCH: rhv78/master
12991f
BREW: 27052907
12991f
12991f
commit 70dfabeaa79ba4d7a3b699abe1a047c8012db114
12991f
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
12991f
Date:   Wed Aug 22 19:02:50 2018 +0200
12991f
12991f
    When using "-seccomp on", the seccomp policy is only applied to the
12991f
    main thread, the vcpu worker thread and other worker threads created
12991f
    after seccomp policy is applied; the seccomp policy is not applied to
12991f
    e.g. the RCU thread because it is created before the seccomp policy is
12991f
    applied and SECCOMP_FILTER_FLAG_TSYNC isn't used.
12991f
12991f
    This can be verified with
12991f
    for task in /proc/`pidof qemu`/task/*; do cat $task/status | grep Secc ; done
12991f
    Seccomp:	2
12991f
    Seccomp:	0
12991f
    Seccomp:	0
12991f
    Seccomp:	2
12991f
    Seccomp:	2
12991f
    Seccomp:	2
12991f
12991f
    Starting with libseccomp 2.2.0 and kernel >= 3.17, we can use
12991f
    seccomp_attr_set(ctx, > SCMP_FLTATR_CTL_TSYNC, 1) to update the policy
12991f
    on all threads.
12991f
12991f
    libseccomp requirement was bumped to 2.2.0 in previous patch.
12991f
    libseccomp should fail to set the filter if it can't honour
12991f
    SCMP_FLTATR_CTL_TSYNC (untested), and thus -sandbox will now fail on
12991f
    kernel < 3.17.
12991f
12991f
    Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
12991f
    Acked-by: Eduardo Otubo <otubo@redhat.com>
12991f
12991f
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
12991f
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
12991f
---
12991f
 qemu-seccomp.c | 5 +++++
12991f
 1 file changed, 5 insertions(+)
12991f
12991f
diff --git a/qemu-seccomp.c b/qemu-seccomp.c
12991f
index b770a77..a5455af 100644
12991f
--- a/qemu-seccomp.c
12991f
+++ b/qemu-seccomp.c
12991f
@@ -108,6 +108,11 @@ int seccomp_start(uint32_t seccomp_opts)
12991f
         goto seccomp_return;
12991f
     }
12991f
 
12991f
+    rc = seccomp_attr_set(ctx, SCMP_FLTATR_CTL_TSYNC, 1);
12991f
+    if (rc != 0) {
12991f
+        goto seccomp_return;
12991f
+    }
12991f
+
12991f
     for (i = 0; i < ARRAY_SIZE(blacklist); i++) {
12991f
         if (!(seccomp_opts & blacklist[i].set)) {
12991f
             continue;
12991f
-- 
12991f
1.8.3.1
12991f