Giter VIP home page Giter VIP logo

audit-testsuite's People

Contributors

jankara avatar maxenglander avatar olsajiri avatar pcmoore avatar rgbriggs avatar the-mule avatar wonder93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

audit-testsuite's Issues

BUG: lost_reset is stubbornly failing on my aarch64 test system (again)

The lost_reset test continues to be the most fragile test in this test suite. What was once happening occasionally appears to happening with more frequency. Example test failure:

Running as   user    root
        with context unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
        on   system  Fedora

backlog_wait_time_actual_reset/test .. ok
exec_execve/test ..................... ok
exec_name/test ....................... ok
file_create/test ..................... ok
file_delete/test ..................... ok
file_rename/test ..................... ok
filter_exclude/test .................. ok
filter_saddr_fam/test ................ ok
filter_sessionid/test ................ ok
login_tty/test ....................... ok
# Test 4 got: "0" (lost_reset/test at line 166)
#   Expected: "1"
#  lost_reset/test line 166 is: ok( $found_msg, 1 );              # Was the message well-formed?
# Failed test 5 in lost_reset/test at line 167
#  lost_reset/test line 167 is: ok( $reset_rc == $reset_msg );    # Do the two lost values agree?
lost_reset/test ...................... 
Failed 2/5 subtests 
netfilter_pkt/test ................... ok
syscalls_file/test ................... ok
syscall_module/test .................. ok
time_change/test ..................... ok
user_msg/test ........................ ok
fanotify/test ........................ ok
bpf/test ............................. ok

Test Summary Report
-------------------
lost_reset/test                    (Wstat: 0 Tests: 5 Failed: 2)
  Failed tests:  4-5
Files=18, Tests=202, 53 wallclock secs ( 0.17 usr  0.04 sys +  8.67 cusr  3.32 csys = 12.20 CPU)
Result: FAIL
Failed 1/18 test programs. 2/202 subtests failed.

exec_name fail

system("auditctl -a always,exit -S all -F exe=$exec -k $key");
-F unknown field: exe

Maybe should system("auditctl -a always,exit -S all -F path=$exec -k $key"); ??

RFE: recent audit userspace changes make the test suite noisy

A recent audit-userspace change (linux-audit/audit-userspace@958b1ce) has made the test suite output very noisy, for example:

% make test
make -C tests test
...
chmod +x */test
Running as   user    root
        with context unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
        on   system  Fedora

backlog_wait_time_actual_reset/test .. 1/5 q_depth should be larger than 512 for safety margin
backlog_wait_time_actual_reset/test .. ok   
exec_execve/test ..................... q_depth should be larger than 512 for safety margin
exec_execve/test ..................... ok
...

BUG: Debian instructions missing libc6-dev-i386

On Ubuntu 16.04, the instructions in README.md lead to:

cc -g -O0 -Wall -D_GNU_SOURCE -m32 -o conn conn.c
In file included from /usr/include/unistd.h:25:0,
                 from conn.c:1:
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
Makefile:8: recipe for target 'conn' failed

Fixed with:

diff --git a/README.md b/README.md
index 625a684..c6124c7 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,7 @@ please follow the instructions below.
        # apt-get install auditd \
                          build-essential \
                          libc6-i386 \
+                         libc6-dev-i386 \
                          perl-modules \
                          netcat

RFE: add tests for auditing specific syscalls

For a first attempt it should be sufficient to audit a single syscall and verify things are working correctly, we can grow the list over time if necessary. The important part will be to ensure that the chosen syscall is supported on all platforms, e.g. open(...).

RFE: Basic Event Validation

It would be good to have a test for at least basic event validation. Sometimes events are malformed even though there is a guidance for creating audit events. Since we have fields dictionary and quire clear requirements for events now it might be possible to create a test detecting malformed events.

RFE: check for audit_filter_rules() cred memory leak

Commit c69e8d9c01db ("CRED: Use RCU to access another task's creds and to
release a task's own creds") introduced a cred struct memory leak when the second of the three return conditions in the audit_filter_rules() didn't call put_cred() to match the initial get_task_cred(). This second exit condition tests if a subsequent rule has a higher priority and if it does not it simply exits, but should first call put_cred().

Test for this condition by looking for a matching number of cred_jar entries in the slab.

BUG: fix references to b64 on generic tests

Several tests have embedded references to 64-bit architecture rules when they may be run on 32-bit architecture machines. Convert them from "-F arch=b64" to "-F arch=b$ENV{MODE}".

tests/filter_sessionid/test:
"auditctl -a always,exit -F arch=b64 -F path=/tmp/$key -F sessionid=$sessionid -k $key"
tests/syscall_module/test:
"auditctl -a always,exit -F arch=b64 -S init_module -S finit_module -k $key-load"
tests/syscall_module/test:
system("auditctl -a always,exit -F arch=b64 -S delete_module -k $key-unload");
tests_manual/syscall_module_path_filter/setup:
echo "-a always,exit -F arch=b64 -S init_module -S finit_module -k ghak8-mod-load" ...

BUG: lost_reset fails to lose messages on some systems, failing test

Some recent systems appear to be so robust that provoking lost messages is proving difficult if not impossible. The offending commit appears to be:
5a6f30a ("lost_reset: spin until msg lost")

@pmoore's method of deleting the "-F pid=$ping_pid" argument to the "auditctl -a ..." line of tests/lost_reset/test succeeds on these stubborn systems to trigger lost messages, but is pretty saddistic on any kernel, worse on older ones.

Q: why can't we run multiple instances of the testsuite simultaneously?

If we attempt to run the multiple instances of the testsuite simultaneously we hit a number of failures. While this was never an explicit goal of the testsuite, it can be handy at times for use as a crude stress test for the audit system (lock verification, etc.). There is nothing inherent in the design of the tests that should prevent multiple simultaneous instances so it would be good to understand why this is a problem in practice.

BUG: sporadic failures in lost_reset

Lately I've been seeing sporadic test failures in the lost_reset test. I haven't had an opportunity to debug these failures to the level of determining the root cause, so I'm creating this issue to track the history/progress of the bug.

@The-Mule I believe you have been seeing these failures too in some automated test runs, any chance you have looked into this at all?

@rgbriggs This test has been pretty reliable for me up until recently, have you noticed any failures?

RFE: test for audit container ID functionality

Test for kernel audit container id functionality:

  • prohibit unsetting
  • prohibit self-setting
  • prohibit setting again
  • prohibit without CAP_AUDIT_CONTROL
  • verify AUDIT_CONTAINER record
  • verify auditctl containerid filter
  • verify kernel AUDIT_CONTAINERID filter functionality
  • verify AUDIT_CONTAINER_INFO record

See: linux-audit/audit-kernel#32
See: linux-audit/audit-kernel#90
See: linux-audit/audit-kernel#91
See: linux-audit/audit-kernel#92
See: linux-audit/audit-userspace#40
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID

BUG: filter_exclude fails when execute in specific context

SElinux context is parsed in filter_exclude test incorrectly:

if($subj =~ /([^:]+):([^:]+):([^:]+):([^-]+)-([^-]+)/) {
        ($subj_user, $subj_role, $subj_type, $subj_sen, $subj_clr) = ($1, $2, $3, $4, $5);
}

When there is no clearance (eg. system_u:unconfined_r:unconfined_t:s0 [*]) parsing will not work. The following regex works: ([^:]+):([^:]+):([^:]+):([^-]+)-?([^-]+)?.

Please notice that clearance is used in several places of the test and hence we need to fix those parts as well.

[*] FYI, when I am running testsuite via Beaker, tests are executed with this context.

Reproducer: runcon system_u:unconfined_r:unconfined_t:s0 make tests

BUG: compilation error on Fedora 38

Compilation of tests/syscall_socketcall fails with the following error:

make[2]: Entering directory '/mnt/tests/CoreOS/audit/Sanity/audit-rules-smoke/audit-testsuite/tests/syscall_socketcall'
cc -g -O0 -Wall -D_GNU_SOURCE -m32 -o conn conn.c
In file included from /usr/include/features.h:527,
                 from /usr/include/unistd.h:25,
                 from conn.c:1:
/usr/include/gnu/stubs.h:6:11: fatal error: gnu/stubs-32.h: No such file or directory
    6 | # include <gnu/stubs-32.h>
      |           ^~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:8: conn] Error 1
make[2]: Leaving directory '/mnt/tests/CoreOS/audit/Sanity/audit-rules-smoke/audit-testsuite/tests/syscall_socketcall'

In gnu/stubs.h, I have:

/* This file is automatically generated.
   This file selects the right generated file of `__stub_FUNCTION' macros
   based on the architecture being compiled for.  */

#if !defined __x86_64__
# include <gnu/stubs-32.h>
#endif
#if defined __x86_64__ && defined __LP64__
# include <gnu/stubs-64.h>
#endif
#if defined __x86_64__ && defined __ILP32__
# include <gnu/stubs-x32.h>
#endif

The <gnu/stubs-32.h> lib is included if __x86_64__ is not defined. However, this is not available. The reason why x86_64 is undefined, is because we are passing -m32 to the compiler in https://github.com/linux-audit/audit-testsuite/blob/main/tests/syscall_socketcall/Makefile#L8 .

Removing -m32 helps with the compilation, but I think it's there for a reason. Introduced in e276b30 . Any suggestion is appreciated.

RFE: add test for fanotify events

Based on its settings fanotify subsystem can produce type=FANOTIFY events. We need a test that audit records are created only when it is needed and that they are associated with other records (PROCTITLE, SYSCALL, CWD, PATH).

Q: accomodate tests for known issues for which fix does not yet exist

There are tests that exist for issues (bugs) that are known but for which there does not yet exist a solution (fix, mitigation, patch).

How do we accommodate those tests into the repo while allowing the testsuite to pass?

Potential solutions:

  • I originally wanted to have them in their intended target location ("tests") but simply omit the test name from "tests/Makefile" so it gets skipped over, a bit like we do for different vintages of kernels or distros.

  • Having them in a separate branch and merging them when a fix is upstream leaves them out of the way, but makes things inconvenient for developers switching back and forth and adding more branches than necessary, one per test.

  • They could go in a directory similar to "tests-manual" called "tests-pending" and when ready its sub-directory gets "git mv" into "tests" and update "tests/Makefile".

  • Don't merge the test at all until the fix is upstream.

I'd prefer the first, third, then second, fourth, in that order.

BUG: tests fail on RHEL-7

The testsuite fails on RHEL7, likely due to changes between RHEL7 and upstream. Older RHEL releases are likely also affected.

RFE: test audit signal and ptrace functionality

Add a test to verify basic functionality of the ptrace and signal of the audit daemon.

When ptrace is run on a task, verify an AUDIT_OBJ_PID record is recorded on syscall exit of the ptrace task.

When a signal (TERM|HUP|USR1|USR2) is delivered to the audit daemon, test that a request for AUDIT_SIGNAL_INFO is correctly returned.

When signal logging is configured in audit, verify all signals delivered to a task are recorded on syscall exit of that target task.

Q: what to do with stress tests and potentially destructive tests?

We don't want to include stress tests and/or potentially destructive tests in the standard audit-testsuite, but this doesn't mean we don't want to track these tests for occasional, manual testing. This issue has been created to discuss how best to handle these tests.

BUG: bpf tests fail on aarch64

The bpf tests fail on aarch64 because the test's bpf program fails with EPERM, even run as root on a system with SELinux in permissive mode. The failure does not occur on a similarly configured x86_64 system.
Here is a strace of the bpf program on a Fedora Rawhide aarch64 system:

# strace ./bpf
execve("./bpf", ["./bpf"], 0xffffd43251e0 /* 28 vars */) = 0
brk(NULL)                               = 0xeb27000
faccessat(AT_FDCWD, "/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=35846, ...}) = 0
mmap(NULL, 35846, PROT_READ, MAP_PRIVATE, 3, 0) = 0xffffb37a9000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0\267\0\1\0\0\0\20C\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=3036328, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xffffb37a7000
mmap(NULL, 1530744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xffffb35ff000
mprotect(0xffffb375a000, 73728, PROT_NONE) = 0
mmap(0xffffb376c000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15d000) = 0xffffb376c000
mmap(0xffffb3772000, 11128, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xffffb3772000
close(3)                                = 0
mprotect(0xffffb376c000, 12288, PROT_READ) = 0
mprotect(0x41f000, 4096, PROT_READ)     = 0
mprotect(0xffffb37b4000, 4096, PROT_READ) = 0
munmap(0xffffb37a9000, 35846)           = 0
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0xffffe2d64bc0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0}, 120) = -1 EPERM (Operation not permitted)
exit_group(-1)                          = ?
+++ exited with 255 +++

BUG: tests should not depend on environment variables

One of the goals for this testsuite was to be able to use individual tests as reproducers in bug reports (here and on the various distribution bug trackers). While it is possible to simply point bug assignees to the entire testsuite, it is sometimes very helpful to include an individual test script in the bug tracker. However, in order to include the test script, the test script must have minimal dependencies on the audit-testsuite test infrastructure; this includes the use of $ENV{...} in the scripts.

Currently affected tests include:

# grep -l "ENV" $(find . -name "test")
./tests/filter_exclude/test
./tests/syscalls_file/test
./tests/exec_execve/test

In each of these cases it is the MODE variable which is referenced in the test scripts. We should investigate the possibility of doing the arch/ABI detection in the scripts themselves.

BUG: filter_exclude test fails to parse minimal selinux context

filter_exclude test expected an selinux context of the form:
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
while failing to parse the valid form:
system_u:unconfined_r:unconfined_t:s0

Recommend using the previously parsed values $selinux_* from tests/runtests.pl

RFE: test logging of EXECVE arguments

We need to make sure that we test the following:

  • large numbers of arguments (force multiple EXECVE records)
  • large argument sizes (split across multiple EXECVE records)
  • "bad" characters which force hex encoding
  • "bad" characters which force hex encoding and cause the argument to be recorded in multiple EXECVE records when it wouldn't normally

NOTE: "bad" characters are currently defined as ASCII 0x21, 0x22, and 0x7e.

RFE: Testing module for common subroutines

There are several patterns used in tests which can be moved to our testing module to avoid duplication and speed up the process of writing new tests. Each test works more or less as follows:

  1. Setup: add new audit rules and temporary files.
  2. Trigger: generate audit events.
  3. Verification: verify that correct events were generated.
  4. Clean-up: restore audit rules and remove temporary files.

At the moment, I see the following candidates of "common subroutines" for this testing module:

  1. Setup: unique key generation, audit rules backup, auditd conf backup, create temporary files
  2. Trigger: none, this is usually very specific to tested functionality
  3. Verification: traversing audit event to check it meets specification
  4. Clean-up: restore rules and configuration, remove temporary files

As I mentioned somewhere else, clean-up should be handled as a list of callbacks so that it can be called by a signal handler (to make sure it always happens).

What do you think? I will prepare some example in a separate branch to have some code to discuss.

Q: why does tests/Makefile override PATH?

PATH=/usr/bin:/bin:/usr/sbin:/sbin \

^^^ I just spent the last hour figuring out why the testsuite doesn't work with locally installed audit userspace binaries until I found this line... Does it serve any particular purpose? Can we please remove it and let the user of the testsuite set the PATH variable as it suits them?

BUG: syscalls_file only works on 64-bit systems

The problem is the following line in the syscalls_file/test file:

$result = system("auditctl -a always,exit -F arch=b64 -S open -k $key");

... which results in the following error on 32-bit x86:

# auditctl -a always,exit -F arch=b64 -S open
arch elf mapping not found

RFE: improved documentation for installing and running the testsuite

Right now the README isn't very complete when it comes documentation about installing and running the tests. At the very least we should have instructions for the different supported RHEL versions and upstream/Rawhide; ideally we would have instructions for non Red Hat distributions too, e.g. Debian/Ubuntu.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.