~ubuntu-branches/ubuntu/precise/apparmor/precise-security

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Steve Beattie, Jamie Strandboge, Serge Hallyn, Steve Beattie
  • Date: 2012-04-12 06:17:42 UTC
  • Revision ID: package-import@ubuntu.com-20120412061742-9v75hjko2mjtbewv
Tags: 2.7.102-0ubuntu3
[ Jamie Strandboge ]
* debian/patches/0007-ubuntu-manpage-updates.patch: update apparmor(5)
  to describe Ubuntu's two-stage policy load and how to add utilize it
  when developing policy (LP: #974089)

[ Serge Hallyn ]
* debian/apparmor.init: do nothing in a container.  This can be
  removed once stacked profiles are supported and used by lxc.
  (LP: #978297)

[ Steve Beattie ]
* debian/patches/0008-apparmor-lp963756.patch: Fix permission mapping
  for change_profile onexec (LP: #963756)
* debian/patches/0009-apparmor-lp959560-part1.patch,
  debian/patches/0010-apparmor-lp959560-part2.patch: Update the parser
  to support the 'in' keyword for value lists, and make mount
  operations aware of 'in' keyword so they can affect the flags build
  list (LP: #959560)
* debian/patches/0011-apparmor-lp872446.patch: fix logprof missing
  exec events in complain mode (LP: #872446)
* debian/patches/0012-apparmor-lp978584.patch: allow inet6 access in
  dovecot imap-login profile (LP: #978584)
* debian/patches/0013-apparmor-lp800826.patch: fix libapparmor
  log parsing library from dropping apparmor network events that
  contain ip addresses or ports in them (LP: #800826)
* debian/patches/0014-apparmor-lp979095.patch: document new mount rule
  syntax and usage in apparmor.d(5) manpage (LP: #979095)
* debian/patches/0015-apparmor-lp963756.patch: Fix change_onexec
  for profiles without attachment specification (LP: #963756,
  LP: #978038)
* debian/patches/0016-apparmor-lp968956.patch: Fix protocol error when
  loading policy to kernels without compat patches (LP: #968956)
* debian/patches/0017-apparmor-lp979135.patch: Fix change_profile to
  grant access to /proc/attr api (LP: #979135)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
#       Copyright (C) 2012 Canonical, Ltd.
 
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 onexec
 
10
#=DESCRIPTION 
 
11
# Verifies basic file access permission checks for change_onexec
 
12
#=END
 
13
 
 
14
pwd=`dirname $0`
 
15
pwd=`cd $pwd ; /bin/pwd`
 
16
 
 
17
bin=$pwd
 
18
 
 
19
. $bin/prologue.inc
 
20
 
 
21
file=$tmpdir/file
 
22
subfile=$tmpdir/file2
 
23
okperm=rw
 
24
 
 
25
othertest="$pwd/rename"
 
26
subtest="sub"
 
27
fqsubbase="$pwd/onexec"
 
28
fqsubtest="$fqsubbase//$subtest"
 
29
subtest2="$pwd//sub2"
 
30
subtest3="$pwd//sub3"
 
31
 
 
32
onexec="/proc/*/attr/exec"
 
33
 
 
34
touch $file $subfile
 
35
 
 
36
check_exec()
 
37
{
 
38
    local rc
 
39
    local actual
 
40
    actual=`cat /proc/$1/attr/exec 2>/dev/null`
 
41
    rc=$?
 
42
 
 
43
    # /proc/$1/attr/exec returns invalid argument if onexec has not been called
 
44
    if [ $rc -ne 0 ] ; then
 
45
        if [ "$2" == "nochange" ] ; then
 
46
            return 0
 
47
        fi
 
48
        echo "ONEXEC - exec transition not set"
 
49
        return $rc
 
50
    fi
 
51
    if [ "${actual% (*)}" != "$2" ] ; then
 
52
        echo "ONEXEC - check exec '${actual% (*)}' != expected '$2'"
 
53
        return 1
 
54
    fi
 
55
 
 
56
    return 0
 
57
}
 
58
 
 
59
check_current()
 
60
{
 
61
    local rc
 
62
    local actual
 
63
    actual=`cat /proc/$1/attr/current 2>/dev/null`
 
64
    rc=$?
 
65
 
 
66
    # /proc/$1/attr/current return enoent if the onexec process already exited due to error
 
67
    if [ $rc -ne 0 ] ; then
 
68
        return $rc
 
69
    fi
 
70
 
 
71
    if [ "${actual% (*)}" != "$2" ] ; then
 
72
        echo "ONEXEC - check current '${actual% (*)}' != expected '$2'"
 
73
        return 1
 
74
    fi
 
75
 
 
76
    return 0
 
77
}
 
78
 
 
79
do_test()
 
80
{
 
81
    local desc="$1"
 
82
    local prof="$2"
 
83
    local target_prof="$3"
 
84
    local res="$4"
 
85
    shift 4
 
86
 
 
87
    #ignore prologue.inc error trapping that catches our subfn return values
 
88
 
 
89
    runtestbg "ONEXEC $desc ($prof -> $target_prof)" $res $target_prof "$@"
 
90
    # check that transition does not happen before exec, and that transition
 
91
    # is set
 
92
    
 
93
    if ! check_current $_pid $prof ; then
 
94
        checktestfg
 
95
        return
 
96
    fi
 
97
 
 
98
    if ! check_exec $_pid $target_prof ; then
 
99
        checktestfg
 
100
        return
 
101
    fi
 
102
 
 
103
    kill -CONT $_pid
 
104
 
 
105
    checktestbg
 
106
}
 
107
 
 
108
 
 
109
# ONEXEC from UNCONFINED - don't change profile
 
110
do_test "" unconfined nochange pass $bin/open $file
 
111
 
 
112
# ONEXEC from UNCONFINED - target does NOT exist
 
113
genprofile image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open
 
114
do_test "" unconfined noexist fail $bin/open $file
 
115
 
 
116
# ONEXEC from UNCONFINED - change to rw profile, no exec profile to override
 
117
genprofile image=$bin/rw $bin/open:rix $file:rw
 
118
do_test "no px profile" unconfined $bin/rw pass $bin/open $file
 
119
 
 
120
# ONEXEC from UNCONFINED - don't change profile, make sure exec profile is applied
 
121
genprofile image=$bin/rw $bin/open:px $file:rw  -- image=$bin/open $file:rw
 
122
do_test "nochange px" unconfined nochange pass $bin/open $file
 
123
 
 
124
# ONEXEC from UNCONFINED - change to rw profile, override regular exec profile, exec profile doesn't have perms
 
125
genprofile image=$bin/rw $bin/open:px $file:rw  -- image=$bin/open
 
126
do_test "override px" unconfined $bin/rw pass $bin/open $file
 
127
 
 
128
#------
 
129
 
 
130
# ONEXEC from CONFINED - don't change profile, open can't exec
 
131
genprofile 'change_profile->':$bin/rw $onexec:w
 
132
do_test "no px perm" $bin/onexec nochange fail $bin/open $file
 
133
 
 
134
# ONEXEC from CONFINED - don't change profile, open is run unconfined
 
135
genprofile 'change_profile->':$bin/rw $bin/open:rux $onexec:w
 
136
do_test "nochange rux" $bin/onexec nochange pass $bin/open $file
 
137
 
 
138
# ONEXEC from CONFINED - don't change profile, open is run confined without necessary perms
 
139
genprofile 'change_profile->':$bin/rw $onexec:w -- image=$bin/open $file:rw
 
140
do_test "nochange px - no px perm" $bin/onexec nochange fail $bin/open $file
 
141
 
 
142
# ONEXEC from CONFINED - don't change profile, open is run confined without necessary perms
 
143
genprofile 'change_profile->':$bin/rw $bin/open:rpx $onexec:w -- image=$bin/open
 
144
do_test "nochange px - no file perm" $bin/onexec nochange fail $bin/open $file
 
145
 
 
146
# ONEXEC from CONFINED - target does NOT exist
 
147
genprofile 'change_profile->':$bin/open $onexec:w -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open
 
148
do_test "noexist px" $bin/onexec noexist fail $bin/open $file
 
149
 
 
150
# ONEXEC from CONFINED - change to rw profile, no exec profile to override
 
151
genprofile 'change_profile->':$bin/rw $onexec:w -- image=$bin/rw $bin/open:rix $file:rw
 
152
do_test "change profile - override rix" $bin/onexec $bin/rw pass $bin/open $file
 
153
 
 
154
# ONEXEC from CONFINED - change to rw profile, no exec profile to override, no explicit access to /proc/*/attr/exec
 
155
genprofile 'change_profile->':$bin/rw -- image=$bin/rw $bin/open:rix $file:rw
 
156
do_test "change profile - no onexec:w" $bin/onexec $bin/rw pass $bin/open $file
 
157
 
 
158
# ONEXEC from CONFINED - don't change profile, make sure exec profile is applied
 
159
genprofile 'change_profile->':$bin/rw $onexec:w $bin/open:rpx -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open $file:rw
 
160
do_test "nochange px" $bin/onexec nochange pass $bin/open $file
 
161
 
 
162
# ONEXEC from CONFINED - change to rw profile, override regular exec profile, exec profile doesn't have perms
 
163
genprofile 'change_profile->':$bin/rw $onexec:w -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open
 
164
do_test "override px" $bin/onexec $bin/rw pass $bin/open $file
 
165
 
 
166
# ONEXEC from - change to rw profile, override regular exec profile, exec profile has perms, rw doesn't
 
167
genprofile 'change_profile->':$bin/rw $onexec:w -- image=$bin/rw $bin/open:rix  -- image=$bin/open $file:rw
 
168
do_test "override px" $bin/onexec $bin/rw fail $bin/open $file
 
169
 
 
170
# ONEXEC from COFINED - change to rw profile via glob rule, override exec profile, exec profile doesn't have perms
 
171
genprofile 'change_profile->':/** $onexec:w -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open
 
172
do_test "glob override px" $bin/onexec $bin/rw pass $bin/open $file
 
173
 
 
174
# ONEXEC from COFINED - change to exec profile via glob rule, override exec profile, exec profile doesn't have perms
 
175
genprofile 'change_profile->':/** $onexec:w -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open
 
176
do_test "glob override px" $bin/onexec $bin/open fail $bin/open $file
 
177
 
 
178
# ONEXEC from COFINED - change to exec profile via glob rule, override exec profile, exec profile has perms
 
179
genprofile 'change_profile->':/** $onexec:w -- image=$bin/rw $bin/open:rix $file:rw  -- image=$bin/open $file:rw
 
180
do_test "glob override px" $bin/onexec $bin/rw pass $bin/open $file
 
181