2
# Copyright (C) 2002-2005 Novell/SUSE
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License as
6
# published by the Free Software Foundation, version 2 of the
11
# Variety of tests verifying entry to subprofiles and return back to parent.
12
# AppArmor has rigid requirements around the correct use of the magic# token
13
# passed to changehat.
17
pwd=`cd $pwd ; /bin/pwd`
34
genprofile $file:$okperm
36
runchecktest "NO CHANGEHAT (access parent file)" pass nochange $file
37
runchecktest "NO CHANGEHAT (access sub file)" fail nochange $subfile
39
# CHANGEHAT TEST - test if can enter and exit a subprofile
41
genprofile $file:$okperm hat:$subtest $subfile:$okperm
43
runchecktest "CHANGEHAT (access parent file)" pass $subtest $file
44
runchecktest "CHANGEHAT (access sub file)" fail $subtest $subfile
46
# CHANGEHAT - test enter subprofile -> fork -> exit subprofile
47
settest changehat_misc2
49
genprofile $file:$okperm hat:$subtest $subfile:$okperm
51
runchecktest "FORK BETWEEN CHANGEHATS (access parent file)" pass $subtest $file
52
runchecktest "FORK BETWEEN CHANGEHATS (access sub file)" fail $subtest $subfile
54
# CHANGEHAT FROM ONE SUBPROFILE TO ANOTHER
55
settest changehat_twice
57
genprofile hat:$subtest $subfile:$okperm hat:$subtest2 $file:$okperm
59
runchecktest "CHANGEHAT (subprofile->subprofile)" pass $subtest $subtest2 goodmagic $file
62
echo "*** A 'Killed' message from bash is expected for the following test"
63
runchecktest "CHANGEHAT (subprofile->subprofile w/ bad magic)" signal9 $subtest $subtest2 badmagic $file
65
# 1. ATTEMPT TO CHANGEHAT TO AN INVALID PROFILE, SHOULD PUT US INTO A NULL
67
# 2. ATTEMPT TO CHANGEHAT OUT WITH BAD TOKEN
68
settest changehat_fail
70
genprofile hat:$subtest
72
runchecktest "CHANGEHAT (bad subprofile)" fail ${subtest2}
75
echo "*** A 'Killed' message from bash is expected for the following test"
76
runchecktest "CHANGEHAT (bad token)" signal9 ${subtest}
78
# Attempt to changehat out of a profile when the magic token is 0
79
# ugh, need dynlibs from open test
81
open_dynlibs=${dynlibs}
82
settest changehat_wrapper
84
genprofile hat:open ${dynlibs} ${bin}/open:rix ${file}:${okperm}
86
runchecktest "CHANGEHAT (noexit subprofile (token=0))" pass --token=0 open ${file}
87
runchecktest "CHANGEHAT (exit noexit subprofile (token=0))" fail --token=0 --exit_hat open ${file}
89
if [ -f /proc/self/attr/current ] ; then
90
# do some tests of writing directly to /proc/self/attr/current, skipping
91
# libimmunx. Only do these tests if the extended attribute exists.
92
runchecktest "CHANGEHAT (subprofile/write to /proc/attr/current)" pass --manual=123456 open ${file}
93
runchecktest "CHANGEHAT (exit subprofile/write to /proc/attr/current)" pass --manual=123456 --exit_hat open ${file}
94
runchecktest "CHANGEHAT (noexit subprofile/write 0 to /proc/attr/current)" pass --manual=0 open ${file}
95
runchecktest "CHANGEHAT (noexit subprofile/write 00000000 to /proc/attr/current)" pass --manual=00000000 open ${file}
96
# verify that the kernel accepts the command "changehat ^hat\0" and
97
# treats an empty token as 0.
98
runchecktest "CHANGEHAT (noexit subprofile/write \"\" to /proc/attr/current)" fail --manual="" open ${file}
99
runchecktest "CHANGEHAT (exit of noexit subprofile/write 0 to /proc/attr/current)" fail --manual=0 --exit_hat open ${file}
100
runchecktest "CHANGEHAT (exit of noexit subprofile/write 00000000 to /proc/attr/current)" fail --manual=00000000 --exit_hat open ${file}
101
runchecktest "CHANGEHAT (exit of noexit subprofile/write \"\" to /proc/attr/current)" fail --manual="" --exit_hat open ${file}
104
# CHANGEHAT and PTHREADS: test that change_hat functions correctly in
105
# the presence of threads
106
settest changehat_pthread
107
genprofile $file:$okperm "/proc/**:w" hat:fez $subfile:$okperm "/proc/**:w"
108
runchecktest "CHANGEHAT PTHREAD (access parent file)" fail $file
109
runchecktest "CHANGEHAT PTHREAD (access sub file)" pass $subfile