Skip to content

Commit 13b829a

Browse files
The-Mulepcmoore
authored andcommitted
tests/filter_exit: add test for filter_exit
Signed-off-by: Ondrej Moris <[email protected]> [PM: merge fuzz, subj tweak] Signed-off-by: Paul Moore <[email protected]>
1 parent 6f8c12d commit 13b829a

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

tests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ TESTS := \
2424
file_permission \
2525
file_rename \
2626
filter_exclude \
27+
filter_exit \
2728
filter_saddr_fam \
2829
filter_sessionid \
2930
io_uring \

tests/filter_exit/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
TARGETS=$(patsubst %.c,%,$(wildcard *.c))
2+
3+
LDLIBS += -lpthread
4+
5+
all: $(TARGETS)
6+
clean:
7+
rm -f $(TARGETS)
8+

tests/filter_exit/test

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
5+
use Test;
6+
BEGIN { plan tests => 4 }
7+
8+
use File::Temp qw/ tempdir tempfile /;
9+
10+
###
11+
# functions
12+
13+
sub key_gen {
14+
my @chars = ( "A" .. "Z", "a" .. "z" );
15+
my $key = "testsuite-" . time . "-";
16+
$key .= $chars[ rand @chars ] for 1 .. 8;
17+
return $key;
18+
}
19+
20+
###
21+
# setup
22+
23+
chomp( my $abi_bits = $ENV{MODE} != 0 ? $ENV{MODE} : `getconf LONG_BIT` );
24+
25+
# reset audit
26+
system("auditctl -D >& /dev/null");
27+
28+
# create stdout/stderr sinks
29+
( my $fh_out, my $stdout ) = tempfile(
30+
TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
31+
UNLINK => 1
32+
);
33+
( my $fh_err, my $stderr ) = tempfile(
34+
TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
35+
UNLINK => 1
36+
);
37+
( my $fh_ses, my $sesout ) = tempfile(
38+
TEMPLATE => '/tmp/audit-testsuite-ses-XXXX',
39+
UNLINK => 1
40+
);
41+
( my $fh_pid, my $pidout ) = tempfile(
42+
TEMPLATE => '/tmp/audit-testsuite-pid-XXXX',
43+
UNLINK => 1
44+
);
45+
46+
###
47+
# tests
48+
49+
my $result;
50+
51+
# create a key and rule
52+
my $key = key_gen();
53+
$result = system(
54+
"auditctl -a always,exit -F arch=b$abi_bits -S write -F exit=-EINVAL -k $key"
55+
);
56+
ok( $result, 0 );
57+
58+
# trigger open syscall error EINVAL
59+
$result = system("echo \"TESTING\" > /proc/self/status 2>/dev/null");
60+
ok( $result, 256 );
61+
62+
# make sure the records had a chance to bubble through to the logs
63+
system("auditctl -m syncmarker-$key");
64+
for ( my $i = 0 ; $i < 10 ; $i++ ) {
65+
if ( system("ausearch -m USER | grep -q syncmarker-$key") eq 0 ) {
66+
last;
67+
}
68+
sleep(0.2);
69+
}
70+
71+
# test for the SYSCALL message
72+
$result =
73+
system("ausearch -i -m SYSCALL -sc write -k $key > $stdout 2> $stderr");
74+
ok( $result, 0 );
75+
76+
# test if we generate the SYSCALL record correctly
77+
my $line;
78+
my $syscall_msg_match = 0;
79+
while ( $line = <$fh_out> ) {
80+
81+
# test if SYSCALL record matches
82+
if ( $line =~ m?^type=SYSCALL ?
83+
and $line =~ m? exit=EINVAL?
84+
and $line =~ m? key=$key ? )
85+
{
86+
$syscall_msg_match = 1;
87+
last;
88+
}
89+
}
90+
ok($syscall_msg_match);
91+
92+
###
93+
# cleanup
94+
system("auditctl -D >& /dev/null");

0 commit comments

Comments
 (0)