]> granicus.if.org Git - strace/blobdiff - tests/seccomp-filter-v.c
strace: terminate itself if interrupted by a signal
[strace] / tests / seccomp-filter-v.c
index 5adb6717a4358bb3736809d75b94ec6df84ae2b3..a6fb07816318fe7e22d09a10479e2387d260d831 100644 (file)
@@ -2,29 +2,10 @@
  * Check verbose decoding of seccomp SECCOMP_SET_MODE_FILTER.
  *
  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016-2018 The strace developers.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "tests.h"
@@ -41,9 +22,7 @@
 #ifdef HAVE_LINUX_SECCOMP_H
 # include <linux/seccomp.h>
 #endif
-#ifdef HAVE_LINUX_FILTER_H
-# include <linux/filter.h>
-#endif
+#include <linux/filter.h>
 
 #if defined __NR_seccomp \
  && defined PR_SET_NO_NEW_PRIVS \
@@ -90,17 +69,13 @@ static const struct sock_filter filter_c[] = {
        SOCK_FILTER_KILL_PROCESS
 };
 
-#ifndef BPF_MAXINSNS
-# define BPF_MAXINSNS 4096
-#endif
-
 int
 main(void)
 {
        tprintf("%s", "");
 
        static const char kill_stmt_txt[] =
-               "BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL)";
+               "BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL_THREAD)";
        struct sock_filter *const filter =
                tail_memdup(filter_c, sizeof(filter_c));
        struct sock_filter *const big_filter =
@@ -123,7 +98,7 @@ main(void)
        prog->len = 3;
        syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER, 0, prog);
        tprintf("seccomp(SECCOMP_SET_MODE_FILTER, 0, {len=%u"
-               ", filter=[%s, %p]}) = -1 EFAULT (%m)\n",
+               ", filter=[%s, ... /* %p */]}) = -1 EFAULT (%m)\n",
                prog->len, kill_stmt_txt, filter +  ARRAY_SIZE(filter_c));
 
        prog->len = 0;
@@ -141,11 +116,13 @@ main(void)
        prog->filter = big_filter;
        prog->len = BPF_MAXINSNS + 1;
        tprintf("seccomp(SECCOMP_SET_MODE_FILTER, %s, {len=%u, filter=[",
-               "SECCOMP_FILTER_FLAG_TSYNC|0xfffffffe", prog->len);
+               "SECCOMP_FILTER_FLAG_TSYNC|SECCOMP_FILTER_FLAG_LOG|"
+               "SECCOMP_FILTER_FLAG_SPEC_ALLOW|0xfffffff8",
+               prog->len);
        for (i = 0; i < BPF_MAXINSNS; ++i) {
                if (i)
                        tprintf(", ");
-               switch(BPF_CLASS(i)) {
+               switch (BPF_CLASS(i)) {
                case BPF_LD:
                        tprintf("BPF_STMT(BPF_LD|BPF_W|BPF_IMM, %#x)", i << 16);
                        break;