Skip to content

Commit 1a30291

Browse files
committed
tests: add support for session ID user filter
test: RFE: add a session ID filter to the kernel's user filter linux-audit/audit-kernel#4 Signed-off-by: Richard Guy Briggs <[email protected]>
1 parent 5cf464c commit 1a30291

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

tests/sessionid_filter/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/sessionid_filter/test

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
5+
use Test;
6+
BEGIN { plan tests => 3 }
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+
# reset audit
24+
system("auditctl -D >& /dev/null");
25+
26+
# create stdout/stderr sinks
27+
(my $fh_out, my $stdout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-out-XXXX',
28+
UNLINK => 1);
29+
(my $fh_err, my $stderr) = tempfile(TEMPLATE => '/tmp/audit-testsuite-err-XXXX',
30+
UNLINK => 1);
31+
(my $fh_ses, my $sesout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-tmp-XXXX',
32+
UNLINK => 1);
33+
(my $fh_pid, my $pidout) = tempfile(TEMPLATE => '/tmp/audit-testsuite-tmp-XXXX',
34+
UNLINK => 1);
35+
36+
###
37+
# tests
38+
39+
my $result;
40+
41+
# discover our sesssion ID
42+
system("cat /proc/self/sessionid > $sesout");
43+
my $sessionid = <$fh_ses>;
44+
chomp($sessionid);
45+
46+
# create a key and rule
47+
my $key = key_gen();
48+
$result = system("auditctl -a always,exit -F arch=b64 -F path=/tmp/$key -F sessionid=$sessionid -k $key");
49+
ok($result, 0);
50+
51+
# send the userspace message (NOTE: requires bash)
52+
system("echo \$\$ > $pidout; exec touch /tmp/$key");
53+
my $pid = <$fh_pid>;
54+
chomp($pid);
55+
56+
# test for the SYSCALL message
57+
$result = system("ausearch -i -m SYSCALL -sc open -p $pid --session $sessionid -k $key > $stdout 2> $stderr");
58+
ok($result, 0);
59+
60+
# test if we generate the PATH record correctly
61+
my $line;
62+
my $found_path_msg = 0;
63+
my $syscall_msg_match = 0;
64+
while ($line = <$fh_out>) {
65+
# test if we generate a PATH record
66+
if ($line =~ m?^type=PATH ? and
67+
$line =~ m? name=/tmp/$key ? and
68+
$line =~ m? nametype=CREATE ?) {
69+
$found_path_msg = 1;
70+
}
71+
# test if SYSCALL record matches
72+
if ($line =~ m?^type=SYSCALL ? and
73+
$line =~ m? pid=$pid ? and
74+
$line =~ m? ses=$sessionid ? and
75+
$line =~ m? key=$key ?) {
76+
$syscall_msg_match = 1;
77+
}
78+
}
79+
ok($found_path_msg && $syscall_msg_match);
80+
81+
###
82+
# cleanup
83+
84+
system("auditctl -D >& /dev/null");
85+

0 commit comments

Comments
 (0)