1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/capability.h>
10 #include "../kselftest.h"
12 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 19)
13 # define HAVE_GETAUXVAL
16 static bool bool_arg(char **argv, int i)
18 if (!strcmp(argv[i], "0"))
20 else if (!strcmp(argv[i], "1"))
23 ksft_exit_fail_msg("wrong argv[%d]\n", i);
28 int main(int argc, char **argv)
30 const char *atsec = "";
34 * Be careful just in case a setgid or setcapped copy of this
39 ksft_exit_fail_msg("wrong argc\n");
42 if (getauxval(AT_SECURE))
43 atsec = " (AT_SECURE is set)";
45 atsec = " (AT_SECURE is not set)";
48 ret = capng_get_caps_process();
50 ksft_print_msg("capng_get_caps_process failed\n");
54 if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) {
55 ksft_print_msg("Wrong effective state%s\n", atsec);
59 if (capng_have_capability(CAPNG_PERMITTED, CAP_NET_BIND_SERVICE) != bool_arg(argv, 2)) {
60 ksft_print_msg("Wrong permitted state%s\n", atsec);
64 if (capng_have_capability(CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 3)) {
65 ksft_print_msg("Wrong inheritable state%s\n", atsec);
69 if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_NET_BIND_SERVICE, 0, 0, 0) != bool_arg(argv, 4)) {
70 ksft_print_msg("Wrong ambient state%s\n", atsec);
74 ksft_print_msg("%s: Capabilities after execve were correct\n",