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