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

« back to all changes in this revision

Viewing changes to .pc/tests-fix_systemd_breakage_in_pivot_root-lp1436109.patch/tests/regression/apparmor/pivot_root.sh

  • Committer: Package Import Robot
  • Author(s): Steve Beattie
  • Date: 2015-05-11 22:03:04 UTC
  • mfrom: (1.1.31)
  • Revision ID: package-import@ubuntu.com-20150511220304-gcgk9ix2ui7wvyt0
Tags: 2.9.2-0ubuntu1
* Update to apparmor 2.9.2
  - Fix minitools to work with multiple profiles at once (LP: #1378095)
  - Parse mounts that have non-ascii UTF-8 chars (LP: #1310598)
  - Update dovecot profiles (LP: #1296667)
  - Allow ubuntu-helpers to build texlive fonts (LP: #1010909)
* dropped patches incorporated upstream:
  add-mir-abstraction-lp1422521.patch, systemd-dev-log-lp1413232.patch
  parser-fix_modifier_compilation_+_tests.patch,
  tests-fix_systemd_breakage_in_pivot_root-lp1436109.patch,
  GDM_X_authority-lp1432126.patch, and
  debian/patches/easyprof-framework-policy.patch
* Partial merge with debian apparmor package:
  - debian/rules: enable the bindnow hardening flag during build.
  - debian/upstream/signing-key.asc: add new upstream public
    signing key
  - debian/watch: fix watch file, add gpg signature checking
  - install libapparmor.so dev symlink under /usr not /lib
  - debian/patches/reproducible-pdf.patch: make techdoc.pdf
    reproducible even in face of timezone variations.
  - debian/control: sync fields
  - debian/debhelper/postrm-apparmor: remove
    /etc/apparmor.d/{disable,} on package purge
  - debian/libapache2-mod-apparmor.postrm: on package purge, delete
    /etc/apparmor.d/{,disable} if empty
  - debian/libapparmor1.symbols: Use Build-Depends-Package in the
    symbols file.
  - debian/copyright: sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/bash
2
 
#       Copyright (C) 2014 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 pivot_root
10
 
#=DESCRIPTION 
11
 
# This test verifies that the pivot_root syscall is indeed restricted for
12
 
# confined processes.
13
 
#=END
14
 
 
15
 
pwd=`dirname $0`
16
 
pwd=`cd $pwd ; /bin/pwd`
17
 
 
18
 
bin=$pwd
19
 
 
20
 
. $bin/prologue.inc
21
 
 
22
 
disk_img=$tmpdir/disk_img
23
 
new_root=$tmpdir/new_root/
24
 
put_old=${new_root}put_old/
25
 
bad=$tmpdir/BAD/
26
 
proc=$new_root/proc
27
 
fstype="ext2"
28
 
 
29
 
pivot_root_cleanup() {
30
 
        mountpoint -q "$proc"
31
 
        if [ $? -eq 0 ] ; then
32
 
                umount "$proc"
33
 
        fi
34
 
 
35
 
        mountpoint -q "$new_root"
36
 
        if [ $? -eq 0 ] ; then
37
 
                umount "$new_root"
38
 
        fi
39
 
}
40
 
do_onexit="pivot_root_cleanup"
41
 
 
42
 
# Create disk image since pivot_root doesn't allow old root and new root to be
43
 
# on the same filesystem
44
 
dd if=/dev/zero of="$disk_img" bs=1024 count=512 2> /dev/null
45
 
/sbin/mkfs -t "$fstype" -F "$disk_img" > /dev/null 2> /dev/null
46
 
/bin/mkdir "$new_root"
47
 
/bin/mount -o loop -t "$fstype" "$disk_img" "$new_root"
48
 
 
49
 
# Must mount proc because the pivot_root test program calls aa_getcon() after
50
 
# pivot_root() and aa_getcon() reads /proc/<PID>/attr/current
51
 
mkdir "$proc"
52
 
mount -t proc proc "$proc"
53
 
 
54
 
# Will be used for pivot_root()'s put_old parameter
55
 
mkdir "$put_old"
56
 
 
57
 
do_test()
58
 
{
59
 
        local desc="PIVOT_ROOT ($1)"
60
 
        shift
61
 
 
62
 
        runchecktest "$desc" "$@"
63
 
}
64
 
 
65
 
# Needed for aa_getcon()
66
 
cur="/proc/*/attr/current:r"
67
 
 
68
 
# Needed for clone(CLONE_NEWNS) and pivot_root()
69
 
cap=capability:sys_admin
70
 
 
71
 
# A profile name that'll be used to test AA's transitions during pivot_root()
72
 
new_prof=/sbin/init
73
 
 
74
 
 
75
 
# Ensure everything works as expected when unconfined
76
 
do_test "unconfined" pass "$put_old" "$new_root" unconfined
77
 
 
78
 
# Ensure the test binary is accurately doing post pivot_root profile verification
79
 
do_test "unconfined, bad context" fail "$put_old" "$new_root" "$bad"
80
 
 
81
 
# Ensure failure when no perms are granted
82
 
genprofile
83
 
do_test "no perms" fail "$put_old" "$new_root" "$test"
84
 
 
85
 
if [ "$(have_features mount)" != "true" ] ; then
86
 
        # pivot_root mediation isn't supported by this kernel, so verify that
87
 
        # capability sys_admin is sufficient and skip the remaining tests
88
 
        genprofile $cur $cap
89
 
        do_test "cap" pass "$put_old" "$new_root" "$test"
90
 
 
91
 
        exit
92
 
fi
93
 
 
94
 
# Ensure failure when no pivot_root perms are granted
95
 
genprofile $cur $cap
96
 
do_test "cap only" fail "$put_old" "$new_root" "$test"
97
 
 
98
 
# Ensure failure when everything except capability sys_admin is granted
99
 
genprofile $cur "pivot_root:ALL"
100
 
do_test "bare rule, no cap" fail "$put_old" "$new_root" "$test"
101
 
 
102
 
# Give sufficient perms with full pivot_root access
103
 
genprofile $cur $cap "pivot_root:ALL"
104
 
do_test "bare rule" pass "$put_old" "$new_root" "$test"
105
 
 
106
 
# Give sufficient perms and specify new_root
107
 
genprofile $cur $cap "pivot_root:$new_root"
108
 
do_test "new_root" pass "$put_old" "$new_root" "$test"
109
 
 
110
 
# Ensure failure when new_root is bad
111
 
genprofile $cur $cap "pivot_root:$bad"
112
 
do_test "bad new_root" fail "$put_old" "$new_root" "$test"
113
 
 
114
 
# Give sufficient perms and specify put_old
115
 
genprofile $cur $cap "pivot_root:oldroot=$put_old"
116
 
do_test "put_old" pass "$put_old" "$new_root" "$test"
117
 
 
118
 
# Ensure failure when put_old is bad
119
 
genprofile $cur $cap "pivot_root:oldroot=$bad"
120
 
do_test "bad put_old" fail "$put_old" "$new_root" "$test"
121
 
 
122
 
# Give sufficient perms and specify put_old and new_root
123
 
genprofile $cur $cap "pivot_root:oldroot=$put_old $new_root"
124
 
do_test "put_old, new_root" pass "$put_old" "$new_root" "$test"
125
 
 
126
 
# Ensure failure when put_old is bad
127
 
genprofile $cur $cap "pivot_root:oldroot=$bad $new_root"
128
 
do_test "bad put_old, new_root" fail "$put_old" "$new_root" "$test"
129
 
 
130
 
# Ensure failure when new_root is bad
131
 
genprofile $cur $cap "pivot_root:oldroot=$put_old $bad"
132
 
do_test "put_old, bad new_root" fail "$put_old" "$new_root" "$test"
133
 
 
134
 
# Give sufficient perms and perform a profile transition
135
 
genprofile $cap "pivot_root:-> $new_prof" -- image=$new_prof $cur
136
 
do_test "transition" pass "$put_old" "$new_root" "$new_prof"
137
 
 
138
 
# Ensure failure when the the new profile can't read /proc/<PID>/attr/current
139
 
genprofile $cap "pivot_root:-> $new_prof" -- image=$new_prof
140
 
do_test "transition, no perms" fail "$put_old" "$new_root" "$new_prof"
141
 
 
142
 
# Ensure failure when the new profile doesn't exist
143
 
genprofile $cap "pivot_root:-> $bad" -- image=$new_prof $cur
144
 
do_test "bad transition" fail "$put_old" "$new_root" "$new_prof"
145
 
 
146
 
# Ensure the test binary is accurately doing post pivot_root profile verification
147
 
genprofile $cap "pivot_root:-> $new_prof" -- image=$new_prof $cur
148
 
do_test "bad transition comparison" fail "$put_old" "$new_root" "$test"
149
 
 
150
 
# Give sufficient perms with new_root and a transition
151
 
genprofile $cap "pivot_root:$new_root -> $new_prof" -- image=$new_prof $cur
152
 
do_test "new_root, transition" pass "$put_old" "$new_root" "$new_prof"
153
 
 
154
 
# Ensure failure when the new profile doesn't exist and new_root is specified
155
 
genprofile $cap "pivot_root:$new_root -> $bad" -- image=$new_prof $cur
156
 
do_test "new_root, bad transition" fail "$put_old" "$new_root" "$new_prof"
157
 
 
158
 
# Give sufficient perms with new_root, put_old, and a transition
159
 
genprofile $cap "pivot_root:oldroot=$put_old $new_root -> $new_prof" -- image=$new_prof $cur
160
 
do_test "put_old, new_root, transition" pass "$put_old" "$new_root" "$new_prof"
161
 
 
162
 
# Ensure failure when the new profile doesn't exist and new_root and put_old are specified
163
 
genprofile $cap "pivot_root:oldroot=$put_old $new_root -> $bad" -- image=$new_prof $cur
164
 
do_test "put_old, new_root, bad transition" fail "$put_old" "$new_root" "$new_prof"