(root)/
strace-6.5/
tests-mx32/
prctl-cap-ambient.c
       1  /*
       2   * Check decoding of prctl PR_CAP_AMBIENT operations.
       3   *
       4   * Copyright (c) 2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  #include <stdio.h>
      13  #include <unistd.h>
      14  #include <linux/prctl.h>
      15  #include <linux/capability.h>
      16  
      17  int
      18  main(void)
      19  {
      20  	long rc;
      21  
      22  	prctl_marker();
      23  
      24  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE,
      25  				 CAP_NET_RAW, 0, 0);
      26  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_NET_RAW, 0, 0) = %s\n",
      27  		   sprintrc(rc));
      28  
      29  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE,
      30  				 CAP_AUDIT_CONTROL, 0, 0);
      31  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, CAP_AUDIT_CONTROL, 0, 0) = %s\n",
      32  		   sprintrc(rc));
      33  
      34  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, 0xff, 0, 0);
      35  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, 0xff /* CAP_??? */, 0, 0) = %s\n",
      36  		   sprintrc(rc));
      37  
      38  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER,
      39  				 CAP_NET_RAW, 0, 0);
      40  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, CAP_NET_RAW, 0, 0) = %s\n",
      41  		   sprintrc(rc));
      42  
      43  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER,
      44  				 CAP_KILL, 0, 0);
      45  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, CAP_KILL, 0, 0) = %s\n",
      46  		   sprintrc(rc));
      47  
      48  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, 0xff, 0, 0);
      49  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, 0xff /* CAP_??? */, 0, 0) = %s\n",
      50  		   sprintrc(rc));
      51  
      52  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET,
      53  				 CAP_NET_RAW, 0, 0);
      54  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_RAW, 0, 0) = %s\n",
      55  		   sprintrc(rc));
      56  
      57  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET,
      58  				 CAP_AUDIT_CONTROL, 0, 0);
      59  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_AUDIT_CONTROL, 0, 0) = %s\n",
      60  		   sprintrc(rc));
      61  
      62  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, 0xff, 0, 0);
      63  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, 0xff /* CAP_??? */, 0, 0) = %s\n",
      64  		   sprintrc(rc));
      65  
      66  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);
      67  	printf("prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0) = %s\n",
      68  		   sprintrc(rc));
      69  
      70  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, 0xff, 0xaaaa, 0, 0);
      71  	printf("prctl(PR_CAP_AMBIENT, 0xff /* PR_CAP_AMBIENT_??? */, 0xaaaa, 0, 0) = %s\n",
      72  		   sprintrc(rc));
      73  
      74  	rc = syscall(__NR_prctl, PR_CAP_AMBIENT, 0xff, 0xaaaa, 0xbbbb, 0xcccc);
      75  	printf("prctl(PR_CAP_AMBIENT, 0xff /* PR_CAP_AMBIENT_??? */, 0xaaaa, 0xbbbb, 0xcccc) = %s\n",
      76  		   sprintrc(rc));
      77  
      78  	puts("+++ exited with 0 +++");
      79  	return 0;
      80  }