apparmor/tests/regression/subdomain
John Johansen 0320e0e849 Update changeprofile tests
Have the parser skip the caches
2009-08-20 23:46:48 +00:00
..
netdomain 2007-04-08 07:54:29 +00:00
scripts Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
TODO Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
access.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
access.sh access.patch 2007-12-23 01:03:39 +00:00
AppArmor.rtf Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
capabilities.sh net-raw.patch 2007-12-23 01:06:09 +00:00
changehat.c regression tests for changehat returning eperm when an application is unconfined and tries to do a changehat 2006-10-24 22:15:32 +00:00
changehat.h Update changeprofile tests 2009-08-20 23:46:48 +00:00
changehat.sh changehat-no-hats.patch 2007-12-23 01:06:30 +00:00
changehat_fail.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_fork.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_fork.sh fix_changehat_fork.patch 2007-12-23 01:06:49 +00:00
changehat_misc.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_misc.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_misc2.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_pthread.c start of 10.3 test update 2007-12-23 00:58:47 +00:00
changehat_twice.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changehat_wrapper.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
changeprofile.c start of some changeprofile tests 2009-08-20 04:13:08 +00:00
changeprofile.sh Update changeprofile tests 2009-08-20 23:46:48 +00:00
chdir.c Add a testcase for fchdir, and test steps to verify we didn't break 2007-04-30 18:40:42 +00:00
chdir.sh Add a testcase for fchdir, and test steps to verify we didn't break 2007-04-30 18:40:42 +00:00
chgrp.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
chmod.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
chown.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
clone.c Fix the clone regression test so that the correct end of the stack is 2009-07-28 02:17:10 +00:00
clone.sh Add a testcase to verify when clone() is allowed. 2007-03-08 23:40:10 +00:00
coredump.c Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
coredump.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
deleted.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
deleted.sh deleted-open-revalidate.patch 2007-12-23 01:00:19 +00:00
dropprivs_wrapper.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
env_check.c [This corresponds to commits 6414, 6415, 6417, 6422, 6423, and 6424 in 2006-09-12 05:55:31 +00:00
env_check.sh need these fixes for the regression tests to run on ubuntu 2007-03-24 00:59:27 +00:00
environ.c [This corresponds to commits 6414, 6415, 6417, 6422, 6423, and 6424 in 2006-09-12 05:55:31 +00:00
environ.sh This checkin fixes the environ.sh to work on 64bit systems (with /lib64/ 2006-09-15 22:39:59 +00:00
epilogue.inc fix fatal errors so that they don't exit with an exit code of 0 when no 2008-03-28 07:17:14 +00:00
exec.c Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
exec.sh merge over r1151 - update to exec.sh test which allows it to run on 2008-03-27 01:16:40 +00:00
exec_qual.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
exec_qual.sh confined.patch 2007-12-23 01:02:00 +00:00
exec_qual2.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
fchdir.c Add a testcase for fchdir, and test steps to verify we didn't break 2007-04-30 18:40:42 +00:00
fchdir.sh chdir.patch 2007-12-23 01:03:58 +00:00
fchgrp.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
fchmod.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
fchown.c Add testcases for fchmod/fchown and clean up some formatting in the 2007-03-08 00:09:47 +00:00
fork.c Run fork.c through lindent. 2007-03-06 20:13:31 +00:00
fork.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
i18n.sh start of 10.3 test update 2007-12-23 00:58:47 +00:00
link.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
link.sh make the link subset test livable 2007-12-23 01:07:16 +00:00
link_subset.c update link_subset test, to include child x 2008-06-04 05:59:11 +00:00
link_subset.sh add missing link subset tests 2008-02-18 11:19:11 +00:00
longpath.sh make longpath a default test 2008-03-08 04:17:40 +00:00
Makefile start of some changeprofile tests 2009-08-20 04:13:08 +00:00
mkdir.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
mkdir.sh dir-files.patch 2007-12-23 01:00:56 +00:00
mkprofile.pl network-base.patch 2007-12-23 01:04:46 +00:00
mmap.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
mmap.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
mount.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
mount.sh Update mount test to allow for cability sys_admin, allowing mount and unmount 2009-07-08 21:35:28 +00:00
mult_mount.sh dir-files.patch 2007-12-23 01:00:56 +00:00
named_pipe.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
named_pipe.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
net_raw.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
net_raw.sh net-raw.patch 2007-12-23 01:06:09 +00:00
open.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
open.sh Add the ability to mark as test as a known_fail or known_pass, 2007-12-23 01:10:29 +00:00
openat.c Add tests to openat to test what names apparmor sees when a rename 2007-03-14 19:53:10 +00:00
openat.sh Add the ability to mark as test as a known_fail or known_pass, 2007-12-23 01:10:29 +00:00
owlsm.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
pipe.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
pipe.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
prologue.inc Fix library resolution when linux-vdso.so.1 is used instead of 2009-08-20 12:33:29 +00:00
ptrace.c Update ptrace test 2008-03-27 17:27:39 +00:00
ptrace.sh start of some changeprofile tests 2009-08-20 04:13:08 +00:00
ptrace_helper.c Update ptrace test 2008-03-27 17:27:39 +00:00
pwrite.c Fix up warning on 64bit platforms 2006-06-21 04:55:48 +00:00
pwrite.sh start of 10.3 test update 2007-12-23 00:58:47 +00:00
readdir.c Fix a compilation error on ubuntu; wondering if there's older distros 2008-10-08 19:43:28 +00:00
readdir.sh dir-files.patch 2007-12-23 01:00:56 +00:00
README This checkin fixes the environ.sh to work on 64bit systems (with /lib64/ 2006-09-15 22:39:59 +00:00
regex.sh This patch adds m support to the regression tests 2006-08-04 17:15:41 +00:00
rename.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
rename.sh dir-files.patch 2007-12-23 01:00:56 +00:00
rw.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
rw.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
sd_flags.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
setattr.sh Based on a patch from jjohansen@suse.de, does s/constrained/confined/ in 2007-03-08 21:23:17 +00:00
strace.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
swap.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
swap.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
symlink.c add tests for mediate of the creation of the symlink link file. Remove the patch from for-mainline since it is no longer necessary 2007-03-23 17:31:32 +00:00
symlink.sh add tests for mediate of the creation of the symlink link file. Remove the patch from for-mainline since it is no longer necessary 2007-03-23 17:31:32 +00:00
syscall.sh sysctl.patch 2007-12-23 01:02:50 +00:00
syscall_chroot.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_ioperm.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_iopl.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_mknod.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_mlockall.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_ptrace.c ptrace.patch 2007-12-23 01:00:33 +00:00
syscall_query_module.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_reboot.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_setdomainname.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_sethostname.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_setpriority.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_setscheduler.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_sysctl.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
syscall_sysctl.sh add more missing files 2008-03-08 02:49:17 +00:00
sysctl_proc.c Fix a compilation error on ubuntu; wondering if there's older distros 2008-10-08 19:43:28 +00:00
tcp.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
tcp.sh Add a test for cap net_bind_service w/tcp. Alas, this test is still 2007-03-07 18:54:28 +00:00
unix_fd_client.c Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
unix_fd_server.c Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
unix_fd_server.sh Based on a patch from jjohansen@suse.de, does s/constrained/confined/ in 2007-03-08 21:23:17 +00:00
unlink.c Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
unlink.sh Set svn:keyword attributes on everything, kill Makefile rule for 2006-05-19 17:32:14 +00:00
uservars.inc Update changeprofile tests 2009-08-20 23:46:48 +00:00
xattrs.c Import the rest of the core functionality of the internal apparmor 2006-04-11 21:52:54 +00:00
xattrs.sh dir-files.patch 2007-12-23 01:00:56 +00:00

Running tests
=============

Type "make tests" at the shell prompt, this will make the subprograms
and run the tests.

You must be root to execute make tests (a requirement of subdomain).

(There is also a 'make alltests', which adds a test for bug that, when
triggered, would cause the kernel to crash.)

Test output
===========

No output is displayed for a passing test.  The makefile will output
	running <testname> for each test.

Output other than this indicates a problem.

There are three typical failure scenarios:
	- Test failed when it was expected to pass
	- Test passed when it was expected to fail
	- Unexpected shell error - the test harness encountered an unexpected
		error.


Changing environment variables
==============================

Common user changeable environment variables are stored in the file
'uservars.inc'.  Currently the path to the tmp directory, the path
to the subdomain_parser executable, and any additional arguments to give
to the parser are specified in this configuration file.

(Note: the tmp directory specified in uservars.inc will have an added
random string appended to it by the mktemp(1) program.)

Debugging test failures
=======================

In the event of a failure run the individual test harness using the -r (or 
-retain) option.  This will not remove the temporary test directory and will 
display it's path.  Inside the directory is a script called 'runtest' which 
will rerun the last failed command. 

Example:

# sh unlink.sh -r
Files retained in: /tmp/sdtest.25406-19681

#ls -l /tmp/sdtest.25406-19681
total 3
-rw-r--r--    1 root     root            0 Jul  2 11:51 file
-rw-r--r--    1 root     root           25 Jul  2 11:51 output.unlink
-rw-r--r--    1 root     root          182 Jul  2 11:51 profile
-rw-r--r--    1 root     root          292 Jul  2 11:51 runtest


Note that the contents of this directory (when -r is specified) is the output
of the final test contained within the controlling test harness, in this case
unlink.sh.   If the harness passed, then output.unlink will contain the output
from the final run of the executable (which may indicate an expected error).
If there was an unexpected error (failed when pass was expected or passed when
failure was expected, or an unexpected test harness error), the controlling 
test harness will abort processing further tests and the contents of the 
directory will contain the files for the failed subtest.

It may be necessary to create certain temp files in this directory in order to 
have the test function correctly, see the subdomain profile 'profile' in the 
directory in order to determine which files may need to be created to support
the executable.

In order to debug more complicated test failures such as an expected 
shell error (test harness error) it is usually necessary to rerun the test with 
debugging enabled, for example:

# sh -x unlink.sh


Adding new tests
================

The test harness is designed to make adding new tests fairly simply.

Each test consists of one controlling shell script and one or more executable
files.  

The file 'prologue.inc' must be loaded into the shell script.  This file 
contains the controlling logic and supporting shell functions.

By default, prologue.inc assumes the test binary is the same name as the shell
script, with '.sh' removed.  For test scripts with only one executable this 
makes things simple.  You may want to have a single shell script run multiple
executables (syscall.sh for example). In this case, the 'settest' function is
used to select a new binary executable for this test.

The 'genprofile' function generates a profile based on passed arguments.  
The function automatically adds the necessary shared libraries and output 
files necessary to support the execution, it is not necessary to specify 
these manually.  Therefore a call to genprofile without arguments will build 
a profile allowing the executable to run but without any additional access.
Specifying additional arguments to genprofile in the form of <filename>:<perm>
will allow additional access.  

Support for changehat subprofiles is provided by the 'hat:<hatname>'
argument to genprofile. This will create a hat within the profile named
<hatname>. All following rules (file, net, or cap) up to the next "hat:"
argument or the end of the argument list will be included within this hat.

Support for multiple profiles within a single load (for example for
test that want to domain tansition to another profile) is supported by
the "image' argument to genprofile. This keyword preceeded by a '--'
seperator terminates the previous profile and creates a new profile for
the specified executable image.

Together, 'image' and 'hat:' allow complex profiles including subhats and
domain transitions to be specified via a single invocation of genprofile.

[Note: the old "-- subhat=<hatname>" mechanism for specifying hats is
 no longer supported.]

Executing a test is achieved by calling the 'runchecktest' function which
will run either the executable matching the name of the shell script, or 
specified by settest.  The first argument is a brief description of what the
executable does in this mode, which is displayed in the event of an error.
The second argument is either "pass" or "fail" indicating whether the test
is expected to pass or fail.  The executable is expected to output "PASS"
for success and "FAIL: <error message>" in the event of a failure.  If the
executable outputs something other than this, the controlling shell script
will interpret this as a test failure and output "unable to run test sub
executable" and terminate.  Remaining arguments to runchecktest are passed
to the executable as argv[1] .. argv[n].

The runchecktest command executes and checks the test serially.  If a test
requires to be run in the background, so that the shell may do subsequent
operations, such as sending it a signal before checking it's output, this is
accomplished by separately calling 'runtestbg' and 'checktestbg' instead
of calling 'runchecktest'.

Profile loading, replacing and unloading is automatically handled by the 
shell script (via prologue.inc).  Also, cleanup (tempfile removal and 
profile unloading) on exit is automatic.

As an example, the text shell script for exec (exec.sh) is 24 lines and
may be used as a template for creating new simple tests (changehat.sh is
a good template for subprofile tests and rw.sh is a template for tests
requiring signal passing)

	#! /bin/bash
	
	pwd=`dirname $0`
	pwd=`cd $pwd ; pwd`
	
	<bin must be set prior to including prologue.inc. This is the only>
	<requirement placed on the shell script author by prologue.inc>
	bin=$pwd
	
	<prologie.inc must be included before running any tests>
	. $bin/prologue.inc
	
	<variable definitions used by this script?
	file=/bin/true
	okperm=x
	badperm=r
	
	# PASS TEST
	
	<generate a profile allowing x access to /bin/true>
	genprofile $file:$okperm
	
	<run this test (exec) passing /bin/true as argv[1]>
	<check it's output, it is expected to pass>
	runchecktest "EXEC with x" pass $file
	
	# NOLINK PERMTEST
	<generate a new profile allowing only r access to /bin/true>
	<subdomain_parser will automatically be invoked in -r mode>
	genprofile $file:$badperm

	<run this test (exec) passing /bin/true as argv[1]>
	<check it's output, it is expected to FAIL>
	runchecktest "EXEC no x" fail $file

	<Thats it. Exit status $rc is automatically returned by epilogue.inc>

Additional documentation
========================

See the file 'subdomain_test.txt'

Supporting files
================

strace.sh	Not a test harness, used to support strace testing.
mkprofile.sh	Not a test harness, used to generate subdomain profiles.
prologue.inc	Must be dotted (included) into the test harness. Provides
		support routines.
epilogue.inc	Cleanup support, automatically called upon successful or
		unsuccessful exit
uservars.inc	Contains variables that may need to be changed per user.

Makefile	Makefile for building or running tests. Use 'make' to build,
		'make tests' to run.

*.sh		Controlling test harness
*.c		Test executable.

Disabled tests
==============

Symlink mediation (symlink.sh) in AppArmor has been disabled.
It is too easy to defeat by creating a relative symlink and subsequently
moving the link.

Current failures
================

1) Changehat_misc

   THIS IS NOT AN ERROR - per se.
   Two killed messages will be output. 
   This is not an error, rather a sign that bash noticed the kernel had killed 
   a process which was attempting to use a bogus MAGIC number.  Alas, there is 
   no way to get bash to not print this diagnostic

3) Ptrace
	Error: open passed. Test 'STRACE OPEN (x confinement)' 
	was expected to 'fail'
 
   Regression from 2.4.18 to 2.4.20. (We aren't sure on the first
   endpoint, and the problem still happens in 2.4.20-20_imnx_10smp.)

4) Open
	Error: open passed. Test 'OPEN W (create)' was expected to 'fail'

   LSM issue.  Flags passed to inode_permission are 0 if O_CREAT is used to
   open file.  Need to submit a patch to inode_create hook to receive the
   O_RDWR flags. See https://bugs.wirex.com/show_bug.cgi?id=2885