1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
This script tests if file permissions are properly checked with and
without ACLs. The script must be run as root to allow switching users.
The following users are required. They must be a member in the groups
listed in parentheses.
bin (bin)
daemon (bin, daemon)
Cry immediately if we are not running as root.
$ require_root
First, set up a temporary directory and create a regular file with
defined permissions.
$ umask 022
$ mkdir d
$ cd d
$ umask 027
$ touch f
$ ls -l f | awk -- '{ print $1, $3, $4 }' | sed 's/\\.//g'
> -rw-r----- root root
Make sure root has access to the file. Verify that user daemon does not
have access to the file owned by root.
$ echo root > f
$ su daemon
$ echo daemon >> f
>~ .*f: Permission denied$
$ su
Now, change the ownership of the file to bin:bin and verify that this
gives user bin write access.
$ chown bin:bin f
$ ls -l f | awk -- '{ print $1, $3, $4 }' | sed 's/\\.//g'
> -rw-r----- bin bin
$ su bin
$ echo bin >> f
User daemon is a member in the owning group, which has only read access.
Verify this.
$ su daemon
$ cat f
> root
> bin
$ echo daemon >> f
>~ .*f: Permission denied$
Now, add an ACL entry for user daemon that grants him rw- access. File
owners and users capable of CAP_FOWNER are allowed to change ACLs.
$ su bin
$ setfacl -m u:daemon:rw f
$ getfacl --omit-header f
> user::rw-
> user:daemon:rw-
> group::r--
> mask::rw-
> other::---
>
Verify that the additional ACL entry grants user daemon write access.
$ su daemon
$ echo daemon >> f
$ cat f
> root
> bin
> daemon
Remove write access from the group class permission bits, and
verify that this masks daemon's write permission.
$ su bin
$ chmod g-w f
$ getfacl --omit-header f
> user::rw-
> user:daemon:rw- #effective:r--
> group::r--
> mask::r--
> other::---
>
$ su daemon
$ echo daemon >> f
>~ .*f: Permission denied$
Add an entry for group daemon with rw- access, and change the
permissions for user daemon to r--. Also change the others permissions t
rw-. The user entry should take precedence, so daemon should be denied
access.
$ su bin
$ setfacl -m u:daemon:r,g:daemon:rw-,o::rw- f
$ su daemon
$ echo daemon >> f
>~ .*f: Permission denied$
Remove the entry for user daemon. The group daemon permissions should
now give user daemon rw- access.
$ su bin
$ setfacl -x u:daemon f
$ su daemon
$ echo daemon2 >> f
$ cat f
> root
> bin
> daemon
> daemon2
Set the group daemon permissions to r-- and verify that after than, user
daemon does not have write access anymore.
$ su bin
$ setfacl -m g:daemon:r f
$ su daemon
$ echo daemon3 >> f
>~ .*f: Permission denied$
Now, remove the group daemon entry. Because user daemon is a member in
the owning group, he should still have no write access.
$ su bin
$ setfacl -x g:daemon f
$ su daemon
$ echo daemon4 >> f
>~ .*f: Permission denied$
Change the owning group. The other permissions should now grant user
daemon write access.
$ su
$ chgrp root f
$ su daemon
$ echo daemon5 >> f
$ cat f
> root
> bin
> daemon
> daemon2
> daemon5
Verify that permissions in separate matching ACL entries do not
accumulate.
$ su
$ setfacl -m g:bin:r,g:daemon:w f
$ su daemon
$ : < f
$ : > f
$ : <> f
>~ .*f: Permission denied$
Test if directories can have ACLs. We assume that only one access check
algorithm is used for all file types the file system, so these tests
only need to verify that ACL permissions make a difference.
$ su
$ mkdir -m 750 e
$ touch e/h
$ su bin
$ shopt -s nullglob ; echo e/*
>
$ echo i > e/i
>~ .*e/i: Permission denied$
$ su
$ setfacl -m u:bin:rx e
$ su bin
$ echo e/*
> e/h
$ echo i > e/i
>~ .*e/i: Permission denied$
$ su
$ setfacl -m u:bin:rwx e
$ su bin
$ echo i > e/i
Test if symlinks are properly followed.
$ su
$ touch g
$ ln -s g l
$ setfacl -m u:bin:rw l
$ ls -l g | awk -- '{ print $1, $3, $4 }'
> -rw-rw----+ root root
Test if ACLs are effective for block and character special files, fifos,
sockets. This is done by creating special files locally. The devices do
not need to exist: The access check is earlier in the code path than the
test if the device exists.
$ mknod -m 0660 hdt b 91 64
$ mknod -m 0660 null c 1 3
$ mkfifo -m 0660 fifo
$ su bin
$ : < hdt
>~ .*hdt: Permission denied$
$ : < null
>~ .*null: Permission denied$
$ : < fifo
>~ .*fifo: Permission denied$
$ su
$ setfacl -m u:bin:rw hdt null fifo
$ su bin
$ : < hdt
>~ .*hdt: No such device or address$
$ : < null
$ ( echo blah > fifo & ) ; cat fifo
> blah
Test if CAP_FOWNER is properly honored for directories. This addresses a
specific bug in XFS 1.2, which does not grant root access to files in
directories if the file has an ACL and only CAP_FOWNER would grant them.
$ su
$ mkdir -m 600 x
$ chown daemon:daemon x
$ echo j > x/j
$ ls -l x/j | awk -- '{ print $1, $3, $4 }' | sed 's/\\.//g'
> -rw-r----- root root
$ setfacl -m u:daemon:r x
$ ls -l x/j | awk -- '{ print $1, $3, $4 }' | sed 's/\\.//g'
> -rw-r----- root root
(With the bug this gives: `ls: x/j: Permission denied'.)
$ echo k > x/k
(With the bug this gives: `x/k: Permission denied'.)
$ chmod 750 x
Clean up.
$ su
$ cd ..
$ rm -rf d
|