2 # Copyright (C) 2005-2020 Junjiro R. Okajima
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Since aufs supports dynamic branch manipulation, ie. add/remove a branch
20 and changing its permission/attribute, there are a lot of works to do.
24 ----------------------------------------------------------------------
25 o Confirm the adding dir exists outside of aufs, including loopback
26 mount, and its various attributes.
27 o Initialize the xino file and whiteout bases if necessary.
30 o Check the owner/group/mode of the directory
31 When the owner/group/mode of the adding directory differs from the
32 existing branch, aufs issues a warning because it may impose a
34 For example, when a upper writable branch has a world writable empty
35 top directory, a malicious user can create any files on the writable
36 branch directly, like copy-up and modify manually. If something like
37 /etc/{passwd,shadow} exists on the lower readonly branch but the upper
38 writable branch, and the writable branch is world-writable, then a
39 malicious guy may create /etc/passwd on the writable branch directly
40 and the infected file will be valid in aufs.
41 I am afraid it can be a security issue, but aufs can do nothing except
46 ----------------------------------------------------------------------
47 o Confirm the deleting branch is not busy
48 To be general, there is one merit to adopt "remount" interface to
49 manipulate branches. It is to discard caches. At deleting a branch,
50 aufs checks the still cached (and connected) dentries and inodes. If
51 there are any, then they are all in-use. An inode without its
52 corresponding dentry can be alive alone (for example, inotify/fsnotify case).
54 For the cached one, aufs checks whether the same named entry exists on
56 If the cached one is a directory, because aufs provides a merged view
57 to users, as long as one dir is left on any branch aufs can show the
58 dir to users. In this case, the branch can be removed from aufs.
59 Otherwise aufs rejects deleting the branch.
61 If any file on the deleting branch is opened by aufs, then aufs
65 Modify the Permission of a Branch
66 ----------------------------------------------------------------------
67 o Re-initialize or remove the xino file and whiteout bases if necessary.
70 o rw --> ro: Confirm the modifying branch is not busy
71 Aufs rejects the request if any of these conditions are true.
72 - a file on the branch is mmap-ed.
73 - a regular file on the branch is opened for write and there is no
74 same named entry on the upper branch.