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 | |
Ingo Molnar | 5b825c3 | 2017-02-02 17:54:15 +0100 | [diff] [blame] | 10 | #include <uapi/linux/magic.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 11 | #include <linux/fs.h> |
| 12 | #include <linux/namei.h> |
| 13 | #include <linux/xattr.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 14 | #include <linux/mount.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 15 | #include <linux/parser.h> |
| 16 | #include <linux/module.h> |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 17 | #include <linux/statfs.h> |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 18 | #include <linux/seq_file.h> |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 19 | #include <linux/posix_acl_xattr.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 20 | #include "overlayfs.h" |
| 21 | |
| 22 | MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>"); |
| 23 | MODULE_DESCRIPTION("Overlay filesystem"); |
| 24 | MODULE_LICENSE("GPL"); |
| 25 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 26 | |
| 27 | struct ovl_dir_cache; |
| 28 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 29 | #define OVL_MAX_STACK 500 |
| 30 | |
Miklos Szeredi | 688ea0e | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 31 | static bool ovl_redirect_dir_def = IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR); |
| 32 | module_param_named(redirect_dir, ovl_redirect_dir_def, bool, 0644); |
| 33 | MODULE_PARM_DESC(ovl_redirect_dir_def, |
| 34 | "Default to on or off for the redirect_dir feature"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 35 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 36 | static bool ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX); |
| 37 | module_param_named(index, ovl_index_def, bool, 0644); |
| 38 | MODULE_PARM_DESC(ovl_index_def, |
| 39 | "Default to on or off for the inodes index feature"); |
| 40 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 41 | static void ovl_dentry_release(struct dentry *dentry) |
| 42 | { |
| 43 | struct ovl_entry *oe = dentry->d_fsdata; |
| 44 | |
| 45 | if (oe) { |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 46 | unsigned int i; |
| 47 | |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 48 | for (i = 0; i < oe->numlower; i++) |
| 49 | dput(oe->lowerstack[i].dentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 50 | kfree_rcu(oe, rcu); |
| 51 | } |
| 52 | } |
| 53 | |
Amir Goldstein | b0990fb | 2017-04-08 14:49:07 +0300 | [diff] [blame] | 54 | static int ovl_check_append_only(struct inode *inode, int flag) |
| 55 | { |
| 56 | /* |
| 57 | * This test was moot in vfs may_open() because overlay inode does |
| 58 | * not have the S_APPEND flag, so re-check on real upper inode |
| 59 | */ |
| 60 | if (IS_APPEND(inode)) { |
| 61 | if ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND)) |
| 62 | return -EPERM; |
| 63 | if (flag & O_TRUNC) |
| 64 | return -EPERM; |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 70 | static struct dentry *ovl_d_real(struct dentry *dentry, |
| 71 | const struct inode *inode, |
Miklos Szeredi | 495e642 | 2017-09-04 21:42:22 +0200 | [diff] [blame] | 72 | unsigned int open_flags, unsigned int flags) |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 73 | { |
| 74 | struct dentry *real; |
Amir Goldstein | b0990fb | 2017-04-08 14:49:07 +0300 | [diff] [blame] | 75 | int err; |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 76 | |
Miklos Szeredi | cd91304 | 2017-09-05 12:53:11 +0200 | [diff] [blame] | 77 | if (flags & D_REAL_UPPER) |
| 78 | return ovl_dentry_upper(dentry); |
| 79 | |
Miklos Szeredi | ca4c8a3 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 80 | if (!d_is_reg(dentry)) { |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 81 | if (!inode || inode == d_inode(dentry)) |
| 82 | return dentry; |
| 83 | goto bug; |
| 84 | } |
| 85 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 86 | if (open_flags) { |
Amir Goldstein | b0990fb | 2017-04-08 14:49:07 +0300 | [diff] [blame] | 87 | err = ovl_open_maybe_copy_up(dentry, open_flags); |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 88 | if (err) |
| 89 | return ERR_PTR(err); |
| 90 | } |
| 91 | |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 92 | real = ovl_dentry_upper(dentry); |
Amir Goldstein | b0990fb | 2017-04-08 14:49:07 +0300 | [diff] [blame] | 93 | if (real && (!inode || inode == d_inode(real))) { |
| 94 | if (!inode) { |
| 95 | err = ovl_check_append_only(d_inode(real), open_flags); |
| 96 | if (err) |
| 97 | return ERR_PTR(err); |
| 98 | } |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 99 | return real; |
Amir Goldstein | b0990fb | 2017-04-08 14:49:07 +0300 | [diff] [blame] | 100 | } |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 101 | |
| 102 | real = ovl_dentry_lower(dentry); |
| 103 | if (!real) |
| 104 | goto bug; |
| 105 | |
Miklos Szeredi | c4fcfc1 | 2016-11-29 10:20:24 +0100 | [diff] [blame] | 106 | /* Handle recursion */ |
Miklos Szeredi | 495e642 | 2017-09-04 21:42:22 +0200 | [diff] [blame] | 107 | real = d_real(real, inode, open_flags, 0); |
Miklos Szeredi | c4fcfc1 | 2016-11-29 10:20:24 +0100 | [diff] [blame] | 108 | |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 109 | if (!inode || inode == d_inode(real)) |
| 110 | return real; |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 111 | bug: |
Miklos Szeredi | 656189d | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 112 | 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] | 113 | inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0); |
| 114 | return dentry; |
| 115 | } |
| 116 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 117 | static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) |
| 118 | { |
| 119 | struct ovl_entry *oe = dentry->d_fsdata; |
| 120 | unsigned int i; |
| 121 | int ret = 1; |
| 122 | |
| 123 | for (i = 0; i < oe->numlower; i++) { |
| 124 | struct dentry *d = oe->lowerstack[i].dentry; |
| 125 | |
| 126 | if (d->d_flags & DCACHE_OP_REVALIDATE) { |
| 127 | ret = d->d_op->d_revalidate(d, flags); |
| 128 | if (ret < 0) |
| 129 | return ret; |
| 130 | if (!ret) { |
| 131 | if (!(flags & LOOKUP_RCU)) |
| 132 | d_invalidate(d); |
| 133 | return -ESTALE; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | return 1; |
| 138 | } |
| 139 | |
| 140 | static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) |
| 141 | { |
| 142 | struct ovl_entry *oe = dentry->d_fsdata; |
| 143 | unsigned int i; |
| 144 | int ret = 1; |
| 145 | |
| 146 | for (i = 0; i < oe->numlower; i++) { |
| 147 | struct dentry *d = oe->lowerstack[i].dentry; |
| 148 | |
| 149 | if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) { |
| 150 | ret = d->d_op->d_weak_revalidate(d, flags); |
| 151 | if (ret <= 0) |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | return ret; |
| 156 | } |
| 157 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 158 | static const struct dentry_operations ovl_dentry_operations = { |
| 159 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 160 | .d_real = ovl_d_real, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 161 | }; |
| 162 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 163 | static const struct dentry_operations ovl_reval_dentry_operations = { |
| 164 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 165 | .d_real = ovl_d_real, |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 166 | .d_revalidate = ovl_dentry_revalidate, |
| 167 | .d_weak_revalidate = ovl_dentry_weak_revalidate, |
| 168 | }; |
| 169 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 170 | static struct kmem_cache *ovl_inode_cachep; |
| 171 | |
| 172 | static struct inode *ovl_alloc_inode(struct super_block *sb) |
| 173 | { |
| 174 | struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL); |
| 175 | |
Hirofumi Nakagawa | b3885bd | 2017-09-26 03:09:53 +0900 | [diff] [blame] | 176 | if (!oi) |
| 177 | return NULL; |
| 178 | |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 179 | oi->cache = NULL; |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 180 | oi->redirect = NULL; |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 181 | oi->version = 0; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 182 | oi->flags = 0; |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 183 | oi->__upperdentry = NULL; |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 184 | oi->lower = NULL; |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 185 | mutex_init(&oi->lock); |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 186 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 187 | return &oi->vfs_inode; |
| 188 | } |
| 189 | |
| 190 | static void ovl_i_callback(struct rcu_head *head) |
| 191 | { |
| 192 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 193 | |
| 194 | kmem_cache_free(ovl_inode_cachep, OVL_I(inode)); |
| 195 | } |
| 196 | |
| 197 | static void ovl_destroy_inode(struct inode *inode) |
| 198 | { |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 199 | struct ovl_inode *oi = OVL_I(inode); |
| 200 | |
| 201 | dput(oi->__upperdentry); |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 202 | kfree(oi->redirect); |
Miklos Szeredi | 4edb83b | 2017-07-27 21:54:06 +0200 | [diff] [blame] | 203 | ovl_dir_cache_free(inode); |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 204 | mutex_destroy(&oi->lock); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 205 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 206 | call_rcu(&inode->i_rcu, ovl_i_callback); |
| 207 | } |
| 208 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 209 | static void ovl_put_super(struct super_block *sb) |
| 210 | { |
| 211 | struct ovl_fs *ufs = sb->s_fs_info; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 212 | unsigned i; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 213 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 214 | dput(ufs->indexdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 215 | dput(ufs->workdir); |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 216 | if (ufs->workdir_locked) |
| 217 | ovl_inuse_unlock(ufs->workbasedir); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 218 | dput(ufs->workbasedir); |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 219 | if (ufs->upper_mnt && ufs->upperdir_locked) |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 220 | ovl_inuse_unlock(ufs->upper_mnt->mnt_root); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 221 | mntput(ufs->upper_mnt); |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 222 | for (i = 0; i < ufs->numlower; i++) |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 223 | mntput(ufs->lower_layers[i].mnt); |
| 224 | kfree(ufs->lower_layers); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 225 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 226 | kfree(ufs->config.lowerdir); |
| 227 | kfree(ufs->config.upperdir); |
| 228 | kfree(ufs->config.workdir); |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 229 | put_cred(ufs->creator_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 230 | kfree(ufs); |
| 231 | } |
| 232 | |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 233 | static int ovl_sync_fs(struct super_block *sb, int wait) |
| 234 | { |
| 235 | struct ovl_fs *ufs = sb->s_fs_info; |
| 236 | struct super_block *upper_sb; |
| 237 | int ret; |
| 238 | |
| 239 | if (!ufs->upper_mnt) |
| 240 | return 0; |
| 241 | upper_sb = ufs->upper_mnt->mnt_sb; |
| 242 | if (!upper_sb->s_op->sync_fs) |
| 243 | return 0; |
| 244 | |
| 245 | /* real inodes have already been synced by sync_filesystem(ovl_sb) */ |
| 246 | down_read(&upper_sb->s_umount); |
| 247 | ret = upper_sb->s_op->sync_fs(upper_sb, wait); |
| 248 | up_read(&upper_sb->s_umount); |
| 249 | return ret; |
| 250 | } |
| 251 | |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 252 | /** |
| 253 | * ovl_statfs |
| 254 | * @sb: The overlayfs super block |
| 255 | * @buf: The struct kstatfs to fill in with stats |
| 256 | * |
| 257 | * Get the filesystem statistics. As writes always target the upper layer |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 258 | * filesystem pass the statfs to the upper filesystem (if it exists) |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 259 | */ |
| 260 | static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 261 | { |
| 262 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 263 | struct dentry *root_dentry = dentry->d_sb->s_root; |
| 264 | struct path path; |
| 265 | int err; |
| 266 | |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 267 | ovl_path_real(root_dentry, &path); |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 268 | |
| 269 | err = vfs_statfs(&path, buf); |
| 270 | if (!err) { |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 271 | buf->f_namelen = ofs->namelen; |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 272 | buf->f_type = OVERLAYFS_SUPER_MAGIC; |
| 273 | } |
| 274 | |
| 275 | return err; |
| 276 | } |
| 277 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 278 | /* Will this overlay be forced to mount/remount ro? */ |
| 279 | static bool ovl_force_readonly(struct ovl_fs *ufs) |
| 280 | { |
| 281 | return (!ufs->upper_mnt || !ufs->workdir); |
| 282 | } |
| 283 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 284 | /** |
| 285 | * ovl_show_options |
| 286 | * |
| 287 | * Prints the mount options for a given superblock. |
| 288 | * Returns zero; does not fail. |
| 289 | */ |
| 290 | static int ovl_show_options(struct seq_file *m, struct dentry *dentry) |
| 291 | { |
| 292 | struct super_block *sb = dentry->d_sb; |
| 293 | struct ovl_fs *ufs = sb->s_fs_info; |
| 294 | |
Kees Cook | a068acf | 2015-09-04 15:44:57 -0700 | [diff] [blame] | 295 | seq_show_option(m, "lowerdir", ufs->config.lowerdir); |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 296 | if (ufs->config.upperdir) { |
Kees Cook | a068acf | 2015-09-04 15:44:57 -0700 | [diff] [blame] | 297 | seq_show_option(m, "upperdir", ufs->config.upperdir); |
| 298 | seq_show_option(m, "workdir", ufs->config.workdir); |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 299 | } |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 300 | if (ufs->config.default_permissions) |
| 301 | seq_puts(m, ",default_permissions"); |
Amir Goldstein | c5bef3a | 2016-11-22 11:47:09 +0200 | [diff] [blame] | 302 | if (ufs->config.redirect_dir != ovl_redirect_dir_def) |
| 303 | seq_printf(m, ",redirect_dir=%s", |
| 304 | ufs->config.redirect_dir ? "on" : "off"); |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 305 | if (ufs->config.index != ovl_index_def) |
| 306 | seq_printf(m, ",index=%s", |
| 307 | ufs->config.index ? "on" : "off"); |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 308 | return 0; |
| 309 | } |
| 310 | |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 311 | static int ovl_remount(struct super_block *sb, int *flags, char *data) |
| 312 | { |
| 313 | struct ovl_fs *ufs = sb->s_fs_info; |
| 314 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 315 | if (!(*flags & MS_RDONLY) && ovl_force_readonly(ufs)) |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 316 | return -EROFS; |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 321 | static const struct super_operations ovl_super_operations = { |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 322 | .alloc_inode = ovl_alloc_inode, |
| 323 | .destroy_inode = ovl_destroy_inode, |
| 324 | .drop_inode = generic_delete_inode, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 325 | .put_super = ovl_put_super, |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 326 | .sync_fs = ovl_sync_fs, |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 327 | .statfs = ovl_statfs, |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 328 | .show_options = ovl_show_options, |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 329 | .remount_fs = ovl_remount, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | enum { |
| 333 | OPT_LOWERDIR, |
| 334 | OPT_UPPERDIR, |
| 335 | OPT_WORKDIR, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 336 | OPT_DEFAULT_PERMISSIONS, |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 337 | OPT_REDIRECT_DIR_ON, |
| 338 | OPT_REDIRECT_DIR_OFF, |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 339 | OPT_INDEX_ON, |
| 340 | OPT_INDEX_OFF, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 341 | OPT_ERR, |
| 342 | }; |
| 343 | |
| 344 | static const match_table_t ovl_tokens = { |
| 345 | {OPT_LOWERDIR, "lowerdir=%s"}, |
| 346 | {OPT_UPPERDIR, "upperdir=%s"}, |
| 347 | {OPT_WORKDIR, "workdir=%s"}, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 348 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 349 | {OPT_REDIRECT_DIR_ON, "redirect_dir=on"}, |
| 350 | {OPT_REDIRECT_DIR_OFF, "redirect_dir=off"}, |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 351 | {OPT_INDEX_ON, "index=on"}, |
| 352 | {OPT_INDEX_OFF, "index=off"}, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 353 | {OPT_ERR, NULL} |
| 354 | }; |
| 355 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 356 | static char *ovl_next_opt(char **s) |
| 357 | { |
| 358 | char *sbegin = *s; |
| 359 | char *p; |
| 360 | |
| 361 | if (sbegin == NULL) |
| 362 | return NULL; |
| 363 | |
| 364 | for (p = sbegin; *p; p++) { |
| 365 | if (*p == '\\') { |
| 366 | p++; |
| 367 | if (!*p) |
| 368 | break; |
| 369 | } else if (*p == ',') { |
| 370 | *p = '\0'; |
| 371 | *s = p + 1; |
| 372 | return sbegin; |
| 373 | } |
| 374 | } |
| 375 | *s = NULL; |
| 376 | return sbegin; |
| 377 | } |
| 378 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 379 | static int ovl_parse_opt(char *opt, struct ovl_config *config) |
| 380 | { |
| 381 | char *p; |
| 382 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 383 | while ((p = ovl_next_opt(&opt)) != NULL) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 384 | int token; |
| 385 | substring_t args[MAX_OPT_ARGS]; |
| 386 | |
| 387 | if (!*p) |
| 388 | continue; |
| 389 | |
| 390 | token = match_token(p, ovl_tokens, args); |
| 391 | switch (token) { |
| 392 | case OPT_UPPERDIR: |
| 393 | kfree(config->upperdir); |
| 394 | config->upperdir = match_strdup(&args[0]); |
| 395 | if (!config->upperdir) |
| 396 | return -ENOMEM; |
| 397 | break; |
| 398 | |
| 399 | case OPT_LOWERDIR: |
| 400 | kfree(config->lowerdir); |
| 401 | config->lowerdir = match_strdup(&args[0]); |
| 402 | if (!config->lowerdir) |
| 403 | return -ENOMEM; |
| 404 | break; |
| 405 | |
| 406 | case OPT_WORKDIR: |
| 407 | kfree(config->workdir); |
| 408 | config->workdir = match_strdup(&args[0]); |
| 409 | if (!config->workdir) |
| 410 | return -ENOMEM; |
| 411 | break; |
| 412 | |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 413 | case OPT_DEFAULT_PERMISSIONS: |
| 414 | config->default_permissions = true; |
| 415 | break; |
| 416 | |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 417 | case OPT_REDIRECT_DIR_ON: |
| 418 | config->redirect_dir = true; |
| 419 | break; |
| 420 | |
| 421 | case OPT_REDIRECT_DIR_OFF: |
| 422 | config->redirect_dir = false; |
| 423 | break; |
| 424 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 425 | case OPT_INDEX_ON: |
| 426 | config->index = true; |
| 427 | break; |
| 428 | |
| 429 | case OPT_INDEX_OFF: |
| 430 | config->index = false; |
| 431 | break; |
| 432 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 433 | default: |
hujianyang | bead55e | 2015-01-15 13:17:36 +0800 | [diff] [blame] | 434 | pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 435 | return -EINVAL; |
| 436 | } |
| 437 | } |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 438 | |
| 439 | /* Workdir is useless in non-upper mount */ |
| 440 | if (!config->upperdir && config->workdir) { |
| 441 | pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n", |
| 442 | config->workdir); |
| 443 | kfree(config->workdir); |
| 444 | config->workdir = NULL; |
| 445 | } |
| 446 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | #define OVL_WORKDIR_NAME "work" |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 451 | #define OVL_INDEXDIR_NAME "index" |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 452 | |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 453 | static struct dentry *ovl_workdir_create(struct super_block *sb, |
| 454 | struct ovl_fs *ufs, |
| 455 | struct dentry *dentry, |
| 456 | const char *name, bool persist) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 457 | { |
| 458 | struct inode *dir = dentry->d_inode; |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 459 | struct vfsmount *mnt = ufs->upper_mnt; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 460 | struct dentry *work; |
| 461 | int err; |
| 462 | bool retried = false; |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 463 | bool locked = false; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 464 | |
| 465 | err = mnt_want_write(mnt); |
| 466 | if (err) |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 467 | goto out_err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 468 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 469 | inode_lock_nested(dir, I_MUTEX_PARENT); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 470 | locked = true; |
| 471 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 472 | retry: |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 473 | work = lookup_one_len(name, dentry, strlen(name)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 474 | |
| 475 | if (!IS_ERR(work)) { |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 476 | struct iattr attr = { |
| 477 | .ia_valid = ATTR_MODE, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 478 | .ia_mode = S_IFDIR | 0, |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 479 | }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 480 | |
| 481 | if (work->d_inode) { |
| 482 | err = -EEXIST; |
| 483 | if (retried) |
| 484 | goto out_dput; |
| 485 | |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 486 | if (persist) |
| 487 | goto out_unlock; |
| 488 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 489 | retried = true; |
Miklos Szeredi | eea2fb4 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 490 | ovl_workdir_cleanup(dir, mnt, work, 0); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 491 | dput(work); |
| 492 | goto retry; |
| 493 | } |
| 494 | |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 495 | err = ovl_create_real(dir, work, |
| 496 | &(struct cattr){.mode = S_IFDIR | 0}, |
| 497 | NULL, true); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 498 | if (err) |
| 499 | goto out_dput; |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 500 | |
Miklos Szeredi | cb348ed | 2016-10-04 14:40:44 +0200 | [diff] [blame] | 501 | /* |
| 502 | * Try to remove POSIX ACL xattrs from workdir. We are good if: |
| 503 | * |
| 504 | * a) success (there was a POSIX ACL xattr and was removed) |
| 505 | * b) -ENODATA (there was no POSIX ACL xattr) |
| 506 | * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported) |
| 507 | * |
| 508 | * There are various other error values that could effectively |
| 509 | * mean that the xattr doesn't exist (e.g. -ERANGE is returned |
| 510 | * if the xattr name is too long), but the set of filesystems |
| 511 | * allowed as upper are limited to "normal" ones, where checking |
| 512 | * for the above two errors is sufficient. |
| 513 | */ |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 514 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 515 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 516 | goto out_dput; |
| 517 | |
| 518 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 519 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 520 | goto out_dput; |
| 521 | |
| 522 | /* Clear any inherited mode bits */ |
| 523 | inode_lock(work->d_inode); |
| 524 | err = notify_change(work, &attr, NULL); |
| 525 | inode_unlock(work->d_inode); |
| 526 | if (err) |
| 527 | goto out_dput; |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 528 | } else { |
| 529 | err = PTR_ERR(work); |
| 530 | goto out_err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 531 | } |
| 532 | out_unlock: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 533 | mnt_drop_write(mnt); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 534 | if (locked) |
| 535 | inode_unlock(dir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 536 | |
| 537 | return work; |
| 538 | |
| 539 | out_dput: |
| 540 | dput(work); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 541 | out_err: |
| 542 | pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n", |
| 543 | ufs->config.workdir, name, -err); |
| 544 | sb->s_flags |= MS_RDONLY; |
| 545 | work = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 546 | goto out_unlock; |
| 547 | } |
| 548 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 549 | static void ovl_unescape(char *s) |
| 550 | { |
| 551 | char *d = s; |
| 552 | |
| 553 | for (;; s++, d++) { |
| 554 | if (*s == '\\') |
| 555 | s++; |
| 556 | *d = *s; |
| 557 | if (!*s) |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 562 | static int ovl_mount_dir_noesc(const char *name, struct path *path) |
| 563 | { |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 564 | int err = -EINVAL; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 565 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 566 | if (!*name) { |
| 567 | pr_err("overlayfs: empty lowerdir\n"); |
| 568 | goto out; |
| 569 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 570 | err = kern_path(name, LOOKUP_FOLLOW, path); |
| 571 | if (err) { |
| 572 | pr_err("overlayfs: failed to resolve '%s': %i\n", name, err); |
| 573 | goto out; |
| 574 | } |
| 575 | err = -EINVAL; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 576 | if (ovl_dentry_weird(path->dentry)) { |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 577 | pr_err("overlayfs: filesystem on '%s' not supported\n", name); |
| 578 | goto out_put; |
| 579 | } |
Miklos Szeredi | 2b8c30e | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 580 | if (!d_is_dir(path->dentry)) { |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 581 | pr_err("overlayfs: '%s' not a directory\n", name); |
| 582 | goto out_put; |
| 583 | } |
| 584 | return 0; |
| 585 | |
| 586 | out_put: |
| 587 | path_put(path); |
| 588 | out: |
| 589 | return err; |
| 590 | } |
| 591 | |
| 592 | static int ovl_mount_dir(const char *name, struct path *path) |
| 593 | { |
| 594 | int err = -ENOMEM; |
| 595 | char *tmp = kstrdup(name, GFP_KERNEL); |
| 596 | |
| 597 | if (tmp) { |
| 598 | ovl_unescape(tmp); |
| 599 | err = ovl_mount_dir_noesc(tmp, path); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 600 | |
| 601 | if (!err) |
| 602 | if (ovl_dentry_remote(path->dentry)) { |
| 603 | pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n", |
| 604 | tmp); |
| 605 | path_put(path); |
| 606 | err = -EINVAL; |
| 607 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 608 | kfree(tmp); |
| 609 | } |
| 610 | return err; |
| 611 | } |
| 612 | |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 613 | static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs, |
| 614 | const char *name) |
| 615 | { |
| 616 | struct kstatfs statfs; |
| 617 | int err = vfs_statfs(path, &statfs); |
| 618 | |
| 619 | if (err) |
| 620 | pr_err("overlayfs: statfs failed on '%s'\n", name); |
| 621 | else |
| 622 | ofs->namelen = max(ofs->namelen, statfs.f_namelen); |
| 623 | |
| 624 | return err; |
| 625 | } |
| 626 | |
| 627 | static int ovl_lower_dir(const char *name, struct path *path, |
| 628 | struct ovl_fs *ofs, int *stack_depth, bool *remote) |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 629 | { |
| 630 | int err; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 631 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 632 | err = ovl_mount_dir_noesc(name, path); |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 633 | if (err) |
| 634 | goto out; |
| 635 | |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 636 | err = ovl_check_namelen(path, ofs, name); |
| 637 | if (err) |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 638 | goto out_put; |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 639 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 640 | *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth); |
| 641 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 642 | if (ovl_dentry_remote(path->dentry)) |
| 643 | *remote = true; |
| 644 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 645 | /* |
| 646 | * The inodes index feature needs to encode and decode file |
| 647 | * handles, so it requires that all layers support them. |
| 648 | */ |
| 649 | if (ofs->config.index && !ovl_can_decode_fh(path->dentry->d_sb)) { |
| 650 | ofs->config.index = false; |
| 651 | pr_warn("overlayfs: fs on '%s' does not support file handles, falling back to index=off.\n", name); |
| 652 | } |
| 653 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 654 | return 0; |
| 655 | |
| 656 | out_put: |
| 657 | path_put(path); |
| 658 | out: |
| 659 | return err; |
| 660 | } |
| 661 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 662 | /* Workdir should not be subdir of upperdir and vice versa */ |
| 663 | static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir) |
| 664 | { |
| 665 | bool ok = false; |
| 666 | |
| 667 | if (workdir != upperdir) { |
| 668 | ok = (lock_rename(workdir, upperdir) == NULL); |
| 669 | unlock_rename(workdir, upperdir); |
| 670 | } |
| 671 | return ok; |
| 672 | } |
| 673 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 674 | static unsigned int ovl_split_lowerdirs(char *str) |
| 675 | { |
| 676 | unsigned int ctr = 1; |
| 677 | char *s, *d; |
| 678 | |
| 679 | for (s = d = str;; s++, d++) { |
| 680 | if (*s == '\\') { |
| 681 | s++; |
| 682 | } else if (*s == ':') { |
| 683 | *d = '\0'; |
| 684 | ctr++; |
| 685 | continue; |
| 686 | } |
| 687 | *d = *s; |
| 688 | if (!*s) |
| 689 | break; |
| 690 | } |
| 691 | return ctr; |
| 692 | } |
| 693 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 694 | static int __maybe_unused |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 695 | ovl_posix_acl_xattr_get(const struct xattr_handler *handler, |
| 696 | struct dentry *dentry, struct inode *inode, |
| 697 | const char *name, void *buffer, size_t size) |
| 698 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 699 | return ovl_xattr_get(dentry, inode, handler->name, buffer, size); |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static int __maybe_unused |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 703 | ovl_posix_acl_xattr_set(const struct xattr_handler *handler, |
| 704 | struct dentry *dentry, struct inode *inode, |
| 705 | const char *name, const void *value, |
| 706 | size_t size, int flags) |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 707 | { |
| 708 | struct dentry *workdir = ovl_workdir(dentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 709 | struct inode *realinode = ovl_inode_real(inode); |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 710 | struct posix_acl *acl = NULL; |
| 711 | int err; |
| 712 | |
| 713 | /* Check that everything is OK before copy-up */ |
| 714 | if (value) { |
| 715 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
| 716 | if (IS_ERR(acl)) |
| 717 | return PTR_ERR(acl); |
| 718 | } |
| 719 | err = -EOPNOTSUPP; |
| 720 | if (!IS_POSIXACL(d_inode(workdir))) |
| 721 | goto out_acl_release; |
| 722 | if (!realinode->i_op->set_acl) |
| 723 | goto out_acl_release; |
| 724 | if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) { |
| 725 | err = acl ? -EACCES : 0; |
| 726 | goto out_acl_release; |
| 727 | } |
| 728 | err = -EPERM; |
| 729 | if (!inode_owner_or_capable(inode)) |
| 730 | goto out_acl_release; |
| 731 | |
| 732 | posix_acl_release(acl); |
| 733 | |
Miklos Szeredi | fd3220d | 2016-10-31 14:42:14 +0100 | [diff] [blame] | 734 | /* |
| 735 | * Check if sgid bit needs to be cleared (actual setacl operation will |
| 736 | * be done with mounter's capabilities and so that won't do it for us). |
| 737 | */ |
| 738 | if (unlikely(inode->i_mode & S_ISGID) && |
| 739 | handler->flags == ACL_TYPE_ACCESS && |
| 740 | !in_group_p(inode->i_gid) && |
| 741 | !capable_wrt_inode_uidgid(inode, CAP_FSETID)) { |
| 742 | struct iattr iattr = { .ia_valid = ATTR_KILL_SGID }; |
| 743 | |
| 744 | err = ovl_setattr(dentry, &iattr); |
| 745 | if (err) |
| 746 | return err; |
| 747 | } |
| 748 | |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 749 | err = ovl_xattr_set(dentry, inode, handler->name, value, size, flags); |
Miklos Szeredi | ce31513 | 2016-09-01 11:12:00 +0200 | [diff] [blame] | 750 | if (!err) |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 751 | ovl_copyattr(ovl_inode_real(inode), inode); |
Miklos Szeredi | ce31513 | 2016-09-01 11:12:00 +0200 | [diff] [blame] | 752 | |
| 753 | return err; |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 754 | |
| 755 | out_acl_release: |
| 756 | posix_acl_release(acl); |
| 757 | return err; |
| 758 | } |
| 759 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 760 | static int ovl_own_xattr_get(const struct xattr_handler *handler, |
| 761 | struct dentry *dentry, struct inode *inode, |
| 762 | const char *name, void *buffer, size_t size) |
| 763 | { |
Amir Goldstein | 48fab5d | 2016-11-16 11:22:39 +0200 | [diff] [blame] | 764 | return -EOPNOTSUPP; |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 765 | } |
| 766 | |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 767 | static int ovl_own_xattr_set(const struct xattr_handler *handler, |
| 768 | struct dentry *dentry, struct inode *inode, |
| 769 | const char *name, const void *value, |
| 770 | size_t size, int flags) |
| 771 | { |
Amir Goldstein | 48fab5d | 2016-11-16 11:22:39 +0200 | [diff] [blame] | 772 | return -EOPNOTSUPP; |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 773 | } |
| 774 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 775 | static int ovl_other_xattr_get(const struct xattr_handler *handler, |
| 776 | struct dentry *dentry, struct inode *inode, |
| 777 | const char *name, void *buffer, size_t size) |
| 778 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 779 | return ovl_xattr_get(dentry, inode, name, buffer, size); |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 780 | } |
| 781 | |
Andreas Gruenbacher | 0e585cc | 2016-08-22 17:22:11 +0200 | [diff] [blame] | 782 | static int ovl_other_xattr_set(const struct xattr_handler *handler, |
| 783 | struct dentry *dentry, struct inode *inode, |
| 784 | const char *name, const void *value, |
| 785 | size_t size, int flags) |
| 786 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 787 | return ovl_xattr_set(dentry, inode, name, value, size, flags); |
Andreas Gruenbacher | 0e585cc | 2016-08-22 17:22:11 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 790 | static const struct xattr_handler __maybe_unused |
| 791 | ovl_posix_acl_access_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 792 | .name = XATTR_NAME_POSIX_ACL_ACCESS, |
| 793 | .flags = ACL_TYPE_ACCESS, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 794 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 795 | .set = ovl_posix_acl_xattr_set, |
| 796 | }; |
| 797 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 798 | static const struct xattr_handler __maybe_unused |
| 799 | ovl_posix_acl_default_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 800 | .name = XATTR_NAME_POSIX_ACL_DEFAULT, |
| 801 | .flags = ACL_TYPE_DEFAULT, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 802 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 803 | .set = ovl_posix_acl_xattr_set, |
| 804 | }; |
| 805 | |
| 806 | static const struct xattr_handler ovl_own_xattr_handler = { |
| 807 | .prefix = OVL_XATTR_PREFIX, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 808 | .get = ovl_own_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 809 | .set = ovl_own_xattr_set, |
| 810 | }; |
| 811 | |
| 812 | static const struct xattr_handler ovl_other_xattr_handler = { |
| 813 | .prefix = "", /* catch all */ |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 814 | .get = ovl_other_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 815 | .set = ovl_other_xattr_set, |
| 816 | }; |
| 817 | |
| 818 | static const struct xattr_handler *ovl_xattr_handlers[] = { |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 819 | #ifdef CONFIG_FS_POSIX_ACL |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 820 | &ovl_posix_acl_access_xattr_handler, |
| 821 | &ovl_posix_acl_default_xattr_handler, |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 822 | #endif |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 823 | &ovl_own_xattr_handler, |
| 824 | &ovl_other_xattr_handler, |
| 825 | NULL |
| 826 | }; |
| 827 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 828 | static int ovl_fill_super(struct super_block *sb, void *data, int silent) |
| 829 | { |
Kees Cook | 33006cd | 2017-03-29 14:02:19 -0700 | [diff] [blame] | 830 | struct path upperpath = { }; |
| 831 | struct path workpath = { }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 832 | struct dentry *root_dentry; |
| 833 | struct ovl_entry *oe; |
| 834 | struct ovl_fs *ufs; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 835 | struct path *stack = NULL; |
| 836 | char *lowertmp; |
| 837 | char *lower; |
| 838 | unsigned int numlower; |
| 839 | unsigned int stacklen = 0; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 840 | unsigned int i; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 841 | bool remote = false; |
Konstantin Khlebnikov | 51f8f3c | 2017-01-10 21:30:21 +0300 | [diff] [blame] | 842 | struct cred *cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 843 | int err; |
| 844 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 845 | err = -ENOMEM; |
| 846 | ufs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL); |
| 847 | if (!ufs) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 848 | goto out; |
| 849 | |
Miklos Szeredi | 688ea0e | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 850 | ufs->config.redirect_dir = ovl_redirect_dir_def; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 851 | ufs->config.index = ovl_index_def; |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 852 | err = ovl_parse_opt((char *) data, &ufs->config); |
| 853 | if (err) |
| 854 | goto out_free_config; |
| 855 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 856 | err = -EINVAL; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 857 | if (!ufs->config.lowerdir) { |
Konstantin Khlebnikov | 07f2af7 | 2015-06-29 20:18:56 +0300 | [diff] [blame] | 858 | if (!silent) |
| 859 | pr_err("overlayfs: missing 'lowerdir'\n"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 860 | goto out_free_config; |
| 861 | } |
| 862 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 863 | sb->s_stack_depth = 0; |
Miklos Szeredi | cf9a678 | 2015-12-11 16:30:49 +0100 | [diff] [blame] | 864 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 865 | if (ufs->config.upperdir) { |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 866 | if (!ufs->config.workdir) { |
| 867 | pr_err("overlayfs: missing 'workdir'\n"); |
| 868 | goto out_free_config; |
| 869 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 870 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 871 | err = ovl_mount_dir(ufs->config.upperdir, &upperpath); |
| 872 | if (err) |
| 873 | goto out_free_config; |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 874 | |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 875 | /* Upper fs should not be r/o */ |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 876 | if (sb_rdonly(upperpath.mnt->mnt_sb)) { |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 877 | pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n"); |
| 878 | err = -EINVAL; |
| 879 | goto out_put_upperpath; |
| 880 | } |
| 881 | |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 882 | err = ovl_check_namelen(&upperpath, ufs, ufs->config.upperdir); |
| 883 | if (err) |
| 884 | goto out_put_upperpath; |
| 885 | |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 886 | err = -EBUSY; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 887 | if (ovl_inuse_trylock(upperpath.dentry)) { |
| 888 | ufs->upperdir_locked = true; |
| 889 | } else if (ufs->config.index) { |
| 890 | pr_err("overlayfs: upperdir is in-use by another mount, mount with '-o index=off' to override exclusive upperdir protection.\n"); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 891 | goto out_put_upperpath; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 892 | } else { |
| 893 | pr_warn("overlayfs: upperdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 894 | } |
| 895 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 896 | err = ovl_mount_dir(ufs->config.workdir, &workpath); |
| 897 | if (err) |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 898 | goto out_unlock_upperdentry; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 899 | |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 900 | err = -EINVAL; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 901 | if (upperpath.mnt != workpath.mnt) { |
| 902 | pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); |
| 903 | goto out_put_workpath; |
| 904 | } |
| 905 | if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) { |
| 906 | pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); |
| 907 | goto out_put_workpath; |
| 908 | } |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 909 | |
| 910 | err = -EBUSY; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 911 | if (ovl_inuse_trylock(workpath.dentry)) { |
| 912 | ufs->workdir_locked = true; |
| 913 | } else if (ufs->config.index) { |
| 914 | pr_err("overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.\n"); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 915 | goto out_put_workpath; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 916 | } else { |
| 917 | pr_warn("overlayfs: workdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | ufs->workbasedir = workpath.dentry; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 921 | sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 922 | } |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 923 | err = -ENOMEM; |
| 924 | lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL); |
| 925 | if (!lowertmp) |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 926 | goto out_unlock_workdentry; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 927 | |
| 928 | err = -EINVAL; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 929 | stacklen = ovl_split_lowerdirs(lowertmp); |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 930 | if (stacklen > OVL_MAX_STACK) { |
Colin Ian King | fd36570 | 2016-08-18 16:58:35 +0100 | [diff] [blame] | 931 | pr_err("overlayfs: too many lower directories, limit is %d\n", |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 932 | OVL_MAX_STACK); |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 933 | goto out_free_lowertmp; |
hujianyang | 6be4506 | 2015-01-15 13:19:21 +0800 | [diff] [blame] | 934 | } else if (!ufs->config.upperdir && stacklen == 1) { |
| 935 | pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n"); |
| 936 | goto out_free_lowertmp; |
| 937 | } |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 938 | |
Geliang Tang | 313684c | 2016-11-18 23:02:46 +0800 | [diff] [blame] | 939 | err = -ENOMEM; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 940 | stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL); |
| 941 | if (!stack) |
| 942 | goto out_free_lowertmp; |
| 943 | |
Geliang Tang | 313684c | 2016-11-18 23:02:46 +0800 | [diff] [blame] | 944 | err = -EINVAL; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 945 | lower = lowertmp; |
| 946 | for (numlower = 0; numlower < stacklen; numlower++) { |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 947 | err = ovl_lower_dir(lower, &stack[numlower], ufs, |
| 948 | &sb->s_stack_depth, &remote); |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 949 | if (err) |
| 950 | goto out_put_lowerpath; |
| 951 | |
| 952 | lower = strchr(lower, '\0') + 1; |
| 953 | } |
| 954 | |
| 955 | err = -EINVAL; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 956 | sb->s_stack_depth++; |
Miklos Szeredi | 69c433e | 2014-10-24 00:14:39 +0200 | [diff] [blame] | 957 | if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { |
| 958 | pr_err("overlayfs: maximum fs stacking depth exceeded\n"); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 959 | goto out_put_lowerpath; |
Miklos Szeredi | 69c433e | 2014-10-24 00:14:39 +0200 | [diff] [blame] | 960 | } |
| 961 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 962 | if (ufs->config.upperdir) { |
| 963 | ufs->upper_mnt = clone_private_mount(&upperpath); |
| 964 | err = PTR_ERR(ufs->upper_mnt); |
| 965 | if (IS_ERR(ufs->upper_mnt)) { |
| 966 | pr_err("overlayfs: failed to clone upperpath\n"); |
| 967 | goto out_put_lowerpath; |
| 968 | } |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 969 | |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 970 | /* Don't inherit atime flags */ |
| 971 | ufs->upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME); |
| 972 | |
| 973 | sb->s_time_gran = ufs->upper_mnt->mnt_sb->s_time_gran; |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 974 | |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 975 | ufs->workdir = ovl_workdir_create(sb, ufs, workpath.dentry, |
| 976 | OVL_WORKDIR_NAME, false); |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 977 | /* |
| 978 | * Upper should support d_type, else whiteouts are visible. |
| 979 | * Given workdir and upper are on same fs, we can do |
Vivek Goyal | 2176519 | 2016-05-20 09:04:26 -0400 | [diff] [blame] | 980 | * iterate_dir() on workdir. This check requires successful |
| 981 | * creation of workdir in previous step. |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 982 | */ |
Vivek Goyal | 2176519 | 2016-05-20 09:04:26 -0400 | [diff] [blame] | 983 | if (ufs->workdir) { |
Amir Goldstein | e7f5242 | 2017-01-17 06:34:53 +0200 | [diff] [blame] | 984 | struct dentry *temp; |
| 985 | |
Vivek Goyal | 2176519 | 2016-05-20 09:04:26 -0400 | [diff] [blame] | 986 | err = ovl_check_d_type_supported(&workpath); |
| 987 | if (err < 0) |
| 988 | goto out_put_workdir; |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 989 | |
Vivek Goyal | e7c0b59 | 2016-07-01 10:02:44 -0400 | [diff] [blame] | 990 | /* |
| 991 | * We allowed this configuration and don't want to |
| 992 | * break users over kernel upgrade. So warn instead |
| 993 | * of erroring out. |
| 994 | */ |
| 995 | if (!err) |
| 996 | pr_warn("overlayfs: upper fs needs to support d_type.\n"); |
Amir Goldstein | e7f5242 | 2017-01-17 06:34:53 +0200 | [diff] [blame] | 997 | |
| 998 | /* Check if upper/work fs supports O_TMPFILE */ |
| 999 | temp = ovl_do_tmpfile(ufs->workdir, S_IFREG | 0); |
| 1000 | ufs->tmpfile = !IS_ERR(temp); |
| 1001 | if (ufs->tmpfile) |
| 1002 | dput(temp); |
| 1003 | else |
| 1004 | pr_warn("overlayfs: upper fs does not support tmpfile.\n"); |
Amir Goldstein | 82b749b | 2017-05-17 00:12:40 +0300 | [diff] [blame] | 1005 | |
| 1006 | /* |
| 1007 | * Check if upper/work fs supports trusted.overlay.* |
| 1008 | * xattr |
| 1009 | */ |
| 1010 | err = ovl_do_setxattr(ufs->workdir, OVL_XATTR_OPAQUE, |
| 1011 | "0", 1, 0); |
| 1012 | if (err) { |
| 1013 | ufs->noxattr = true; |
| 1014 | pr_warn("overlayfs: upper fs does not support xattr.\n"); |
| 1015 | } else { |
| 1016 | vfs_removexattr(ufs->workdir, OVL_XATTR_OPAQUE); |
| 1017 | } |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1018 | |
| 1019 | /* Check if upper/work fs supports file handles */ |
| 1020 | if (ufs->config.index && |
| 1021 | !ovl_can_decode_fh(ufs->workdir->d_sb)) { |
| 1022 | ufs->config.index = false; |
| 1023 | pr_warn("overlayfs: upper fs does not support file handles, falling back to index=off.\n"); |
| 1024 | } |
Vivek Goyal | 45aebea | 2016-02-22 09:28:34 -0500 | [diff] [blame] | 1025 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 1028 | err = -ENOMEM; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1029 | ufs->lower_layers = kcalloc(numlower, sizeof(struct ovl_layer), |
| 1030 | GFP_KERNEL); |
| 1031 | if (ufs->lower_layers == NULL) |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1032 | goto out_put_workdir; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1033 | for (i = 0; i < numlower; i++) { |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1034 | struct vfsmount *mnt; |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1035 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1036 | mnt = clone_private_mount(&stack[i]); |
hujianyang | 2f83fd8 | 2015-01-06 12:52:13 +0800 | [diff] [blame] | 1037 | err = PTR_ERR(mnt); |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1038 | if (IS_ERR(mnt)) { |
| 1039 | pr_err("overlayfs: failed to clone lowerpath\n"); |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1040 | goto out_put_lower_layers; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1041 | } |
| 1042 | /* |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1043 | * Make lower layers R/O. That way fchmod/fchown on lower file |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1044 | * will fail instead of modifying lower fs. |
| 1045 | */ |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 1046 | mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1047 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1048 | ufs->lower_layers[ufs->numlower].mnt = mnt; |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1049 | ufs->numlower++; |
Amir Goldstein | 7bcd74b | 2017-03-22 08:42:21 -0400 | [diff] [blame] | 1050 | |
| 1051 | /* Check if all lower layers are on same sb */ |
| 1052 | if (i == 0) |
| 1053 | ufs->same_sb = mnt->mnt_sb; |
| 1054 | else if (ufs->same_sb != mnt->mnt_sb) |
| 1055 | ufs->same_sb = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 1058 | /* If the upper fs is nonexistent, we mark overlayfs r/o too */ |
| 1059 | if (!ufs->upper_mnt) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1060 | sb->s_flags |= MS_RDONLY; |
Amir Goldstein | 7bcd74b | 2017-03-22 08:42:21 -0400 | [diff] [blame] | 1061 | else if (ufs->upper_mnt->mnt_sb != ufs->same_sb) |
| 1062 | ufs->same_sb = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1063 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1064 | err = -ENOMEM; |
| 1065 | oe = ovl_alloc_entry(numlower); |
| 1066 | if (!oe) |
| 1067 | goto out_put_lower_layers; |
| 1068 | |
| 1069 | for (i = 0; i < numlower; i++) { |
| 1070 | oe->lowerstack[i].dentry = stack[i].dentry; |
| 1071 | oe->lowerstack[i].layer = &(ufs->lower_layers[i]); |
| 1072 | } |
| 1073 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1074 | if (!(ovl_force_readonly(ufs)) && ufs->config.index) { |
Amir Goldstein | 8b88a2e | 2017-06-21 15:28:37 +0300 | [diff] [blame] | 1075 | /* Verify lower root is upper root origin */ |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1076 | err = ovl_verify_origin(upperpath.dentry, |
| 1077 | oe->lowerstack[0].layer->mnt, |
| 1078 | oe->lowerstack[0].dentry, |
| 1079 | false, true); |
Amir Goldstein | 8b88a2e | 2017-06-21 15:28:37 +0300 | [diff] [blame] | 1080 | if (err) { |
| 1081 | pr_err("overlayfs: failed to verify upper root origin\n"); |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1082 | goto out_free_oe; |
Amir Goldstein | 8b88a2e | 2017-06-21 15:28:37 +0300 | [diff] [blame] | 1083 | } |
| 1084 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1085 | ufs->indexdir = ovl_workdir_create(sb, ufs, workpath.dentry, |
| 1086 | OVL_INDEXDIR_NAME, true); |
Amir Goldstein | 54fb347 | 2017-06-21 15:28:38 +0300 | [diff] [blame] | 1087 | if (ufs->indexdir) { |
| 1088 | /* Verify upper root is index dir origin */ |
| 1089 | err = ovl_verify_origin(ufs->indexdir, ufs->upper_mnt, |
| 1090 | upperpath.dentry, true, true); |
| 1091 | if (err) |
| 1092 | pr_err("overlayfs: failed to verify index dir origin\n"); |
Amir Goldstein | 415543d | 2017-06-21 15:28:42 +0300 | [diff] [blame] | 1093 | |
Amir Goldstein | caf70cb | 2017-06-21 13:46:12 +0300 | [diff] [blame] | 1094 | /* Cleanup bad/stale/orphan index entries */ |
Amir Goldstein | 415543d | 2017-06-21 15:28:42 +0300 | [diff] [blame] | 1095 | if (!err) |
| 1096 | err = ovl_indexdir_cleanup(ufs->indexdir, |
| 1097 | ufs->upper_mnt, |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1098 | oe->lowerstack, |
| 1099 | numlower); |
Amir Goldstein | 54fb347 | 2017-06-21 15:28:38 +0300 | [diff] [blame] | 1100 | } |
| 1101 | if (err || !ufs->indexdir) |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1102 | pr_warn("overlayfs: try deleting index dir or mounting with '-o index=off' to disable inodes index.\n"); |
Amir Goldstein | 54fb347 | 2017-06-21 15:28:38 +0300 | [diff] [blame] | 1103 | if (err) |
| 1104 | goto out_put_indexdir; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /* Show index=off/on in /proc/mounts for any of the reasons above */ |
| 1108 | if (!ufs->indexdir) |
| 1109 | ufs->config.index = false; |
| 1110 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 1111 | if (remote) |
| 1112 | sb->s_d_op = &ovl_reval_dentry_operations; |
| 1113 | else |
| 1114 | sb->s_d_op = &ovl_dentry_operations; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1115 | |
Amir Goldstein | 8fc646b | 2017-07-11 15:58:35 +0300 | [diff] [blame] | 1116 | err = -ENOMEM; |
Konstantin Khlebnikov | 51f8f3c | 2017-01-10 21:30:21 +0300 | [diff] [blame] | 1117 | ufs->creator_cred = cred = prepare_creds(); |
| 1118 | if (!cred) |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1119 | goto out_put_indexdir; |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 1120 | |
Konstantin Khlebnikov | 51f8f3c | 2017-01-10 21:30:21 +0300 | [diff] [blame] | 1121 | /* Never override disk quota limits or use reserved space */ |
| 1122 | cap_lower(cred->cap_effective, CAP_SYS_RESOURCE); |
| 1123 | |
Vivek Goyal | 655042c | 2016-10-14 03:03:36 +0200 | [diff] [blame] | 1124 | sb->s_magic = OVERLAYFS_SUPER_MAGIC; |
| 1125 | sb->s_op = &ovl_super_operations; |
| 1126 | sb->s_xattr = ovl_xattr_handlers; |
| 1127 | sb->s_fs_info = ufs; |
| 1128 | sb->s_flags |= MS_POSIXACL | MS_NOREMOTELOCK; |
| 1129 | |
Miklos Szeredi | ca4c8a3 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 1130 | root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1131 | if (!root_dentry) |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1132 | goto out_put_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1133 | |
| 1134 | mntput(upperpath.mnt); |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1135 | for (i = 0; i < numlower; i++) |
| 1136 | mntput(stack[i].mnt); |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1137 | kfree(stack); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 1138 | mntput(workpath.mnt); |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1139 | kfree(lowertmp); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1140 | |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame] | 1141 | if (upperpath.dentry) { |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 1142 | oe->has_upper = true; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 1143 | if (ovl_is_impuredir(upperpath.dentry)) |
| 1144 | ovl_set_flag(OVL_IMPURE, d_inode(root_dentry)); |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame] | 1145 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1146 | |
| 1147 | root_dentry->d_fsdata = oe; |
| 1148 | |
Amir Goldstein | b79e05a | 2017-06-25 16:37:17 +0300 | [diff] [blame] | 1149 | /* Root is always merge -> can have whiteouts */ |
| 1150 | ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry)); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 1151 | ovl_inode_init(d_inode(root_dentry), upperpath.dentry, |
| 1152 | ovl_dentry_lower(root_dentry)); |
Miklos Szeredi | ed06e06 | 2015-12-09 16:11:59 +0100 | [diff] [blame] | 1153 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1154 | sb->s_root = root_dentry; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 1158 | out_put_cred: |
| 1159 | put_cred(ufs->creator_cred); |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1160 | out_put_indexdir: |
| 1161 | dput(ufs->indexdir); |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1162 | out_free_oe: |
| 1163 | kfree(oe); |
| 1164 | out_put_lower_layers: |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 1165 | for (i = 0; i < ufs->numlower; i++) |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame^] | 1166 | mntput(ufs->lower_layers[i].mnt); |
| 1167 | kfree(ufs->lower_layers); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1168 | out_put_workdir: |
| 1169 | dput(ufs->workdir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1170 | mntput(ufs->upper_mnt); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1171 | out_put_lowerpath: |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 1172 | for (i = 0; i < numlower; i++) |
| 1173 | path_put(&stack[i]); |
| 1174 | kfree(stack); |
| 1175 | out_free_lowertmp: |
| 1176 | kfree(lowertmp); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 1177 | out_unlock_workdentry: |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 1178 | if (ufs->workdir_locked) |
| 1179 | ovl_inuse_unlock(workpath.dentry); |
Miklos Szeredi | 3b7a9a2 | 2014-12-13 00:59:48 +0100 | [diff] [blame] | 1180 | out_put_workpath: |
| 1181 | path_put(&workpath); |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 1182 | out_unlock_upperdentry: |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 1183 | if (ufs->upperdir_locked) |
| 1184 | ovl_inuse_unlock(upperpath.dentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1185 | out_put_upperpath: |
| 1186 | path_put(&upperpath); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1187 | out_free_config: |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1188 | kfree(ufs->config.lowerdir); |
| 1189 | kfree(ufs->config.upperdir); |
| 1190 | kfree(ufs->config.workdir); |
| 1191 | kfree(ufs); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1192 | out: |
| 1193 | return err; |
| 1194 | } |
| 1195 | |
| 1196 | static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags, |
| 1197 | const char *dev_name, void *raw_data) |
| 1198 | { |
| 1199 | return mount_nodev(fs_type, flags, raw_data, ovl_fill_super); |
| 1200 | } |
| 1201 | |
| 1202 | static struct file_system_type ovl_fs_type = { |
| 1203 | .owner = THIS_MODULE, |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1204 | .name = "overlay", |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1205 | .mount = ovl_mount, |
| 1206 | .kill_sb = kill_anon_super, |
| 1207 | }; |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1208 | MODULE_ALIAS_FS("overlay"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1209 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1210 | static void ovl_inode_init_once(void *foo) |
| 1211 | { |
| 1212 | struct ovl_inode *oi = foo; |
| 1213 | |
| 1214 | inode_init_once(&oi->vfs_inode); |
| 1215 | } |
| 1216 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1217 | static int __init ovl_init(void) |
| 1218 | { |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1219 | int err; |
| 1220 | |
| 1221 | ovl_inode_cachep = kmem_cache_create("ovl_inode", |
| 1222 | sizeof(struct ovl_inode), 0, |
| 1223 | (SLAB_RECLAIM_ACCOUNT| |
| 1224 | SLAB_MEM_SPREAD|SLAB_ACCOUNT), |
| 1225 | ovl_inode_init_once); |
| 1226 | if (ovl_inode_cachep == NULL) |
| 1227 | return -ENOMEM; |
| 1228 | |
| 1229 | err = register_filesystem(&ovl_fs_type); |
| 1230 | if (err) |
| 1231 | kmem_cache_destroy(ovl_inode_cachep); |
| 1232 | |
| 1233 | return err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static void __exit ovl_exit(void) |
| 1237 | { |
| 1238 | unregister_filesystem(&ovl_fs_type); |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1239 | |
| 1240 | /* |
| 1241 | * Make sure all delayed rcu free inodes are flushed before we |
| 1242 | * destroy cache. |
| 1243 | */ |
| 1244 | rcu_barrier(); |
| 1245 | kmem_cache_destroy(ovl_inode_cachep); |
| 1246 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | module_init(ovl_init); |
| 1250 | module_exit(ovl_exit); |