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

« back to all changes in this revision

Viewing changes to tests/regression/subdomain/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
 
# $Id: changehat_misc.sh 61 2006-05-19 18:32:14Z 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 changehat_misc
12
 
#=DESCRIPTION 
13
 
# Variety of tests verifying entry to subprofiles and return back to parent.   
14
 
# AppArmor has rigid requirements around the correct use of the magic# token 
15
 
# passed to changehat.
16
 
#=END
17
 
 
18
 
pwd=`dirname $0`
19
 
pwd=`cd $pwd ; /bin/pwd`
20
 
 
21
 
bin=$pwd
22
 
 
23
 
. $bin/prologue.inc
24
 
 
25
 
file=$tmpdir/file
26
 
subfile=$tmpdir/file2
27
 
okperm=rw
28
 
 
29
 
subtest=sub
30
 
subtest2=sub2
31
 
 
32
 
touch $file $subfile
33
 
 
34
 
# NO CHANGEHAT TEST
35
 
 
36
 
genprofile $file:$okperm
37
 
 
38
 
runchecktest "NO CHANGEHAT (access parent file)" pass nochange $file
39
 
runchecktest "NO CHANGEHAT (access sub file)" fail nochange $subfile
40
 
 
41
 
# CHANGEHAT TEST - test if can enter and exit a subprofile
42
 
 
43
 
genprofile $file:$okperm hat:$subtest $subfile:$okperm
44
 
 
45
 
runchecktest "CHANGEHAT (access parent file)" pass $subtest $file
46
 
runchecktest "CHANGEHAT (access sub file)" fail $subtest $subfile
47
 
 
48
 
# CHANGEHAT - test enter subprofile -> fork -> exit subprofile
49
 
settest changehat_misc2
50
 
 
51
 
genprofile $file:$okperm hat:$subtest $subfile:$okperm
52
 
 
53
 
runchecktest "FORK BETWEEN CHANGEHATS (access parent file)" pass $subtest $file
54
 
runchecktest "FORK BETWEEN CHANGEHATS (access sub file)" fail $subtest $subfile
55
 
 
56
 
# CHANGEHAT FROM ONE SUBPROFILE TO ANOTHER
57
 
settest changehat_twice
58
 
 
59
 
genprofile hat:$subtest $subfile:$okperm hat:$subtest2 $file:$okperm
60
 
 
61
 
runchecktest "CHANGEHAT (subprofile->subprofile)" pass $subtest $subtest2 goodmagic $file
62
 
 
63
 
echo
64
 
echo "*** A 'Killed' message from bash is expected for the following test"
65
 
runchecktest "CHANGEHAT (subprofile->subprofile w/ bad magic)" signal9 $subtest $subtest2 badmagic $file
66
 
 
67
 
# 1. ATTEMPT TO CHANGEGAT TO AN INVALUD PROFILE, SHOULD PUT US INTO A NULL
68
 
#    PROFILE
69
 
# 2. ATTEMPT TO CHANGEHAT OUT WITH BAD TOKEN
70
 
settest changehat_fail
71
 
 
72
 
genprofile hat:$subtest
73
 
 
74
 
runchecktest "CHANGEHAT (bad subprofile)" fail ${subtest2}
75
 
 
76
 
echo
77
 
echo "*** A 'Killed' message from bash is expected for the following test"
78
 
runchecktest "CHANGEHAT (bad token)" signal9 ${subtest}
79
 
 
80
 
# Attempt to changehat out of a profile when the magic token is 0
81
 
# ugh, need dynlibs from open test
82
 
settest open
83
 
open_dynlibs=${dynlibs}
84
 
settest changehat_wrapper
85
 
 
86
 
genprofile hat:open ${dynlibs} ${bin}/open:rix ${file}:${okperm}
87
 
 
88
 
runchecktest "CHANGEHAT (noexit subprofile (token=0))" pass --token=0 open ${file}
89
 
runchecktest "CHANGEHAT (exit noexit subprofile (token=0))" fail --token=0 --exit_hat open ${file}
90
 
 
91
 
if [ -f /proc/self/attr/current ] ; then
92
 
# do some tests of writing directly to /proc/self/attr/current, skipping
93
 
# libimmunx. Only do these tests if the extended attribute exists.
94
 
runchecktest "CHANGEHAT (subprofile/write to /proc/attr/current)" pass --manual=123456 open ${file}
95
 
runchecktest "CHANGEHAT (exit subprofile/write to /proc/attr/current)" pass --manual=123456 --exit_hat open ${file}
96
 
runchecktest "CHANGEHAT (noexit subprofile/write 0 to /proc/attr/current)" pass --manual=0 open ${file}
97
 
runchecktest "CHANGEHAT (noexit subprofile/write 00000000 to /proc/attr/current)" pass --manual=00000000 open ${file}
98
 
# verify that the kernel accepts the command "changehat ^hat\0" and
99
 
# treats an empty token as 0.
100
 
runchecktest "CHANGEHAT (noexit subprofile/write \"\" to /proc/attr/current)" fail --manual="" open ${file}
101
 
runchecktest "CHANGEHAT (exit of noexit subprofile/write 0 to /proc/attr/current)" fail --manual=0 --exit_hat open ${file}
102
 
runchecktest "CHANGEHAT (exit of noexit subprofile/write 00000000 to /proc/attr/current)" fail --manual=00000000 --exit_hat open ${file}
103
 
runchecktest "CHANGEHAT (exit of noexit subprofile/write \"\" to /proc/attr/current)" fail --manual="" --exit_hat open ${file}
104
 
fi
105
 
 
106
 
# CHANGEHAT and PTHREADS: test that change_hat functions correctly in
107
 
# the presence of threads
108
 
settest changehat_pthread
109
 
genprofile $file:$okperm "/proc/**:w" hat:fez $subfile:$okperm "/proc/**:w"
110
 
runchecktest "CHANGEHAT PTHREAD (access parent file)" fail $file
111
 
runchecktest "CHANGEHAT PTHREAD (access sub file)" pass $subfile