(root)/
strace-6.5/
tests/
seccomp-strict.c
       1  /*
       2   * Check how seccomp SECCOMP_SET_MODE_STRICT is decoded.
       3   *
       4   * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2016-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #include <stdio.h>
      15  #include <unistd.h>
      16  
      17  int
      18  main(void)
      19  {
      20  	static const char text1[] =
      21  		"seccomp(SECCOMP_SET_MODE_STRICT, 0, NULL) = 0\n";
      22  	static const char text2[] = "+++ exited with 0 +++\n";
      23  	const kernel_ulong_t addr = (kernel_ulong_t) 0xfacefeeddeadbeefULL;
      24  	long rc;
      25  
      26  	rc = syscall(__NR_seccomp, -1L, -1L, addr);
      27  	printf("seccomp(%#x /* SECCOMP_SET_MODE_??? */, %#x, %#llx)"
      28  	       " = %s\n", -1, -1, (unsigned long long) addr, sprintrc(rc));
      29  	fflush(stdout);
      30  
      31  	rc = syscall(__NR_seccomp, 0, 0, 0);
      32  	if (rc) {
      33  		printf("seccomp(SECCOMP_SET_MODE_STRICT, 0, NULL) = %s\n",
      34  		       sprintrc(rc));
      35  		fflush(stdout);
      36  		rc = 0;
      37  	} else {
      38  		/*
      39  		 * If kernel implementation of SECCOMP_MODE_STRICT is buggy,
      40  		 * the following syscall will result to SIGKILL.
      41  		 */
      42  		rc = write(1, text1, LENGTH_OF(text1)) != LENGTH_OF(text1);
      43  	}
      44  
      45  	rc += write(1, text2, LENGTH_OF(text2)) != LENGTH_OF(text2);
      46  	return !!syscall(__NR_exit, rc);
      47  }