Skip to content

Commit 361cb24

Browse files
committed
tests: add test 62-sim-arch_transactions
Add a test to verify the logic at the end of db_col_transaction_commit() properly copies and releases the snapshots from the filter when the filter length doesn't match the snapshot length. Signed-off-by: Tom Hromatka <[email protected]> [PM: subj tweak] Signed-off-by: Paul Moore <[email protected]> Signed-off-by: Tom Hromatka <[email protected]>
1 parent 72b0132 commit 361cb24

File tree

5 files changed

+203
-3
lines changed

5 files changed

+203
-3
lines changed

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ util.pyc
6969
59-basic-empty_binary_tree
7070
60-sim-precompute
7171
61-sim-transactions
72+
62-sim-arch_transactions

tests/62-sim-arch_transactions.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Seccomp Library test program
3+
*
4+
* Copyright (c) 2023 Microsoft Corporation <[email protected]>
5+
* Author: Paul Moore <[email protected]>
6+
* Author: Tom Hromatka <[email protected]>
7+
*/
8+
9+
/*
10+
* This library is free software; you can redistribute it and/or modify it
11+
* under the terms of version 2.1 of the GNU Lesser General Public License as
12+
* published by the Free Software Foundation.
13+
*
14+
* This library is distributed in the hope that it will be useful, but WITHOUT
15+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17+
* for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this library; if not, see <http://www.gnu.org/licenses>.
21+
*/
22+
23+
#include <errno.h>
24+
#include <unistd.h>
25+
#include <stdio.h>
26+
27+
#include <seccomp.h>
28+
29+
#include "util.h"
30+
31+
int main(int argc, char *argv[])
32+
{
33+
int rc;
34+
struct util_options opts;
35+
scmp_filter_ctx ctx = NULL;
36+
37+
rc = util_getopt(argc, argv, &opts);
38+
if (rc < 0)
39+
goto out;
40+
41+
ctx = seccomp_init(SCMP_ACT_ALLOW);
42+
if (ctx == NULL)
43+
return ENOMEM;
44+
45+
/* To avoid endian-ness collisions, only run this test against
46+
* x86_64. This will ensure that we can successfully add the "x86"
47+
* architecture later in the test. */
48+
rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
49+
if (rc != 0)
50+
goto out;
51+
rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("x86_64"));
52+
if (rc != 0)
53+
goto out;
54+
55+
rc = seccomp_transaction_start(ctx);
56+
if (rc != 0)
57+
goto out;
58+
rc = seccomp_transaction_start(ctx);
59+
if (rc != 0)
60+
goto out;
61+
62+
rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 0);
63+
if (rc != 0)
64+
goto out;
65+
66+
rc = seccomp_transaction_commit(ctx);
67+
if (rc != 0)
68+
goto out;
69+
70+
rc = seccomp_arch_add(ctx, seccomp_arch_resolve_name("x86"));
71+
if (rc != 0)
72+
goto out;
73+
74+
rc = seccomp_transaction_commit(ctx);
75+
if (rc != 0)
76+
goto out;
77+
78+
rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(write), 0);
79+
if (rc != 0)
80+
goto out;
81+
82+
rc = seccomp_transaction_start(ctx);
83+
if (rc != 0)
84+
goto out;
85+
rc = seccomp_transaction_start(ctx);
86+
if (rc != 0)
87+
goto out;
88+
89+
rc = seccomp_arch_remove(ctx, seccomp_arch_resolve_name("x86"));
90+
if (rc != 0)
91+
goto out;
92+
rc = seccomp_transaction_commit(ctx);
93+
if (rc != 0)
94+
goto out;
95+
96+
rc = seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(open), 0);
97+
if (rc != 0)
98+
goto out;
99+
rc = seccomp_transaction_commit(ctx);
100+
if (rc != 0)
101+
goto out;
102+
103+
rc = util_filter_output(&opts, ctx);
104+
if (rc)
105+
goto out;
106+
107+
out:
108+
seccomp_release(ctx);
109+
return (rc < 0 ? -rc : rc);
110+
}

tests/62-sim-arch_transactions.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
3+
#
4+
# Seccomp Library test program
5+
#
6+
# Copyright (c) 2023 Microsoft Corporation <[email protected]>
7+
# Author: Paul Moore <[email protected]>
8+
# Author: Tom Hromatka <[email protected]>
9+
#
10+
11+
#
12+
# This library is free software; you can redistribute it and/or modify it
13+
# under the terms of version 2.1 of the GNU Lesser General Public License as
14+
# published by the Free Software Foundation.
15+
#
16+
# This library is distributed in the hope that it will be useful, but WITHOUT
17+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
19+
# for more details.
20+
#
21+
# You should have received a copy of the GNU Lesser General Public License
22+
# along with this library; if not, see <http://www.gnu.org/licenses>.
23+
#
24+
25+
import argparse
26+
import sys
27+
28+
import util
29+
30+
from seccomp import *
31+
32+
def test(args):
33+
f = SyscallFilter(ALLOW)
34+
35+
f.remove_arch(Arch())
36+
f.add_arch(Arch("x86_64"))
37+
38+
f.start_transaction()
39+
f.start_transaction()
40+
f.add_rule(KILL, "read")
41+
f.commit_transaction()
42+
f.add_arch(Arch("x86"))
43+
f.commit_transaction()
44+
45+
f.add_rule(KILL, "write")
46+
47+
f.start_transaction()
48+
f.start_transaction()
49+
f.remove_arch(Arch("x86"))
50+
f.commit_transaction()
51+
f.add_rule(KILL, "open")
52+
f.commit_transaction()
53+
54+
return f
55+
56+
args = util.get_opt()
57+
ctx = test(args)
58+
util.filter_output(args, ctx)
59+
60+
# kate: syntax python;
61+
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# libseccomp regression test automation data
3+
#
4+
# Copyright (c) 2023 Microsoft Corporation <[email protected]>
5+
# Author: Paul Moore <[email protected]>
6+
# Author: Tom Hromatka <[email protected]>
7+
#
8+
9+
test type: bpf-sim
10+
11+
# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result
12+
62-sim-arch_transactions +x86_64 read N N N N N N KILL
13+
62-sim-arch_transactions +x86_64 write N N N N N N KILL
14+
62-sim-arch_transactions +x86_64 open N N N N N N KILL
15+
62-sim-arch_transactions +x86_64 close N N N N N N ALLOW
16+
17+
test type: bpf-sim-fuzz
18+
19+
# Testname StressCount
20+
62-sim-arch_transactions 5
21+
22+
test type: bpf-valgrind
23+
24+
# Testname
25+
62-sim-arch_transactions

tests/Makefile.am

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ check_PROGRAMS = \
9696
58-live-tsync_notify \
9797
59-basic-empty_binary_tree \
9898
60-sim-precompute \
99-
61-sim-transactions
99+
61-sim-transactions \
100+
62-sim-arch_transactions
100101

101102
EXTRA_DIST_TESTPYTHON = \
102103
util.py \
@@ -158,7 +159,8 @@ EXTRA_DIST_TESTPYTHON = \
158159
58-live-tsync_notify.py \
159160
59-basic-empty_binary_tree.py \
160161
60-sim-precompute.py \
161-
61-sim-transactions.py
162+
61-sim-transactions.py \
163+
62-sim-arch_transactions.py
162164

163165
EXTRA_DIST_TESTCFGS = \
164166
01-sim-allow.tests \
@@ -221,7 +223,8 @@ EXTRA_DIST_TESTCFGS = \
221223
58-live-tsync_notify.tests \
222224
59-basic-empty_binary_tree.tests \
223225
60-sim-precompute.tests \
224-
61-sim-transactions.tests
226+
61-sim-transactions.tests \
227+
62-sim-arch_transactions.tests
225228

226229
EXTRA_DIST_TESTSCRIPTS = \
227230
38-basic-pfc_coverage.sh 38-basic-pfc_coverage.pfc \

0 commit comments

Comments
 (0)