Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2011 Novell Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/namei.h> |
Miklos Szeredi | cf9a678 | 2015-12-11 16:30:49 +0100 | [diff] [blame] | 12 | #include <linux/pagemap.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 13 | #include <linux/xattr.h> |
| 14 | #include <linux/security.h> |
| 15 | #include <linux/mount.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/parser.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/sched.h> |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 20 | #include <linux/statfs.h> |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 21 | #include <linux/seq_file.h> |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 22 | #include <linux/posix_acl_xattr.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 23 | #include "overlayfs.h" |
| 24 | |
| 25 | MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>"); |
| 26 | MODULE_DESCRIPTION("Overlay filesystem"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 29 | struct ovl_config { |
| 30 | char *lowerdir; |
| 31 | char *upperdir; |
| 32 | char *workdir; |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 33 | bool default_permissions; |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 36 | /* private information held for overlayfs's superblock */ |
| 37 | struct ovl_fs { |
| 38 | struct vfsmount *upper_mnt; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 39 | unsigned numlower; |
| 40 | struct vfsmount **lower_mnt; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 41 | struct dentry *workdir; |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 42 | long lower_namelen; |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 43 | /* pathnames of lower and upper dirs, for show_options */ |
| 44 | struct ovl_config config; |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 45 | /* creds of process who forced instantiation of super block */ |
| 46 | const struct cred *creator_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | struct ovl_dir_cache; |
| 50 | |
| 51 | /* private information held for every overlayfs dentry */ |
| 52 | struct ovl_entry { |
| 53 | struct dentry *__upperdentry; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 54 | struct ovl_dir_cache *cache; |
| 55 | union { |
| 56 | struct { |
| 57 | u64 version; |
| 58 | bool opaque; |
| 59 | }; |
| 60 | struct rcu_head rcu; |
| 61 | }; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 62 | unsigned numlower; |
| 63 | struct path lowerstack[]; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 66 | #define OVL_MAX_STACK 500 |
| 67 | |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 68 | static struct dentry *__ovl_dentry_lower(struct ovl_entry *oe) |
| 69 | { |
| 70 | return oe->numlower ? oe->lowerstack[0].dentry : NULL; |
| 71 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 72 | |
| 73 | enum ovl_path_type ovl_path_type(struct dentry *dentry) |
| 74 | { |
| 75 | struct ovl_entry *oe = dentry->d_fsdata; |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 76 | enum ovl_path_type type = 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 77 | |
| 78 | if (oe->__upperdentry) { |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 79 | type = __OVL_PATH_UPPER; |
| 80 | |
Konstantin Khlebnikov | 45d1173 | 2016-01-31 16:17:53 +0300 | [diff] [blame] | 81 | /* |
| 82 | * Non-dir dentry can hold lower dentry from previous |
| 83 | * location. Its purity depends only on opaque flag. |
| 84 | */ |
| 85 | if (oe->numlower && S_ISDIR(dentry->d_inode->i_mode)) |
| 86 | type |= __OVL_PATH_MERGE; |
| 87 | else if (!oe->opaque) |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 88 | type |= __OVL_PATH_PURE; |
Miklos Szeredi | 9d7459d | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 89 | } else { |
| 90 | if (oe->numlower > 1) |
| 91 | type |= __OVL_PATH_MERGE; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 92 | } |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 93 | return type; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe) |
| 97 | { |
Miklos Szeredi | 71d5092 | 2014-11-20 16:40:01 +0100 | [diff] [blame] | 98 | return lockless_dereference(oe->__upperdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void ovl_path_upper(struct dentry *dentry, struct path *path) |
| 102 | { |
| 103 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 104 | struct ovl_entry *oe = dentry->d_fsdata; |
| 105 | |
| 106 | path->mnt = ofs->upper_mnt; |
| 107 | path->dentry = ovl_upperdentry_dereference(oe); |
| 108 | } |
| 109 | |
| 110 | enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path) |
| 111 | { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 112 | enum ovl_path_type type = ovl_path_type(dentry); |
| 113 | |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 114 | if (!OVL_TYPE_UPPER(type)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 115 | ovl_path_lower(dentry, path); |
| 116 | else |
| 117 | ovl_path_upper(dentry, path); |
| 118 | |
| 119 | return type; |
| 120 | } |
| 121 | |
| 122 | struct dentry *ovl_dentry_upper(struct dentry *dentry) |
| 123 | { |
| 124 | struct ovl_entry *oe = dentry->d_fsdata; |
| 125 | |
| 126 | return ovl_upperdentry_dereference(oe); |
| 127 | } |
| 128 | |
| 129 | struct dentry *ovl_dentry_lower(struct dentry *dentry) |
| 130 | { |
| 131 | struct ovl_entry *oe = dentry->d_fsdata; |
| 132 | |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 133 | return __ovl_dentry_lower(oe); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | struct dentry *ovl_dentry_real(struct dentry *dentry) |
| 137 | { |
| 138 | struct ovl_entry *oe = dentry->d_fsdata; |
| 139 | struct dentry *realdentry; |
| 140 | |
| 141 | realdentry = ovl_upperdentry_dereference(oe); |
| 142 | if (!realdentry) |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 143 | realdentry = __ovl_dentry_lower(oe); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 144 | |
| 145 | return realdentry; |
| 146 | } |
| 147 | |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 148 | static void ovl_inode_init(struct inode *inode, struct inode *realinode, |
| 149 | bool is_upper) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 150 | { |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 151 | WRITE_ONCE(inode->i_private, (unsigned long) realinode | |
| 152 | (is_upper ? OVL_ISUPPER_MASK : 0)); |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame] | 153 | } |
| 154 | |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 155 | struct vfsmount *ovl_entry_mnt_real(struct ovl_entry *oe, struct inode *inode, |
| 156 | bool is_upper) |
| 157 | { |
| 158 | if (is_upper) { |
| 159 | struct ovl_fs *ofs = inode->i_sb->s_fs_info; |
| 160 | |
| 161 | return ofs->upper_mnt; |
| 162 | } else { |
| 163 | return oe->numlower ? oe->lowerstack[0].mnt : NULL; |
| 164 | } |
| 165 | } |
| 166 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 167 | struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry) |
| 168 | { |
| 169 | struct ovl_entry *oe = dentry->d_fsdata; |
| 170 | |
| 171 | return oe->cache; |
| 172 | } |
| 173 | |
| 174 | void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache) |
| 175 | { |
| 176 | struct ovl_entry *oe = dentry->d_fsdata; |
| 177 | |
| 178 | oe->cache = cache; |
| 179 | } |
| 180 | |
| 181 | void ovl_path_lower(struct dentry *dentry, struct path *path) |
| 182 | { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 183 | struct ovl_entry *oe = dentry->d_fsdata; |
| 184 | |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 185 | *path = oe->numlower ? oe->lowerstack[0] : (struct path) { NULL, NULL }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | int ovl_want_write(struct dentry *dentry) |
| 189 | { |
| 190 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 191 | return mnt_want_write(ofs->upper_mnt); |
| 192 | } |
| 193 | |
| 194 | void ovl_drop_write(struct dentry *dentry) |
| 195 | { |
| 196 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 197 | mnt_drop_write(ofs->upper_mnt); |
| 198 | } |
| 199 | |
| 200 | struct dentry *ovl_workdir(struct dentry *dentry) |
| 201 | { |
| 202 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 203 | return ofs->workdir; |
| 204 | } |
| 205 | |
| 206 | bool ovl_dentry_is_opaque(struct dentry *dentry) |
| 207 | { |
| 208 | struct ovl_entry *oe = dentry->d_fsdata; |
| 209 | return oe->opaque; |
| 210 | } |
| 211 | |
| 212 | void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque) |
| 213 | { |
| 214 | struct ovl_entry *oe = dentry->d_fsdata; |
| 215 | oe->opaque = opaque; |
| 216 | } |
| 217 | |
| 218 | void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry) |
| 219 | { |
| 220 | struct ovl_entry *oe = dentry->d_fsdata; |
| 221 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 222 | WARN_ON(!inode_is_locked(upperdentry->d_parent->d_inode)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 223 | WARN_ON(oe->__upperdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 224 | /* |
| 225 | * Make sure upperdentry is consistent before making it visible to |
| 226 | * ovl_upperdentry_dereference(). |
| 227 | */ |
| 228 | smp_wmb(); |
| 229 | oe->__upperdentry = upperdentry; |
| 230 | } |
| 231 | |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 232 | void ovl_inode_update(struct inode *inode, struct inode *upperinode) |
| 233 | { |
| 234 | WARN_ON(!upperinode); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 235 | WARN_ON(!inode_unhashed(inode)); |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 236 | WRITE_ONCE(inode->i_private, |
| 237 | (unsigned long) upperinode | OVL_ISUPPER_MASK); |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 238 | if (!S_ISDIR(upperinode->i_mode)) |
| 239 | __insert_inode_hash(inode, (unsigned long) upperinode); |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 240 | } |
| 241 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 242 | void ovl_dentry_version_inc(struct dentry *dentry) |
| 243 | { |
| 244 | struct ovl_entry *oe = dentry->d_fsdata; |
| 245 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 246 | WARN_ON(!inode_is_locked(dentry->d_inode)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 247 | oe->version++; |
| 248 | } |
| 249 | |
| 250 | u64 ovl_dentry_version_get(struct dentry *dentry) |
| 251 | { |
| 252 | struct ovl_entry *oe = dentry->d_fsdata; |
| 253 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 254 | WARN_ON(!inode_is_locked(dentry->d_inode)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 255 | return oe->version; |
| 256 | } |
| 257 | |
| 258 | bool ovl_is_whiteout(struct dentry *dentry) |
| 259 | { |
| 260 | struct inode *inode = dentry->d_inode; |
| 261 | |
| 262 | return inode && IS_WHITEOUT(inode); |
| 263 | } |
| 264 | |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 265 | const struct cred *ovl_override_creds(struct super_block *sb) |
| 266 | { |
| 267 | struct ovl_fs *ofs = sb->s_fs_info; |
| 268 | |
| 269 | return override_creds(ofs->creator_cred); |
| 270 | } |
| 271 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 272 | static bool ovl_is_opaquedir(struct dentry *dentry) |
| 273 | { |
| 274 | int res; |
| 275 | char val; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 276 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 277 | if (!d_is_dir(dentry)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 278 | return false; |
| 279 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 280 | res = vfs_getxattr(dentry, OVL_XATTR_OPAQUE, &val, 1); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 281 | if (res == 1 && val == 'y') |
| 282 | return true; |
| 283 | |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | static void ovl_dentry_release(struct dentry *dentry) |
| 288 | { |
| 289 | struct ovl_entry *oe = dentry->d_fsdata; |
| 290 | |
| 291 | if (oe) { |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 292 | unsigned int i; |
| 293 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 294 | dput(oe->__upperdentry); |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 295 | for (i = 0; i < oe->numlower; i++) |
| 296 | dput(oe->lowerstack[i].dentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 297 | kfree_rcu(oe, rcu); |
| 298 | } |
| 299 | } |
| 300 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 301 | static struct dentry *ovl_d_real(struct dentry *dentry, |
| 302 | const struct inode *inode, |
| 303 | unsigned int open_flags) |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 304 | { |
| 305 | struct dentry *real; |
| 306 | |
| 307 | if (d_is_dir(dentry)) { |
| 308 | if (!inode || inode == d_inode(dentry)) |
| 309 | return dentry; |
| 310 | goto bug; |
| 311 | } |
| 312 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 313 | if (d_is_negative(dentry)) |
| 314 | return dentry; |
| 315 | |
| 316 | if (open_flags) { |
| 317 | int err = ovl_open_maybe_copy_up(dentry, open_flags); |
| 318 | |
| 319 | if (err) |
| 320 | return ERR_PTR(err); |
| 321 | } |
| 322 | |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 323 | real = ovl_dentry_upper(dentry); |
| 324 | if (real && (!inode || inode == d_inode(real))) |
| 325 | return real; |
| 326 | |
| 327 | real = ovl_dentry_lower(dentry); |
| 328 | if (!real) |
| 329 | goto bug; |
| 330 | |
Miklos Szeredi | c4fcfc1 | 2016-11-29 10:20:24 +0100 | [diff] [blame] | 331 | /* Handle recursion */ |
| 332 | real = d_real(real, inode, open_flags); |
| 333 | |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 334 | if (!inode || inode == d_inode(real)) |
| 335 | return real; |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 336 | bug: |
Miklos Szeredi | 656189d | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 337 | WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 338 | inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0); |
| 339 | return dentry; |
| 340 | } |
| 341 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 342 | static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) |
| 343 | { |
| 344 | struct ovl_entry *oe = dentry->d_fsdata; |
| 345 | unsigned int i; |
| 346 | int ret = 1; |
| 347 | |
| 348 | for (i = 0; i < oe->numlower; i++) { |
| 349 | struct dentry *d = oe->lowerstack[i].dentry; |
| 350 | |
| 351 | if (d->d_flags & DCACHE_OP_REVALIDATE) { |
| 352 | ret = d->d_op->d_revalidate(d, flags); |
| 353 | if (ret < 0) |
| 354 | return ret; |
| 355 | if (!ret) { |
| 356 | if (!(flags & LOOKUP_RCU)) |
| 357 | d_invalidate(d); |
| 358 | return -ESTALE; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | return 1; |
| 363 | } |
| 364 | |
| 365 | static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) |
| 366 | { |
| 367 | struct ovl_entry *oe = dentry->d_fsdata; |
| 368 | unsigned int i; |
| 369 | int ret = 1; |
| 370 | |
| 371 | for (i = 0; i < oe->numlower; i++) { |
| 372 | struct dentry *d = oe->lowerstack[i].dentry; |
| 373 | |
| 374 | if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) { |
| 375 | ret = d->d_op->d_weak_revalidate(d, flags); |
| 376 | if (ret <= 0) |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | return ret; |
| 381 | } |
| 382 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 383 | static const struct dentry_operations ovl_dentry_operations = { |
| 384 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 385 | .d_real = ovl_d_real, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 386 | }; |
| 387 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 388 | static const struct dentry_operations ovl_reval_dentry_operations = { |
| 389 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 390 | .d_real = ovl_d_real, |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 391 | .d_revalidate = ovl_dentry_revalidate, |
| 392 | .d_weak_revalidate = ovl_dentry_weak_revalidate, |
| 393 | }; |
| 394 | |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 395 | static struct ovl_entry *ovl_alloc_entry(unsigned int numlower) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 396 | { |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 397 | size_t size = offsetof(struct ovl_entry, lowerstack[numlower]); |
| 398 | struct ovl_entry *oe = kzalloc(size, GFP_KERNEL); |
| 399 | |
| 400 | if (oe) |
| 401 | oe->numlower = numlower; |
| 402 | |
| 403 | return oe; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 406 | static bool ovl_dentry_remote(struct dentry *dentry) |
| 407 | { |
| 408 | return dentry->d_flags & |
Miklos Szeredi | 76bc8e2 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 409 | (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE | |
| 410 | DCACHE_OP_REAL); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static bool ovl_dentry_weird(struct dentry *dentry) |
| 414 | { |
| 415 | return dentry->d_flags & (DCACHE_NEED_AUTOMOUNT | |
| 416 | DCACHE_MANAGE_TRANSIT | |
| 417 | DCACHE_OP_HASH | |
| 418 | DCACHE_OP_COMPARE); |
| 419 | } |
| 420 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 421 | static inline struct dentry *ovl_lookup_real(struct dentry *dir, |
Al Viro | 29c42e8 | 2016-07-20 22:36:53 -0400 | [diff] [blame] | 422 | const struct qstr *name) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 423 | { |
| 424 | struct dentry *dentry; |
| 425 | |
Miklos Szeredi | c1b2cc1 | 2016-07-29 12:05:22 +0200 | [diff] [blame] | 426 | dentry = lookup_one_len_unlocked(name->name, dir, name->len); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 427 | |
| 428 | if (IS_ERR(dentry)) { |
| 429 | if (PTR_ERR(dentry) == -ENOENT) |
| 430 | dentry = NULL; |
| 431 | } else if (!dentry->d_inode) { |
| 432 | dput(dentry); |
| 433 | dentry = NULL; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 434 | } else if (ovl_dentry_weird(dentry)) { |
Miklos Szeredi | a6f15d9 | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 435 | dput(dentry); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 436 | /* Don't support traversing automounts and other weirdness */ |
Miklos Szeredi | a6f15d9 | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 437 | dentry = ERR_PTR(-EREMOTE); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 438 | } |
| 439 | return dentry; |
| 440 | } |
| 441 | |
Miklos Szeredi | 5ef88da | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 442 | /* |
| 443 | * Returns next layer in stack starting from top. |
| 444 | * Returns -1 if this is the last layer. |
| 445 | */ |
| 446 | int ovl_path_next(int idx, struct dentry *dentry, struct path *path) |
| 447 | { |
| 448 | struct ovl_entry *oe = dentry->d_fsdata; |
| 449 | |
| 450 | BUG_ON(idx < 0); |
| 451 | if (idx == 0) { |
| 452 | ovl_path_upper(dentry, path); |
| 453 | if (path->dentry) |
| 454 | return oe->numlower ? 1 : -1; |
| 455 | idx++; |
| 456 | } |
| 457 | BUG_ON(idx > oe->numlower); |
| 458 | *path = oe->lowerstack[idx - 1]; |
| 459 | |
| 460 | return (idx < oe->numlower) ? idx + 1 : -1; |
| 461 | } |
| 462 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 463 | struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, |
| 464 | unsigned int flags) |
| 465 | { |
| 466 | struct ovl_entry *oe; |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 467 | const struct cred *old_cred; |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 468 | struct ovl_entry *poe = dentry->d_parent->d_fsdata; |
| 469 | struct path *stack = NULL; |
| 470 | struct dentry *upperdir, *upperdentry = NULL; |
| 471 | unsigned int ctr = 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 472 | struct inode *inode = NULL; |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 473 | bool upperopaque = false; |
| 474 | struct dentry *this, *prev = NULL; |
| 475 | unsigned int i; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 476 | int err; |
| 477 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 478 | old_cred = ovl_override_creds(dentry->d_sb); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 479 | upperdir = ovl_upperdentry_dereference(poe); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 480 | if (upperdir) { |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 481 | this = ovl_lookup_real(upperdir, &dentry->d_name); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 482 | err = PTR_ERR(this); |
| 483 | if (IS_ERR(this)) |
| 484 | goto out; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 485 | |
Miklos Szeredi | 3e01cee | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 486 | if (this) { |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 487 | if (unlikely(ovl_dentry_remote(this))) { |
| 488 | dput(this); |
| 489 | err = -EREMOTE; |
| 490 | goto out; |
| 491 | } |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 492 | if (ovl_is_whiteout(this)) { |
| 493 | dput(this); |
| 494 | this = NULL; |
| 495 | upperopaque = true; |
Miklos Szeredi | 3e01cee | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 496 | } else if (poe->numlower && ovl_is_opaquedir(this)) { |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 497 | upperopaque = true; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 498 | } |
| 499 | } |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 500 | upperdentry = prev = this; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 503 | if (!upperopaque && poe->numlower) { |
| 504 | err = -ENOMEM; |
| 505 | stack = kcalloc(poe->numlower, sizeof(struct path), GFP_KERNEL); |
| 506 | if (!stack) |
| 507 | goto out_put_upper; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 510 | for (i = 0; !upperopaque && i < poe->numlower; i++) { |
| 511 | bool opaque = false; |
| 512 | struct path lowerpath = poe->lowerstack[i]; |
| 513 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 514 | this = ovl_lookup_real(lowerpath.dentry, &dentry->d_name); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 515 | err = PTR_ERR(this); |
Miklos Szeredi | 09e1032 | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 516 | if (IS_ERR(this)) { |
| 517 | /* |
| 518 | * If it's positive, then treat ENAMETOOLONG as ENOENT. |
| 519 | */ |
| 520 | if (err == -ENAMETOOLONG && (upperdentry || ctr)) |
| 521 | continue; |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 522 | goto out_put; |
Miklos Szeredi | 09e1032 | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 523 | } |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 524 | if (!this) |
| 525 | continue; |
Miklos Szeredi | 3e01cee | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 526 | if (ovl_is_whiteout(this)) { |
| 527 | dput(this); |
| 528 | break; |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 529 | } |
| 530 | /* |
Miklos Szeredi | 3e01cee | 2014-12-13 00:59:45 +0100 | [diff] [blame] | 531 | * Only makes sense to check opaque dir if this is not the |
| 532 | * lowermost layer. |
| 533 | */ |
| 534 | if (i < poe->numlower - 1 && ovl_is_opaquedir(this)) |
| 535 | opaque = true; |
hujianyang | a425c03 | 2015-01-06 16:10:01 +0800 | [diff] [blame] | 536 | |
| 537 | if (prev && (!S_ISDIR(prev->d_inode->i_mode) || |
| 538 | !S_ISDIR(this->d_inode->i_mode))) { |
| 539 | /* |
| 540 | * FIXME: check for upper-opaqueness maybe better done |
| 541 | * in remove code. |
| 542 | */ |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 543 | if (prev == upperdentry) |
| 544 | upperopaque = true; |
| 545 | dput(this); |
| 546 | break; |
| 547 | } |
hujianyang | a425c03 | 2015-01-06 16:10:01 +0800 | [diff] [blame] | 548 | /* |
| 549 | * If this is a non-directory then stop here. |
| 550 | */ |
| 551 | if (!S_ISDIR(this->d_inode->i_mode)) |
| 552 | opaque = true; |
| 553 | |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 554 | stack[ctr].dentry = this; |
| 555 | stack[ctr].mnt = lowerpath.mnt; |
| 556 | ctr++; |
| 557 | prev = this; |
| 558 | if (opaque) |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | oe = ovl_alloc_entry(ctr); |
| 563 | err = -ENOMEM; |
| 564 | if (!oe) |
| 565 | goto out_put; |
| 566 | |
| 567 | if (upperdentry || ctr) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 568 | struct dentry *realdentry; |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 569 | struct inode *realinode; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 570 | |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 571 | realdentry = upperdentry ? upperdentry : stack[0].dentry; |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 572 | realinode = d_inode(realdentry); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 573 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 574 | err = -ENOMEM; |
Miklos Szeredi | 51f7e52 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 575 | if (upperdentry && !d_is_dir(upperdentry)) { |
| 576 | inode = ovl_get_inode(dentry->d_sb, realinode); |
| 577 | } else { |
| 578 | inode = ovl_new_inode(dentry->d_sb, realinode->i_mode); |
| 579 | if (inode) |
| 580 | ovl_inode_init(inode, realinode, !!upperdentry); |
| 581 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 582 | if (!inode) |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 583 | goto out_free_oe; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 584 | ovl_copyattr(realdentry->d_inode, inode); |
| 585 | } |
| 586 | |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 587 | revert_creds(old_cred); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 588 | oe->opaque = upperopaque; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 589 | oe->__upperdentry = upperdentry; |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 590 | memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr); |
| 591 | kfree(stack); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 592 | dentry->d_fsdata = oe; |
| 593 | d_add(dentry, inode); |
| 594 | |
| 595 | return NULL; |
| 596 | |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 597 | out_free_oe: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 598 | kfree(oe); |
Miklos Szeredi | 3d3c6b8 | 2014-12-13 00:59:44 +0100 | [diff] [blame] | 599 | out_put: |
| 600 | for (i = 0; i < ctr; i++) |
| 601 | dput(stack[i].dentry); |
| 602 | kfree(stack); |
| 603 | out_put_upper: |
| 604 | dput(upperdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 605 | out: |
Miklos Szeredi | 2b6bc7f | 2016-09-16 14:12:11 +0200 | [diff] [blame] | 606 | revert_creds(old_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 607 | return ERR_PTR(err); |
| 608 | } |
| 609 | |
| 610 | struct file *ovl_path_open(struct path *path, int flags) |
| 611 | { |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 612 | return dentry_open(path, flags | O_NOATIME, current_cred()); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void ovl_put_super(struct super_block *sb) |
| 616 | { |
| 617 | struct ovl_fs *ufs = sb->s_fs_info; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 618 | unsigned i; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 619 | |
| 620 | dput(ufs->workdir); |
| 621 | mntput(ufs->upper_mnt); |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 622 | for (i = 0; i < ufs->numlower; i++) |
| 623 | mntput(ufs->lower_mnt[i]); |
Konstantin Khlebnikov | 5ffdbe8 | 2015-08-24 15:57:19 +0300 | [diff] [blame] | 624 | kfree(ufs->lower_mnt); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 625 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 626 | kfree(ufs->config.lowerdir); |
| 627 | kfree(ufs->config.upperdir); |
| 628 | kfree(ufs->config.workdir); |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 629 | put_cred(ufs->creator_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 630 | kfree(ufs); |
| 631 | } |
| 632 | |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 633 | /** |
| 634 | * ovl_statfs |
| 635 | * @sb: The overlayfs super block |
| 636 | * @buf: The struct kstatfs to fill in with stats |
| 637 | * |
| 638 | * Get the filesystem statistics. As writes always target the upper layer |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 639 | * filesystem pass the statfs to the upper filesystem (if it exists) |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 640 | */ |
| 641 | static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 642 | { |
| 643 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 644 | struct dentry *root_dentry = dentry->d_sb->s_root; |
| 645 | struct path path; |
| 646 | int err; |
| 647 | |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 648 | ovl_path_real(root_dentry, &path); |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 649 | |
| 650 | err = vfs_statfs(&path, buf); |
| 651 | if (!err) { |
| 652 | buf->f_namelen = max(buf->f_namelen, ofs->lower_namelen); |
| 653 | buf->f_type = OVERLAYFS_SUPER_MAGIC; |
| 654 | } |
| 655 | |
| 656 | return err; |
| 657 | } |
| 658 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 659 | /** |
| 660 | * ovl_show_options |
| 661 | * |
| 662 | * Prints the mount options for a given superblock. |
| 663 | * Returns zero; does not fail. |
| 664 | */ |
| 665 | static int ovl_show_options(struct seq_file *m, struct dentry *dentry) |
| 666 | { |
| 667 | struct super_block *sb = dentry->d_sb; |
| 668 | struct ovl_fs *ufs = sb->s_fs_info; |
| 669 | |
Kees Cook | a068acf | 2015-09-04 15:44:57 -0700 | [diff] [blame] | 670 | seq_show_option(m, "lowerdir", ufs->config.lowerdir); |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 671 | if (ufs->config.upperdir) { |
Kees Cook | a068acf | 2015-09-04 15:44:57 -0700 | [diff] [blame] | 672 | seq_show_option(m, "upperdir", ufs->config.upperdir); |
| 673 | seq_show_option(m, "workdir", ufs->config.workdir); |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 674 | } |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 675 | if (ufs->config.default_permissions) |
| 676 | seq_puts(m, ",default_permissions"); |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 677 | return 0; |
| 678 | } |
| 679 | |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 680 | static int ovl_remount(struct super_block *sb, int *flags, char *data) |
| 681 | { |
| 682 | struct ovl_fs *ufs = sb->s_fs_info; |
| 683 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 684 | if (!(*flags & MS_RDONLY) && (!ufs->upper_mnt || !ufs->workdir)) |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 685 | return -EROFS; |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 690 | static const struct super_operations ovl_super_operations = { |
| 691 | .put_super = ovl_put_super, |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 692 | .statfs = ovl_statfs, |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 693 | .show_options = ovl_show_options, |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 694 | .remount_fs = ovl_remount, |
Miklos Szeredi | eead4f2 | 2016-07-29 12:05:22 +0200 | [diff] [blame] | 695 | .drop_inode = generic_delete_inode, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 696 | }; |
| 697 | |
| 698 | enum { |
| 699 | OPT_LOWERDIR, |
| 700 | OPT_UPPERDIR, |
| 701 | OPT_WORKDIR, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 702 | OPT_DEFAULT_PERMISSIONS, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 703 | OPT_ERR, |
| 704 | }; |
| 705 | |
| 706 | static const match_table_t ovl_tokens = { |
| 707 | {OPT_LOWERDIR, "lowerdir=%s"}, |
| 708 | {OPT_UPPERDIR, "upperdir=%s"}, |
| 709 | {OPT_WORKDIR, "workdir=%s"}, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 710 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 711 | {OPT_ERR, NULL} |
| 712 | }; |
| 713 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 714 | static char *ovl_next_opt(char **s) |
| 715 | { |
| 716 | char *sbegin = *s; |
| 717 | char *p; |
| 718 | |
| 719 | if (sbegin == NULL) |
| 720 | return NULL; |
| 721 | |
| 722 | for (p = sbegin; *p; p++) { |
| 723 | if (*p == '\\') { |
| 724 | p++; |
| 725 | if (!*p) |
| 726 | break; |
| 727 | } else if (*p == ',') { |
| 728 | *p = '\0'; |
| 729 | *s = p + 1; |
| 730 | return sbegin; |
| 731 | } |
| 732 | } |
| 733 | *s = NULL; |
| 734 | return sbegin; |
| 735 | } |
| 736 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 737 | static int ovl_parse_opt(char *opt, struct ovl_config *config) |
| 738 | { |
| 739 | char *p; |
| 740 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 741 | while ((p = ovl_next_opt(&opt)) != NULL) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 742 | int token; |
| 743 | substring_t args[MAX_OPT_ARGS]; |
| 744 | |
| 745 | if (!*p) |
| 746 | continue; |
| 747 | |
| 748 | token = match_token(p, ovl_tokens, args); |
| 749 | switch (token) { |
| 750 | case OPT_UPPERDIR: |
| 751 | kfree(config->upperdir); |
| 752 | config->upperdir = match_strdup(&args[0]); |
| 753 | if (!config->upperdir) |
| 754 | return -ENOMEM; |
| 755 | break; |
| 756 | |
| 757 | case OPT_LOWERDIR: |
| 758 | kfree(config->lowerdir); |
| 759 | config->lowerdir = match_strdup(&args[0]); |
| 760 | if (!config->lowerdir) |
| 761 | return -ENOMEM; |
| 762 | break; |
| 763 | |
| 764 | case OPT_WORKDIR: |
| 765 | kfree(config->workdir); |
| 766 | config->workdir = match_strdup(&args[0]); |
| 767 | if (!config->workdir) |
| 768 | return -ENOMEM; |
| 769 | break; |
| 770 | |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 771 | case OPT_DEFAULT_PERMISSIONS: |
| 772 | config->default_permissions = true; |
| 773 | break; |
| 774 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 775 | default: |
hujianyang | bead55e | 2015-01-15 13:17:36 +0800 | [diff] [blame] | 776 | pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 777 | return -EINVAL; |
| 778 | } |
| 779 | } |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 780 | |
| 781 | /* Workdir is useless in non-upper mount */ |
| 782 | if (!config->upperdir && config->workdir) { |
| 783 | pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n", |
| 784 | config->workdir); |
| 785 | kfree(config->workdir); |
| 786 | config->workdir = NULL; |
| 787 | } |
| 788 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | #define OVL_WORKDIR_NAME "work" |
| 793 | |
| 794 | static struct dentry *ovl_workdir_create(struct vfsmount *mnt, |
| 795 | struct dentry *dentry) |
| 796 | { |
| 797 | struct inode *dir = dentry->d_inode; |
| 798 | struct dentry *work; |
| 799 | int err; |
| 800 | bool retried = false; |
| 801 | |
| 802 | err = mnt_want_write(mnt); |
| 803 | if (err) |
| 804 | return ERR_PTR(err); |
| 805 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 806 | inode_lock_nested(dir, I_MUTEX_PARENT); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 807 | retry: |
| 808 | work = lookup_one_len(OVL_WORKDIR_NAME, dentry, |
| 809 | strlen(OVL_WORKDIR_NAME)); |
| 810 | |
| 811 | if (!IS_ERR(work)) { |
| 812 | struct kstat stat = { |
| 813 | .mode = S_IFDIR | 0, |
| 814 | }; |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 815 | struct iattr attr = { |
| 816 | .ia_valid = ATTR_MODE, |
| 817 | .ia_mode = stat.mode, |
| 818 | }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 819 | |
| 820 | if (work->d_inode) { |
| 821 | err = -EEXIST; |
| 822 | if (retried) |
| 823 | goto out_dput; |
| 824 | |
| 825 | retried = true; |
Miklos Szeredi | eea2fb4 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 826 | ovl_workdir_cleanup(dir, mnt, work, 0); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 827 | dput(work); |
| 828 | goto retry; |
| 829 | } |
| 830 | |
| 831 | err = ovl_create_real(dir, work, &stat, NULL, NULL, true); |
| 832 | if (err) |
| 833 | goto out_dput; |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 834 | |
Miklos Szeredi | cb348ed | 2016-10-04 14:40:44 +0200 | [diff] [blame] | 835 | /* |
| 836 | * Try to remove POSIX ACL xattrs from workdir. We are good if: |
| 837 | * |
| 838 | * a) success (there was a POSIX ACL xattr and was removed) |
| 839 | * b) -ENODATA (there was no POSIX ACL xattr) |
| 840 | * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported) |
| 841 | * |
| 842 | * There are various other error values that could effectively |
| 843 | * mean that the xattr doesn't exist (e.g. -ERANGE is returned |
| 844 | * if the xattr name is too long), but the set of filesystems |
| 845 | * allowed as upper are limited to "normal" ones, where checking |
| 846 | * for the above two errors is sufficient. |
| 847 | */ |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 848 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 849 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 850 | goto out_dput; |
| 851 | |
| 852 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 853 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 854 | goto out_dput; |
| 855 | |
| 856 | /* Clear any inherited mode bits */ |
| 857 | inode_lock(work->d_inode); |
| 858 | err = notify_change(work, &attr, NULL); |
| 859 | inode_unlock(work->d_inode); |
| 860 | if (err) |
| 861 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 862 | } |
| 863 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 864 | inode_unlock(dir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 865 | mnt_drop_write(mnt); |
| 866 | |
| 867 | return work; |
| 868 | |
| 869 | out_dput: |
| 870 | dput(work); |
| 871 | work = ERR_PTR(err); |
| 872 | goto out_unlock; |
| 873 | } |
| 874 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 875 | static void ovl_unescape(char *s) |
| 876 | { |
| 877 | char *d = s; |
| 878 | |
| 879 | for (;; s++, d++) { |
| 880 | if (*s == '\\') |
| 881 | s++; |
| 882 | *d = *s; |
| 883 | if (!*s) |
| 884 | break; |
| 885 | } |
| 886 | } |
| 887 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 888 | static int ovl_mount_dir_noesc(const char *name, struct path *path) |
| 889 | { |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 890 | int err = -EINVAL; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 891 | |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 892 | if (!*name) { |
| 893 | pr_err("overlayfs: empty lowerdir\n"); |
| 894 | goto out; |
| 895 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 896 | err = kern_path(name, LOOKUP_FOLLOW, path); |
| 897 | if (err) { |
| 898 | pr_err("overlayfs: failed to resolve '%s': %i\n", name, err); |
| 899 | goto out; |
| 900 | } |
| 901 | err = -EINVAL; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 902 | if (ovl_dentry_weird(path->dentry)) { |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 903 | pr_err("overlayfs: filesystem on '%s' not supported\n", name); |
| 904 | goto out_put; |
| 905 | } |
| 906 | if (!S_ISDIR(path->dentry->d_inode->i_mode)) { |
| 907 | pr_err("overlayfs: '%s' not a directory\n", name); |
| 908 | goto out_put; |
| 909 | } |
| 910 | return 0; |
| 911 | |
| 912 | out_put: |
| 913 | path_put(path); |
| 914 | out: |
| 915 | return err; |
| 916 | } |
| 917 | |
| 918 | static int ovl_mount_dir(const char *name, struct path *path) |
| 919 | { |
| 920 | int err = -ENOMEM; |
| 921 | char *tmp = kstrdup(name, GFP_KERNEL); |
| 922 | |
| 923 | if (tmp) { |
| 924 | ovl_unescape(tmp); |
| 925 | err = ovl_mount_dir_noesc(tmp, path); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 926 | |
| 927 | if (!err) |
| 928 | if (ovl_dentry_remote(path->dentry)) { |
| 929 | pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n", |
| 930 | tmp); |
| 931 | path_put(path); |
| 932 | err = -EINVAL; |
| 933 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 934 | kfree(tmp); |
| 935 | } |
| 936 | return err; |
| 937 | } |
| 938 | |
| 939 | static int ovl_lower_dir(const char *name, struct path *path, long *namelen, |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 940 | int *stack_depth, bool *remote) |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 941 | { |
| 942 | int err; |
| 943 | struct kstatfs statfs; |
| 944 | |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 945 | err = ovl_mount_dir_noesc(name, path); |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 946 | if (err) |
| 947 | goto out; |
| 948 | |
| 949 | err = vfs_statfs(path, &statfs); |
| 950 | if (err) { |
| 951 | pr_err("overlayfs: statfs failed on '%s'\n", name); |
| 952 | goto out_put; |
| 953 | } |
| 954 | *namelen = max(*namelen, statfs.f_namelen); |
| 955 | *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth); |
| 956 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 957 | if (ovl_dentry_remote(path->dentry)) |
| 958 | *remote = true; |
| 959 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 960 | return 0; |
| 961 | |
| 962 | out_put: |
| 963 | path_put(path); |
| 964 | out: |
| 965 | return err; |
| 966 | } |
| 967 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 968 | /* Workdir should not be subdir of upperdir and vice versa */ |
| 969 | static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir) |
| 970 | { |
| 971 | bool ok = false; |
| 972 | |
| 973 | if (workdir != upperdir) { |
| 974 | ok = (lock_rename(workdir, upperdir) == NULL); |
| 975 | unlock_rename(workdir, upperdir); |
| 976 | } |
| 977 | return ok; |
| 978 | } |
| 979 | |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 980 | static unsigned int ovl_split_lowerdirs(char *str) |
| 981 | { |
| 982 | unsigned int ctr = 1; |
| 983 | char *s, *d; |
| 984 | |
| 985 | for (s = d = str;; s++, d++) { |
| 986 | if (*s == '\\') { |
| 987 | s++; |
| 988 | } else if (*s == ':') { |
| 989 | *d = '\0'; |
| 990 | ctr++; |
| 991 | continue; |
| 992 | } |
| 993 | *d = *s; |
| 994 | if (!*s) |
| 995 | break; |
| 996 | } |
| 997 | return ctr; |
| 998 | } |
| 999 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1000 | static int __maybe_unused |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1001 | ovl_posix_acl_xattr_get(const struct xattr_handler *handler, |
| 1002 | struct dentry *dentry, struct inode *inode, |
| 1003 | const char *name, void *buffer, size_t size) |
| 1004 | { |
| 1005 | return ovl_xattr_get(dentry, handler->name, buffer, size); |
| 1006 | } |
| 1007 | |
| 1008 | static int __maybe_unused |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1009 | ovl_posix_acl_xattr_set(const struct xattr_handler *handler, |
| 1010 | struct dentry *dentry, struct inode *inode, |
| 1011 | const char *name, const void *value, |
| 1012 | size_t size, int flags) |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1013 | { |
| 1014 | struct dentry *workdir = ovl_workdir(dentry); |
| 1015 | struct inode *realinode = ovl_inode_real(inode, NULL); |
| 1016 | struct posix_acl *acl = NULL; |
| 1017 | int err; |
| 1018 | |
| 1019 | /* Check that everything is OK before copy-up */ |
| 1020 | if (value) { |
| 1021 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
| 1022 | if (IS_ERR(acl)) |
| 1023 | return PTR_ERR(acl); |
| 1024 | } |
| 1025 | err = -EOPNOTSUPP; |
| 1026 | if (!IS_POSIXACL(d_inode(workdir))) |
| 1027 | goto out_acl_release; |
| 1028 | if (!realinode->i_op->set_acl) |
| 1029 | goto out_acl_release; |
| 1030 | if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) { |
| 1031 | err = acl ? -EACCES : 0; |
| 1032 | goto out_acl_release; |
| 1033 | } |
| 1034 | err = -EPERM; |
| 1035 | if (!inode_owner_or_capable(inode)) |
| 1036 | goto out_acl_release; |
| 1037 | |
| 1038 | posix_acl_release(acl); |
| 1039 | |
Miklos Szeredi | fd3220d | 2016-10-31 14:42:14 +0100 | [diff] [blame] | 1040 | /* |
| 1041 | * Check if sgid bit needs to be cleared (actual setacl operation will |
| 1042 | * be done with mounter's capabilities and so that won't do it for us). |
| 1043 | */ |
| 1044 | if (unlikely(inode->i_mode & S_ISGID) && |
| 1045 | handler->flags == ACL_TYPE_ACCESS && |
| 1046 | !in_group_p(inode->i_gid) && |
| 1047 | !capable_wrt_inode_uidgid(inode, CAP_FSETID)) { |
| 1048 | struct iattr iattr = { .ia_valid = ATTR_KILL_SGID }; |
| 1049 | |
| 1050 | err = ovl_setattr(dentry, &iattr); |
| 1051 | if (err) |
| 1052 | return err; |
| 1053 | } |
| 1054 | |
Miklos Szeredi | ce31513 | 2016-09-01 11:12:00 +0200 | [diff] [blame] | 1055 | err = ovl_xattr_set(dentry, handler->name, value, size, flags); |
| 1056 | if (!err) |
| 1057 | ovl_copyattr(ovl_inode_real(inode, NULL), inode); |
| 1058 | |
| 1059 | return err; |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1060 | |
| 1061 | out_acl_release: |
| 1062 | posix_acl_release(acl); |
| 1063 | return err; |
| 1064 | } |
| 1065 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1066 | static int ovl_own_xattr_get(const struct xattr_handler *handler, |
| 1067 | struct dentry *dentry, struct inode *inode, |
| 1068 | const char *name, void *buffer, size_t size) |
| 1069 | { |
| 1070 | return -EPERM; |
| 1071 | } |
| 1072 | |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1073 | static int ovl_own_xattr_set(const struct xattr_handler *handler, |
| 1074 | struct dentry *dentry, struct inode *inode, |
| 1075 | const char *name, const void *value, |
| 1076 | size_t size, int flags) |
| 1077 | { |
| 1078 | return -EPERM; |
| 1079 | } |
| 1080 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1081 | static int ovl_other_xattr_get(const struct xattr_handler *handler, |
| 1082 | struct dentry *dentry, struct inode *inode, |
| 1083 | const char *name, void *buffer, size_t size) |
| 1084 | { |
| 1085 | return ovl_xattr_get(dentry, name, buffer, size); |
| 1086 | } |
| 1087 | |
Andreas Gruenbacher | 0e585cc | 2016-08-22 17:22:11 +0200 | [diff] [blame] | 1088 | static int ovl_other_xattr_set(const struct xattr_handler *handler, |
| 1089 | struct dentry *dentry, struct inode *inode, |
| 1090 | const char *name, const void *value, |
| 1091 | size_t size, int flags) |
| 1092 | { |
| 1093 | return ovl_xattr_set(dentry, name, value, size, flags); |
| 1094 | } |
| 1095 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1096 | static const struct xattr_handler __maybe_unused |
| 1097 | ovl_posix_acl_access_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1098 | .name = XATTR_NAME_POSIX_ACL_ACCESS, |
| 1099 | .flags = ACL_TYPE_ACCESS, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1100 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1101 | .set = ovl_posix_acl_xattr_set, |
| 1102 | }; |
| 1103 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1104 | static const struct xattr_handler __maybe_unused |
| 1105 | ovl_posix_acl_default_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1106 | .name = XATTR_NAME_POSIX_ACL_DEFAULT, |
| 1107 | .flags = ACL_TYPE_DEFAULT, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1108 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1109 | .set = ovl_posix_acl_xattr_set, |
| 1110 | }; |
| 1111 | |
| 1112 | static const struct xattr_handler ovl_own_xattr_handler = { |
| 1113 | .prefix = OVL_XATTR_PREFIX, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1114 | .get = ovl_own_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1115 | .set = ovl_own_xattr_set, |
| 1116 | }; |
| 1117 | |
| 1118 | static const struct xattr_handler ovl_other_xattr_handler = { |
| 1119 | .prefix = "", /* catch all */ |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 1120 | .get = ovl_other_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1121 | .set = ovl_other_xattr_set, |
| 1122 | }; |
| 1123 | |
| 1124 | static const struct xattr_handler *ovl_xattr_handlers[] = { |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1125 | #ifdef CONFIG_FS_POSIX_ACL |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1126 | &ovl_posix_acl_access_xattr_handler, |
| 1127 | &ovl_posix_acl_default_xattr_handler, |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 1128 | #endif |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1129 | &ovl_own_xattr_handler, |
| 1130 | &ovl_other_xattr_handler, |
| 1131 | NULL |
| 1132 | }; |
| 1133 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1134 | static int ovl_fill_super(struct super_block *sb, void *data, int silent) |
| 1135 | { |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1136 | struct path upperpath = { NULL, NULL }; |
| 1137 | struct path workpath = { NULL, NULL }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1138 | struct dentry *root_dentry; |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1139 | struct inode *realinode; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1140 | struct ovl_entry *oe; |
| 1141 | struct ovl_fs *ufs; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1142 | struct path *stack = NULL; |
| 1143 | char *lowertmp; |
| 1144 | char *lower; |
| 1145 | unsigned int numlower; |
| 1146 | unsigned int stacklen = 0; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1147 | unsigned int i; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 1148 | bool remote = false; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1149 | int err; |
| 1150 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1151 | err = -ENOMEM; |
| 1152 | ufs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL); |
| 1153 | if (!ufs) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1154 | goto out; |
| 1155 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1156 | err = ovl_parse_opt((char *) data, &ufs->config); |
| 1157 | if (err) |
| 1158 | goto out_free_config; |
| 1159 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1160 | err = -EINVAL; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1161 | if (!ufs->config.lowerdir) { |
Konstantin Khlebnikov | 07f2af7 | 2015-06-29 20:18:56 +0300 | [diff] [blame] | 1162 | if (!silent) |
| 1163 | pr_err("overlayfs: missing 'lowerdir'\n"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1164 | goto out_free_config; |
| 1165 | } |
| 1166 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1167 | sb->s_stack_depth = 0; |
Miklos Szeredi | cf9a678 | 2015-12-11 16:30:49 +0100 | [diff] [blame] | 1168 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1169 | if (ufs->config.upperdir) { |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1170 | if (!ufs->config.workdir) { |
| 1171 | pr_err("overlayfs: missing 'workdir'\n"); |
| 1172 | goto out_free_config; |
| 1173 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1174 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1175 | err = ovl_mount_dir(ufs->config.upperdir, &upperpath); |
| 1176 | if (err) |
| 1177 | goto out_free_config; |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1178 | |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 1179 | /* Upper fs should not be r/o */ |
| 1180 | if (upperpath.mnt->mnt_sb->s_flags & MS_RDONLY) { |
| 1181 | pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n"); |
| 1182 | err = -EINVAL; |
| 1183 | goto out_put_upperpath; |
| 1184 | } |
| 1185 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1186 | err = ovl_mount_dir(ufs->config.workdir, &workpath); |
| 1187 | if (err) |
| 1188 | goto out_put_upperpath; |
| 1189 | |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 1190 | err = -EINVAL; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1191 | if (upperpath.mnt != workpath.mnt) { |
| 1192 | pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); |
| 1193 | goto out_put_workpath; |
| 1194 | } |
| 1195 | if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) { |
| 1196 | pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); |
| 1197 | goto out_put_workpath; |
| 1198 | } |
| 1199 | sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 1200 | } |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1201 | err = -ENOMEM; |
| 1202 | lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL); |
| 1203 | if (!lowertmp) |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1204 | goto out_put_workpath; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1205 | |
| 1206 | err = -EINVAL; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1207 | stacklen = ovl_split_lowerdirs(lowertmp); |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 1208 | if (stacklen > OVL_MAX_STACK) { |
Colin Ian King | fd36570 | 2016-08-18 16:58:35 +0100 | [diff] [blame] | 1209 | pr_err("overlayfs: too many lower directories, limit is %d\n", |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 1210 | OVL_MAX_STACK); |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1211 | goto out_free_lowertmp; |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 1212 | } else if (!ufs->config.upperdir && stacklen == 1) { |
| 1213 | pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n"); |
| 1214 | goto out_free_lowertmp; |
| 1215 | } |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1216 | |
| 1217 | stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL); |
| 1218 | if (!stack) |
| 1219 | goto out_free_lowertmp; |
| 1220 | |
| 1221 | lower = lowertmp; |
| 1222 | for (numlower = 0; numlower < stacklen; numlower++) { |
| 1223 | err = ovl_lower_dir(lower, &stack[numlower], |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 1224 | &ufs->lower_namelen, &sb->s_stack_depth, |
| 1225 | &remote); |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1226 | if (err) |
| 1227 | goto out_put_lowerpath; |
| 1228 | |
| 1229 | lower = strchr(lower, '\0') + 1; |
| 1230 | } |
| 1231 | |
| 1232 | err = -EINVAL; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 1233 | sb->s_stack_depth++; |
Miklos Szeredi | 69c433e | 2014-10-24 00:14:39 +0200 | [diff] [blame] | 1234 | if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { |
| 1235 | pr_err("overlayfs: maximum fs stacking depth exceeded\n"); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1236 | goto out_put_lowerpath; |
Miklos Szeredi | 69c433e | 2014-10-24 00:14:39 +0200 | [diff] [blame] | 1237 | } |
| 1238 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1239 | if (ufs->config.upperdir) { |
| 1240 | ufs->upper_mnt = clone_private_mount(&upperpath); |
| 1241 | err = PTR_ERR(ufs->upper_mnt); |
| 1242 | if (IS_ERR(ufs->upper_mnt)) { |
| 1243 | pr_err("overlayfs: failed to clone upperpath\n"); |
| 1244 | goto out_put_lowerpath; |
| 1245 | } |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 1246 | /* Don't inherit atime flags */ |
| 1247 | ufs->upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME); |
| 1248 | |
| 1249 | sb->s_time_gran = ufs->upper_mnt->mnt_sb->s_time_gran; |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1250 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1251 | ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry); |
| 1252 | err = PTR_ERR(ufs->workdir); |
| 1253 | if (IS_ERR(ufs->workdir)) { |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 1254 | pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n", |
| 1255 | ufs->config.workdir, OVL_WORKDIR_NAME, -err); |
| 1256 | sb->s_flags |= MS_RDONLY; |
| 1257 | ufs->workdir = NULL; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1258 | } |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 1259 | |
| 1260 | /* |
| 1261 | * Upper should support d_type, else whiteouts are visible. |
| 1262 | * Given workdir and upper are on same fs, we can do |
Vivek Goyal | 2176519 | 2016-05-20 09:04:26 -0400 | [diff] [blame] | 1263 | * iterate_dir() on workdir. This check requires successful |
| 1264 | * creation of workdir in previous step. |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 1265 | */ |
Vivek Goyal | 2176519 | 2016-05-20 09:04:26 -0400 | [diff] [blame] | 1266 | if (ufs->workdir) { |
| 1267 | err = ovl_check_d_type_supported(&workpath); |
| 1268 | if (err < 0) |
| 1269 | goto out_put_workdir; |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 1270 | |
Vivek Goyal | e7c0b59 | 2016-07-01 10:02:44 -0400 | [diff] [blame] | 1271 | /* |
| 1272 | * We allowed this configuration and don't want to |
| 1273 | * break users over kernel upgrade. So warn instead |
| 1274 | * of erroring out. |
| 1275 | */ |
| 1276 | if (!err) |
| 1277 | pr_warn("overlayfs: upper fs needs to support d_type.\n"); |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 1278 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 1281 | err = -ENOMEM; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1282 | ufs->lower_mnt = kcalloc(numlower, sizeof(struct vfsmount *), GFP_KERNEL); |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1283 | if (ufs->lower_mnt == NULL) |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1284 | goto out_put_workdir; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1285 | for (i = 0; i < numlower; i++) { |
| 1286 | struct vfsmount *mnt = clone_private_mount(&stack[i]); |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1287 | |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 1288 | err = PTR_ERR(mnt); |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1289 | if (IS_ERR(mnt)) { |
| 1290 | pr_err("overlayfs: failed to clone lowerpath\n"); |
| 1291 | goto out_put_lower_mnt; |
| 1292 | } |
| 1293 | /* |
| 1294 | * Make lower_mnt R/O. That way fchmod/fchown on lower file |
| 1295 | * will fail instead of modifying lower fs. |
| 1296 | */ |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 1297 | mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1298 | |
| 1299 | ufs->lower_mnt[ufs->numlower] = mnt; |
| 1300 | ufs->numlower++; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1301 | } |
| 1302 | |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 1303 | /* If the upper fs is nonexistent, we mark overlayfs r/o too */ |
| 1304 | if (!ufs->upper_mnt) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1305 | sb->s_flags |= MS_RDONLY; |
| 1306 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 1307 | if (remote) |
| 1308 | sb->s_d_op = &ovl_reval_dentry_operations; |
| 1309 | else |
| 1310 | sb->s_d_op = &ovl_dentry_operations; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1311 | |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 1312 | ufs->creator_cred = prepare_creds(); |
| 1313 | if (!ufs->creator_cred) |
| 1314 | goto out_put_lower_mnt; |
| 1315 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1316 | err = -ENOMEM; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1317 | oe = ovl_alloc_entry(numlower); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1318 | if (!oe) |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 1319 | goto out_put_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1320 | |
Vivek Goyal | 655042c | 2016-10-14 03:03:36 +0200 | [diff] [blame] | 1321 | sb->s_magic = OVERLAYFS_SUPER_MAGIC; |
| 1322 | sb->s_op = &ovl_super_operations; |
| 1323 | sb->s_xattr = ovl_xattr_handlers; |
| 1324 | sb->s_fs_info = ufs; |
| 1325 | sb->s_flags |= MS_POSIXACL | MS_NOREMOTELOCK; |
| 1326 | |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1327 | root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1328 | if (!root_dentry) |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1329 | goto out_free_oe; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1330 | |
| 1331 | mntput(upperpath.mnt); |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1332 | for (i = 0; i < numlower; i++) |
| 1333 | mntput(stack[i].mnt); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1334 | path_put(&workpath); |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1335 | kfree(lowertmp); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1336 | |
| 1337 | oe->__upperdentry = upperpath.dentry; |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1338 | for (i = 0; i < numlower; i++) { |
| 1339 | oe->lowerstack[i].dentry = stack[i].dentry; |
| 1340 | oe->lowerstack[i].mnt = ufs->lower_mnt[i]; |
| 1341 | } |
Konstantin Khlebnikov | 0f95502 | 2015-08-24 15:57:18 +0300 | [diff] [blame] | 1342 | kfree(stack); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1343 | |
| 1344 | root_dentry->d_fsdata = oe; |
| 1345 | |
Miklos Szeredi | 39b681f | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 1346 | realinode = d_inode(ovl_dentry_real(root_dentry)); |
| 1347 | ovl_inode_init(d_inode(root_dentry), realinode, !!upperpath.dentry); |
| 1348 | ovl_copyattr(realinode, d_inode(root_dentry)); |
Miklos Szeredi | ed06e06 | 2015-12-09 16:11:59 +0100 | [diff] [blame] | 1349 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1350 | sb->s_root = root_dentry; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1351 | |
| 1352 | return 0; |
| 1353 | |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1354 | out_free_oe: |
| 1355 | kfree(oe); |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 1356 | out_put_cred: |
| 1357 | put_cred(ufs->creator_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1358 | out_put_lower_mnt: |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1359 | for (i = 0; i < ufs->numlower; i++) |
| 1360 | mntput(ufs->lower_mnt[i]); |
| 1361 | kfree(ufs->lower_mnt); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1362 | out_put_workdir: |
| 1363 | dput(ufs->workdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1364 | mntput(ufs->upper_mnt); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1365 | out_put_lowerpath: |
Miklos Szeredi | a78d9f0d | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1366 | for (i = 0; i < numlower; i++) |
| 1367 | path_put(&stack[i]); |
| 1368 | kfree(stack); |
| 1369 | out_free_lowertmp: |
| 1370 | kfree(lowertmp); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1371 | out_put_workpath: |
| 1372 | path_put(&workpath); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1373 | out_put_upperpath: |
| 1374 | path_put(&upperpath); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1375 | out_free_config: |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1376 | kfree(ufs->config.lowerdir); |
| 1377 | kfree(ufs->config.upperdir); |
| 1378 | kfree(ufs->config.workdir); |
| 1379 | kfree(ufs); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1380 | out: |
| 1381 | return err; |
| 1382 | } |
| 1383 | |
| 1384 | static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags, |
| 1385 | const char *dev_name, void *raw_data) |
| 1386 | { |
| 1387 | return mount_nodev(fs_type, flags, raw_data, ovl_fill_super); |
| 1388 | } |
| 1389 | |
| 1390 | static struct file_system_type ovl_fs_type = { |
| 1391 | .owner = THIS_MODULE, |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1392 | .name = "overlay", |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1393 | .mount = ovl_mount, |
| 1394 | .kill_sb = kill_anon_super, |
| 1395 | }; |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1396 | MODULE_ALIAS_FS("overlay"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1397 | |
| 1398 | static int __init ovl_init(void) |
| 1399 | { |
| 1400 | return register_filesystem(&ovl_fs_type); |
| 1401 | } |
| 1402 | |
| 1403 | static void __exit ovl_exit(void) |
| 1404 | { |
| 1405 | unregister_filesystem(&ovl_fs_type); |
| 1406 | } |
| 1407 | |
| 1408 | module_init(ovl_init); |
| 1409 | module_exit(ovl_exit); |