Skip to content

Commit fc1e398

Browse files
Gautam-Menghanikees
authored andcommitted
selftests/seccomp: Check CAP_SYS_ADMIN capability in the test mode_filter_without_nnp
In the "mode_filter_without_nnp" test in seccomp_bpf, there is currently a TODO which asks to check the capability CAP_SYS_ADMIN instead of euid. This patch adds support to check if the calling process has the flag CAP_SYS_ADMIN, and also if this flag has CAP_EFFECTIVE set. Signed-off-by: Gautam Menghani <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 247f34f commit fc1e398

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ TEST(mode_filter_without_nnp)
392392
.filter = filter,
393393
};
394394
long ret;
395+
cap_t cap = cap_get_proc();
396+
cap_flag_value_t is_cap_sys_admin = 0;
395397

396398
ret = prctl(PR_GET_NO_NEW_PRIVS, 0, NULL, 0, 0);
397399
ASSERT_LE(0, ret) {
@@ -400,8 +402,8 @@ TEST(mode_filter_without_nnp)
400402
errno = 0;
401403
ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog, 0, 0);
402404
/* Succeeds with CAP_SYS_ADMIN, fails without */
403-
/* TODO(wad) check caps not euid */
404-
if (geteuid()) {
405+
cap_get_flag(cap, CAP_SYS_ADMIN, CAP_EFFECTIVE, &is_cap_sys_admin);
406+
if (!is_cap_sys_admin) {
405407
EXPECT_EQ(-1, ret);
406408
EXPECT_EQ(EACCES, errno);
407409
} else {

0 commit comments

Comments
 (0)