~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to tests/regression/apparmor/changehat_misc.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
#       Copyright (C) 2002-2005 Novell/SUSE
 
3
#
 
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
 
7
#       License.
 
8
 
 
9
#=NAME changehat_misc
 
10
#=DESCRIPTION 
 
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.
 
14
#=END
 
15
 
 
16
pwd=`dirname $0`
 
17
pwd=`cd $pwd ; /bin/pwd`
 
18
 
 
19
bin=$pwd
 
20
 
 
21
. $bin/prologue.inc
 
22
 
 
23
file=$tmpdir/file
 
24
subfile=$tmpdir/file2
 
25
okperm=rw
 
26
 
 
27
subtest=sub
 
28
subtest2=sub2
 
29
 
 
30
touch $file $subfile
 
31
 
 
32
# NO CHANGEHAT TEST
 
33
 
 
34
genprofile $file:$okperm
 
35
 
 
36
runchecktest "NO CHANGEHAT (access parent file)" pass nochange $file
 
37
runchecktest "NO CHANGEHAT (access sub file)" fail nochange $subfile
 
38
 
 
39
# CHANGEHAT TEST - test if can enter and exit a subprofile
 
40
 
 
41
genprofile $file:$okperm hat:$subtest $subfile:$okperm
 
42
 
 
43
runchecktest "CHANGEHAT (access parent file)" pass $subtest $file
 
44
runchecktest "CHANGEHAT (access sub file)" fail $subtest $subfile
 
45
 
 
46
# CHANGEHAT - test enter subprofile -> fork -> exit subprofile
 
47
settest changehat_misc2
 
48
 
 
49
genprofile $file:$okperm hat:$subtest $subfile:$okperm
 
50
 
 
51
runchecktest "FORK BETWEEN CHANGEHATS (access parent file)" pass $subtest $file
 
52
runchecktest "FORK BETWEEN CHANGEHATS (access sub file)" fail $subtest $subfile
 
53
 
 
54
# CHANGEHAT FROM ONE SUBPROFILE TO ANOTHER
 
55
settest changehat_twice
 
56
 
 
57
genprofile hat:$subtest $subfile:$okperm hat:$subtest2 $file:$okperm
 
58
 
 
59
runchecktest "CHANGEHAT (subprofile->subprofile)" pass $subtest $subtest2 goodmagic $file
 
60
 
 
61
echo
 
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
 
64
 
 
65
# 1. ATTEMPT TO CHANGEHAT TO AN INVALID PROFILE, SHOULD PUT US INTO A NULL
 
66
#    PROFILE
 
67
# 2. ATTEMPT TO CHANGEHAT OUT WITH BAD TOKEN
 
68
settest changehat_fail
 
69
 
 
70
genprofile hat:$subtest
 
71
 
 
72
runchecktest "CHANGEHAT (bad subprofile)" fail ${subtest2}
 
73
 
 
74
echo
 
75
echo "*** A 'Killed' message from bash is expected for the following test"
 
76
runchecktest "CHANGEHAT (bad token)" signal9 ${subtest}
 
77
 
 
78
# Attempt to changehat out of a profile when the magic token is 0
 
79
# ugh, need dynlibs from open test
 
80
settest open
 
81
open_dynlibs=${dynlibs}
 
82
settest changehat_wrapper
 
83
 
 
84
genprofile hat:open ${dynlibs} ${bin}/open:rix ${file}:${okperm}
 
85
 
 
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}
 
88
 
 
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}
 
102
fi
 
103
 
 
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