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