698723
From 3cf73fa4599116da350a0100378e749bbcbcad37 Mon Sep 17 00:00:00 2001
698723
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
698723
Date: Thu, 26 Nov 2020 11:23:54 +0100
698723
Subject: [PATCH] shared/seccomp-util: address family filtering is broken on
698723
 ppc
698723
698723
This reverts the gist of da1921a5c396547261c8c7fcd94173346eb3b718 and
698723
0d9fca76bb69e162265b2d25cb79f1890c0da31b (for ppc).
698723
698723
Quoting #17559:
698723
> libseccomp 2.5 added socket syscall multiplexing on ppc64(el):
698723
> https://github.com/seccomp/libseccomp/pull/229
698723
>
698723
> Like with i386, s390 and s390x this breaks socket argument filtering, so
698723
> RestrictAddressFamilies doesn't work.
698723
>
698723
> This causes the unit test to fail:
698723
> /* test_restrict_address_families */
698723
> Operating on architecture: ppc
698723
> Failed to install socket family rules for architecture ppc, skipping: Operation canceled
698723
> Operating on architecture: ppc64
698723
> Failed to add socket() rule for architecture ppc64, skipping: Invalid argument
698723
> Operating on architecture: ppc64-le
698723
> Failed to add socket() rule for architecture ppc64-le, skipping: Invalid argument
698723
> Assertion 'fd < 0' failed at src/test/test-seccomp.c:424, function test_restrict_address_families(). Aborting.
698723
>
698723
> The socket filters can't be added so `socket(AF_UNIX, SOCK_DGRAM, 0);` still
698723
> works, triggering the assertion.
698723
698723
Fixes #17559.
698723
698723
(cherry picked from commit d5923e38bc0e6cf9d7620ed5f1f8606fe7fe1168)
698723
698723
Resolves: #1982650
698723
---
698723
 src/shared/seccomp-util.c | 6 +++---
698723
 src/test/test-seccomp.c   | 2 +-
698723
 2 files changed, 4 insertions(+), 4 deletions(-)
698723
698723
diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c
698723
index e903512d45..c57c409433 100644
698723
--- a/src/shared/seccomp-util.c
698723
+++ b/src/shared/seccomp-util.c
698723
@@ -1251,9 +1251,6 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
698723
                 case SCMP_ARCH_X32:
698723
                 case SCMP_ARCH_ARM:
698723
                 case SCMP_ARCH_AARCH64:
698723
-                case SCMP_ARCH_PPC:
698723
-                case SCMP_ARCH_PPC64:
698723
-                case SCMP_ARCH_PPC64LE:
698723
                 case SCMP_ARCH_MIPSEL64N32:
698723
                 case SCMP_ARCH_MIPS64N32:
698723
                 case SCMP_ARCH_MIPSEL64:
698723
@@ -1267,6 +1264,9 @@ int seccomp_restrict_address_families(Set *address_families, bool whitelist) {
698723
                 case SCMP_ARCH_X86:
698723
                 case SCMP_ARCH_MIPSEL:
698723
                 case SCMP_ARCH_MIPS:
698723
+                case SCMP_ARCH_PPC:
698723
+                case SCMP_ARCH_PPC64:
698723
+                case SCMP_ARCH_PPC64LE:
698723
                 default:
698723
                         /* These we either know we don't support (i.e. are the ones that do use socketcall()), or we
698723
                          * don't know */
698723
diff --git a/src/test/test-seccomp.c b/src/test/test-seccomp.c
698723
index 009a2e1922..5eb1c78b8b 100644
698723
--- a/src/test/test-seccomp.c
698723
+++ b/src/test/test-seccomp.c
698723
@@ -25,7 +25,7 @@
698723
 #include "util.h"
698723
 #include "virt.h"
698723
 
698723
-#if SCMP_SYS(socket) < 0 || defined(__i386__) || defined(__s390x__) || defined(__s390__)
698723
+#if SCMP_SYS(socket) < 0 || defined(__i386__) || defined(__s390x__) || defined(__s390__) || defined(__powerpc64__) || defined(__powerpc__)
698723
 /* On these archs, socket() is implemented via the socketcall() syscall multiplexer,
698723
  * and we can't restrict it hence via seccomp. */
698723
 #  define SECCOMP_RESTRICT_ADDRESS_FAMILIES_BROKEN 1