2
# $Id: capabilities.sh 429 2007-03-08 21:00:12Z steve-beattie $
4
# Copyright (C) 2002-2005 Novell/SUSE
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
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.
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.
29
pwd=`cd $pwd ; /bin/pwd`
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
40
#only do the ioperm/iopl tests for x86 derived architectures
42
i386 | i486 | i586 | i686 | x86 | x86_64)
43
TESTS="$TESTS syscall_ioperm syscall_iopl"
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"
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
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
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"
77
syscall_chroot_args=${tmpdir}
79
# if a testcase requires extra subdomain rules, add them here
80
syscall_chroot_extra_entries="/:r ${tmpdir}:r"
82
testwrapper=changehat_wrapper
84
# needed for modern linux kernels
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})
93
runchecktest "${TEST} -- unconfined" pass ${my_arg}
94
genprofile ${my_entries}
95
runchecktest "${TEST} -- no caps" fail ${my_arg}
97
# iterate through each of the capabilities
98
for cap in ${CAPABILITIES} ; do
99
if [ "X$(eval echo \${${TEST}_${cap}})" == "XTRUE" ] ; then
104
genprofile cap:${cap} ${my_entries}
105
runchecktest "${TEST} -- capability ${cap}" ${expected_result} ${my_arg}
108
# okay, now check to see if the capability functions from within
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
122
genprofile hat:${TEST} ${test_dynlibs} ${bin}/${TEST}:rix cap:${cap} ${my_entries}
123
runchecktest "${TEST} changehat -- capability ${cap}" ${expected_result} ${TEST} ${my_arg}