~ubuntu-branches/ubuntu/raring/apparmor/raring

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/capabilities.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-03-23 16:42:01 UTC
  • Revision ID: james.westby@ubuntu.com-20070323164201-jkax6f0oku087b7l
Tags: upstream-2.0.1+510.dfsg
ImportĀ upstreamĀ versionĀ 2.0.1+510.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# $Id: capabilities.sh 429 2007-03-08 21:00:12Z steve-beattie $
 
3
 
 
4
#       Copyright (C) 2002-2005 Novell/SUSE
 
5
#
 
6
#       This program is free software; you can redistribute it and/or
 
7
#       modify it under the terms of the GNU General Public License as
 
8
#       published by the Free Software Foundation, version 2 of the
 
9
#       License.
 
10
 
 
11
#=NAME capabilities
 
12
#=DESCRIPTION 
 
13
# The capabilities test is an attempt to determine that for a variety of 
 
14
# syscalls, the expected capability (especially since Immunix intercepts 
 
15
# capability processing for confined processes) and no others allows successful
 
16
# access.  For every syscall in the test, we iterate over each capability 
 
17
# individually (plus no capabilities) in order to verify that only the expected
 
18
# capability grants access to the priviledged operation. The same is repeated 
 
19
# for capabilities within hats.
 
20
#=END
 
21
 
 
22
# An attempt to verify what subdomain/posix capabilities actually grant
 
23
# access to. This overlaps _a lot_ with the syscall test.
 
24
# this now verifies that a capability functions within a changehat().
 
25
# FIXME: should test for a cap in the parent, but the need for the cap
 
26
# within the subprofile.  Wow. oogly.
 
27
 
 
28
pwd=`dirname $0`
 
29
pwd=`cd $pwd ; /bin/pwd`
 
30
bin=$pwd
 
31
 
 
32
. ./prologue.inc
 
33
 
 
34
TESTS="syscall_ptrace syscall_sysctl syscall_sethostname \
 
35
       syscall_setdomainname syscall_setpriority syscall_setscheduler \
 
36
       syscall_reboot syscall_chroot \
 
37
       syscall_mlockall net_raw"
 
38
# FIXME/XXX - need a test case for syscall_mknod
 
39
 
 
40
#only do the ioperm/iopl tests for x86 derived architectures
 
41
case `uname -i` in
 
42
i386 | i486 | i586 | i686 | x86 | x86_64) 
 
43
        TESTS="$TESTS syscall_ioperm syscall_iopl"
 
44
        ;;
 
45
esac
 
46
 
 
47
CAPABILITIES="chown dac_override dac_read_search fowner fsetid kill \
 
48
              setgid setuid setpcap linux_immutable net_bind_service \
 
49
              net_broadcast net_admin net_raw ipc_lock ipc_owner \
 
50
              sys_module sys_rawio sys_chroot sys_ptrace sys_pacct \
 
51
              sys_admin sys_boot sys_nice sys_resource sys_time \
 
52
              sys_tty_config mknod lease audit_write audit_control"
 
53
 
 
54
# defines which test+capability pairs should succeed.
 
55
syscall_reboot_sys_boot=TRUE
 
56
syscall_sethostname_sys_admin=TRUE
 
57
syscall_setdomainname_sys_admin=TRUE
 
58
syscall_setpriority_sys_nice=TRUE
 
59
syscall_setscheduler_sys_nice=TRUE
 
60
syscall_ioperm_sys_rawio=TRUE
 
61
syscall_iopl_sys_rawio=TRUE
 
62
syscall_chroot_sys_chroot=TRUE
 
63
syscall_mlockall_ipc_lock=TRUE
 
64
syscall_sysctl_sys_admin=TRUE
 
65
net_raw_net_raw=TRUE
 
66
 
 
67
# we completely disable ptrace(), but it's not clear if we should allow it
 
68
# when the sys_ptrace cap is specified.
 
69
# syscall_ptrace_sys_ptrace=TRUE
 
70
 
 
71
# if a test case requires arguments, add them here.
 
72
syscall_reboot_args=off
 
73
syscall_sethostname_args=a.dumb.example.com
 
74
syscall_setdomainname_args=dumb.example.com
 
75
syscall_ioperm_args="0 0x3ff"
 
76
syscall_iopl_args=3
 
77
syscall_chroot_args=${tmpdir}
 
78
 
 
79
# if a testcase requires extra subdomain rules, add them here
 
80
syscall_chroot_extra_entries="/:r ${tmpdir}:r"
 
81
 
 
82
testwrapper=changehat_wrapper
 
83
 
 
84
# needed for modern linux kernels
 
85
ulimit -l 0
 
86
 
 
87
for TEST in ${TESTS} ; do 
 
88
        echo "        (${TEST#syscall_})"
 
89
        my_arg=$(eval echo \${${TEST}_args})
 
90
        my_entries=$(eval echo \${${TEST}_extra_entries})
 
91
 
 
92
        settest ${TEST}
 
93
        runchecktest "${TEST} -- unconfined" pass ${my_arg}
 
94
        genprofile ${my_entries}
 
95
        runchecktest "${TEST} -- no caps" fail ${my_arg}
 
96
 
 
97
        # iterate through each of the capabilities
 
98
        for cap in ${CAPABILITIES} ; do
 
99
                if [ "X$(eval echo \${${TEST}_${cap}})" == "XTRUE" ] ; then
 
100
                        expected_result=pass
 
101
                else
 
102
                        expected_result=fail
 
103
                fi
 
104
                genprofile cap:${cap} ${my_entries}
 
105
                runchecktest "${TEST} -- capability ${cap}" ${expected_result} ${my_arg}
 
106
        done
 
107
 
 
108
        # okay, now check to see if the capability functions from within
 
109
        # a subprofile.
 
110
        # Eww, this is ugly. subprofile tests depend on the internal
 
111
        # variable dynlibs defined by prologue.inc::settest
 
112
        test_dynlibs=${dynlibs}
 
113
        settest ${testwrapper}
 
114
        genprofile hat:${TEST} ${test_dynlibs} ${bin}/${TEST}:rix ${my_entries}
 
115
        runchecktest "${TEST} changehat -- no caps" fail ${TEST} ${my_arg}
 
116
        for cap in ${CAPABILITIES} ; do
 
117
                if [ "X$(eval echo \${${TEST}_${cap}})" == "XTRUE" ] ; then
 
118
                        expected_result=pass
 
119
                else
 
120
                        expected_result=fail
 
121
                fi
 
122
                genprofile hat:${TEST} ${test_dynlibs} ${bin}/${TEST}:rix cap:${cap} ${my_entries}
 
123
                runchecktest "${TEST} changehat -- capability ${cap}" ${expected_result} ${TEST} ${my_arg}
 
124
        done
 
125
 
 
126
done
 
127