Skip to content

Commit 6bdc497

Browse files
committed
tests: add a test covering forced 32-bit comparisons
Signed-off-by: James Henstridge <james.henstridge@canonical.com>
1 parent bfd93dc commit 6bdc497

File tree

3 files changed

+143
-1
lines changed

3 files changed

+143
-1
lines changed

tests/60-sim-32b_args_on_64b.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Seccomp Library test program
3+
*
4+
* Copyright (c) 2019 Cisco Systems, Inc. <pmoore2@cisco.com>
5+
* Author: Paul Moore <paul@paul-moore.com>
6+
* Additions: Michael Weiser <michael.weiser@gmx.de>
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 <inttypes.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_KILL);
42+
if (ctx == NULL)
43+
return ENOMEM;
44+
45+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1001, 1,
46+
SCMP_A0(SCMP_CMP_NE | SCMP_CMP_32BIT, 0x10));
47+
if (rc != 0)
48+
goto out;
49+
50+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1002, 1,
51+
SCMP_A0(SCMP_CMP_LT | SCMP_CMP_32BIT, 0x10));
52+
if (rc != 0)
53+
goto out;
54+
55+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1003, 1,
56+
SCMP_A0(SCMP_CMP_LE | SCMP_CMP_32BIT, 0x10));
57+
if (rc != 0)
58+
goto out;
59+
60+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1004, 1,
61+
SCMP_A0(SCMP_CMP_EQ | SCMP_CMP_32BIT, 0x10));
62+
if (rc != 0)
63+
goto out;
64+
65+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1005, 1,
66+
SCMP_A0(SCMP_CMP_GE | SCMP_CMP_32BIT, 0x10));
67+
if (rc != 0)
68+
goto out;
69+
70+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1006, 1,
71+
SCMP_A0(SCMP_CMP_GT | SCMP_CMP_32BIT, 0x10));
72+
if (rc != 0)
73+
goto out;
74+
75+
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1007, 1,
76+
SCMP_A0(SCMP_CMP_MASKED_EQ | SCMP_CMP_32BIT, 0xff, 0x10));
77+
if (rc != 0)
78+
goto out;
79+
80+
rc = util_filter_output(&opts, ctx);
81+
if (rc)
82+
goto out;
83+
84+
out:
85+
seccomp_release(ctx);
86+
return (rc < 0 ? -rc : rc);
87+
}

tests/60-sim-32b_args_on_64b.tests

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# libseccomp regression test automation data
3+
#
4+
# Copyright (c) 2019 Cisco Systems, Inc. <pmoore2@cisco.com>
5+
# Author: Paul Moore <paul@paul-moore.com>
6+
#
7+
8+
test type: bpf-sim
9+
10+
# Testname Arch Syscall Arg0 Arg1 Arg2 Arg3 Arg4 Arg5 Result
11+
60-sim-32b_args_on_64b all 1001 0x1 N N N N N ALLOW
12+
60-sim-32b_args_on_64b all 1001 0x10 N N N N N KILL
13+
60-sim-32b_args_on_64b all 1001 0xffffffff00000001 N N N N N ALLOW
14+
60-sim-32b_args_on_64b all 1001 0xffffffff00000010 N N N N N KILL
15+
16+
60-sim-32b_args_on_64b all 1002 0x1 N N N N N ALLOW
17+
60-sim-32b_args_on_64b all 1002 0x20 N N N N N KILL
18+
60-sim-32b_args_on_64b all 1002 0xffffffff00000001 N N N N N ALLOW
19+
60-sim-32b_args_on_64b all 1002 0xffffffff00000020 N N N N N KILL
20+
21+
60-sim-32b_args_on_64b all 1003 0x10 N N N N N ALLOW
22+
60-sim-32b_args_on_64b all 1003 0x20 N N N N N KILL
23+
60-sim-32b_args_on_64b all 1003 0xffffffff00000010 N N N N N ALLOW
24+
60-sim-32b_args_on_64b all 1003 0xffffffff00000020 N N N N N KILL
25+
26+
60-sim-32b_args_on_64b all 1004 0x10 N N N N N ALLOW
27+
60-sim-32b_args_on_64b all 1004 0x20 N N N N N KILL
28+
60-sim-32b_args_on_64b all 1004 0xffffffff00000010 N N N N N ALLOW
29+
60-sim-32b_args_on_64b all 1004 0xffffffff00000020 N N N N N KILL
30+
31+
60-sim-32b_args_on_64b all 1005 0x10 N N N N N ALLOW
32+
60-sim-32b_args_on_64b all 1005 0x01 N N N N N KILL
33+
60-sim-32b_args_on_64b all 1005 0xffffffff00000010 N N N N N ALLOW
34+
60-sim-32b_args_on_64b all 1005 0xffffffff00000001 N N N N N KILL
35+
36+
60-sim-32b_args_on_64b all 1006 0x20 N N N N N ALLOW
37+
60-sim-32b_args_on_64b all 1006 0x01 N N N N N KILL
38+
60-sim-32b_args_on_64b all 1006 0xffffffff00000020 N N N N N ALLOW
39+
60-sim-32b_args_on_64b all 1006 0xffffffff00000001 N N N N N KILL
40+
41+
60-sim-32b_args_on_64b all 1007 0xff10 N N N N N ALLOW
42+
60-sim-32b_args_on_64b all 1007 0x01 N N N N N KILL
43+
60-sim-32b_args_on_64b all 1007 0xffffffff0000ff10 N N N N N ALLOW
44+
60-sim-32b_args_on_64b all 1007 0xffffffff00000001 N N N N N KILL
45+
46+
test type: bpf-sim-fuzz
47+
48+
# Testname StressCount
49+
60-sim-32b_args_on_64b 5
50+
51+
test type: bpf-valgrind
52+
53+
# Testname
54+
60-sim-32b_args_on_64b

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ check_PROGRAMS = \
9494
56-basic-iterate_syscalls \
9595
57-basic-rawsysrc \
9696
58-live-tsync_notify \
97-
59-basic-empty_binary_tree
97+
59-basic-empty_binary_tree \
98+
60-sim-32b_args_on_64b
9899

99100
EXTRA_DIST_TESTPYTHON = \
100101
util.py \

0 commit comments

Comments
 (0)