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> |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 20 | #include <linux/exportfs.h> |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 21 | #include "overlayfs.h" |
| 22 | |
| 23 | MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>"); |
| 24 | MODULE_DESCRIPTION("Overlay filesystem"); |
| 25 | MODULE_LICENSE("GPL"); |
| 26 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 27 | |
| 28 | struct ovl_dir_cache; |
| 29 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 30 | #define OVL_MAX_STACK 500 |
| 31 | |
Miklos Szeredi | 688ea0e | 2016-12-16 11:02:57 +0100 | [diff] [blame] | 32 | static bool ovl_redirect_dir_def = IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR); |
| 33 | module_param_named(redirect_dir, ovl_redirect_dir_def, bool, 0644); |
| 34 | MODULE_PARM_DESC(ovl_redirect_dir_def, |
| 35 | "Default to on or off for the redirect_dir feature"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 36 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 37 | static bool ovl_redirect_always_follow = |
| 38 | IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW); |
| 39 | module_param_named(redirect_always_follow, ovl_redirect_always_follow, |
| 40 | bool, 0644); |
| 41 | MODULE_PARM_DESC(ovl_redirect_always_follow, |
| 42 | "Follow redirects even if redirect_dir feature is turned off"); |
| 43 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 44 | static bool ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX); |
| 45 | module_param_named(index, ovl_index_def, bool, 0644); |
| 46 | MODULE_PARM_DESC(ovl_index_def, |
| 47 | "Default to on or off for the inodes index feature"); |
| 48 | |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 49 | static bool ovl_nfs_export_def = IS_ENABLED(CONFIG_OVERLAY_FS_NFS_EXPORT); |
| 50 | module_param_named(nfs_export, ovl_nfs_export_def, bool, 0644); |
| 51 | MODULE_PARM_DESC(ovl_nfs_export_def, |
| 52 | "Default to on or off for the NFS export feature"); |
| 53 | |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 54 | static bool ovl_xino_auto_def = IS_ENABLED(CONFIG_OVERLAY_FS_XINO_AUTO); |
| 55 | module_param_named(xino_auto, ovl_xino_auto_def, bool, 0644); |
| 56 | MODULE_PARM_DESC(ovl_xino_auto_def, |
| 57 | "Auto enable xino feature"); |
| 58 | |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 59 | static void ovl_entry_stack_free(struct ovl_entry *oe) |
| 60 | { |
| 61 | unsigned int i; |
| 62 | |
| 63 | for (i = 0; i < oe->numlower; i++) |
| 64 | dput(oe->lowerstack[i].dentry); |
| 65 | } |
| 66 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 67 | static void ovl_dentry_release(struct dentry *dentry) |
| 68 | { |
| 69 | struct ovl_entry *oe = dentry->d_fsdata; |
| 70 | |
| 71 | if (oe) { |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 72 | ovl_entry_stack_free(oe); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 73 | kfree_rcu(oe, rcu); |
| 74 | } |
| 75 | } |
| 76 | |
Miklos Szeredi | 2d90267 | 2016-06-30 08:53:27 +0200 | [diff] [blame] | 77 | static struct dentry *ovl_d_real(struct dentry *dentry, |
Miklos Szeredi | fb16043 | 2018-07-18 15:44:44 +0200 | [diff] [blame^] | 78 | const struct inode *inode) |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 79 | { |
| 80 | struct dentry *real; |
| 81 | |
Miklos Szeredi | e8c985b | 2018-07-18 15:44:41 +0200 | [diff] [blame] | 82 | /* It's an overlay file */ |
| 83 | if (inode && d_inode(dentry) == inode) |
| 84 | return dentry; |
| 85 | |
Miklos Szeredi | ca4c8a3 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 86 | if (!d_is_reg(dentry)) { |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 87 | if (!inode || inode == d_inode(dentry)) |
| 88 | return dentry; |
| 89 | goto bug; |
| 90 | } |
| 91 | |
| 92 | real = ovl_dentry_upper(dentry); |
Miklos Szeredi | fb16043 | 2018-07-18 15:44:44 +0200 | [diff] [blame^] | 93 | if (real && (!inode || inode == d_inode(real))) |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 94 | return real; |
| 95 | |
| 96 | real = ovl_dentry_lower(dentry); |
| 97 | if (!real) |
| 98 | goto bug; |
| 99 | |
Miklos Szeredi | c4fcfc1 | 2016-11-29 10:20:24 +0100 | [diff] [blame] | 100 | /* Handle recursion */ |
Miklos Szeredi | fb16043 | 2018-07-18 15:44:44 +0200 | [diff] [blame^] | 101 | real = d_real(real, inode); |
Miklos Szeredi | c4fcfc1 | 2016-11-29 10:20:24 +0100 | [diff] [blame] | 102 | |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 103 | if (!inode || inode == d_inode(real)) |
| 104 | return real; |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 105 | bug: |
Miklos Szeredi | 656189d | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 106 | 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] | 107 | inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0); |
| 108 | return dentry; |
| 109 | } |
| 110 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 111 | static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags) |
| 112 | { |
| 113 | struct ovl_entry *oe = dentry->d_fsdata; |
| 114 | unsigned int i; |
| 115 | int ret = 1; |
| 116 | |
| 117 | for (i = 0; i < oe->numlower; i++) { |
| 118 | struct dentry *d = oe->lowerstack[i].dentry; |
| 119 | |
| 120 | if (d->d_flags & DCACHE_OP_REVALIDATE) { |
| 121 | ret = d->d_op->d_revalidate(d, flags); |
| 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | if (!ret) { |
| 125 | if (!(flags & LOOKUP_RCU)) |
| 126 | d_invalidate(d); |
| 127 | return -ESTALE; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) |
| 135 | { |
| 136 | struct ovl_entry *oe = dentry->d_fsdata; |
| 137 | unsigned int i; |
| 138 | int ret = 1; |
| 139 | |
| 140 | for (i = 0; i < oe->numlower; i++) { |
| 141 | struct dentry *d = oe->lowerstack[i].dentry; |
| 142 | |
| 143 | if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) { |
| 144 | ret = d->d_op->d_weak_revalidate(d, flags); |
| 145 | if (ret <= 0) |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | return ret; |
| 150 | } |
| 151 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 152 | static const struct dentry_operations ovl_dentry_operations = { |
| 153 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 154 | .d_real = ovl_d_real, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 155 | }; |
| 156 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 157 | static const struct dentry_operations ovl_reval_dentry_operations = { |
| 158 | .d_release = ovl_dentry_release, |
Miklos Szeredi | d101a12 | 2016-03-26 16:14:37 -0400 | [diff] [blame] | 159 | .d_real = ovl_d_real, |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 160 | .d_revalidate = ovl_dentry_revalidate, |
| 161 | .d_weak_revalidate = ovl_dentry_weak_revalidate, |
| 162 | }; |
| 163 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 164 | static struct kmem_cache *ovl_inode_cachep; |
| 165 | |
| 166 | static struct inode *ovl_alloc_inode(struct super_block *sb) |
| 167 | { |
| 168 | struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL); |
| 169 | |
Hirofumi Nakagawa | b3885bd | 2017-09-26 03:09:53 +0900 | [diff] [blame] | 170 | if (!oi) |
| 171 | return NULL; |
| 172 | |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 173 | oi->cache = NULL; |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 174 | oi->redirect = NULL; |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 175 | oi->version = 0; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 176 | oi->flags = 0; |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 177 | oi->__upperdentry = NULL; |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 178 | oi->lower = NULL; |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 179 | mutex_init(&oi->lock); |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 180 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 181 | return &oi->vfs_inode; |
| 182 | } |
| 183 | |
| 184 | static void ovl_i_callback(struct rcu_head *head) |
| 185 | { |
| 186 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 187 | |
| 188 | kmem_cache_free(ovl_inode_cachep, OVL_I(inode)); |
| 189 | } |
| 190 | |
| 191 | static void ovl_destroy_inode(struct inode *inode) |
| 192 | { |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 193 | struct ovl_inode *oi = OVL_I(inode); |
| 194 | |
| 195 | dput(oi->__upperdentry); |
Amir Goldstein | 31747ed | 2018-01-14 18:35:40 +0200 | [diff] [blame] | 196 | iput(oi->lower); |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 197 | kfree(oi->redirect); |
Miklos Szeredi | 4edb83b | 2017-07-27 21:54:06 +0200 | [diff] [blame] | 198 | ovl_dir_cache_free(inode); |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 199 | mutex_destroy(&oi->lock); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 200 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 201 | call_rcu(&inode->i_rcu, ovl_i_callback); |
| 202 | } |
| 203 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 204 | static void ovl_free_fs(struct ovl_fs *ofs) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 205 | { |
Miklos Szeredi | dd66266 | 2014-12-13 00:59:43 +0100 | [diff] [blame] | 206 | unsigned i; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 207 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 208 | dput(ofs->indexdir); |
| 209 | dput(ofs->workdir); |
| 210 | if (ofs->workdir_locked) |
| 211 | ovl_inuse_unlock(ofs->workbasedir); |
| 212 | dput(ofs->workbasedir); |
| 213 | if (ofs->upperdir_locked) |
| 214 | ovl_inuse_unlock(ofs->upper_mnt->mnt_root); |
| 215 | mntput(ofs->upper_mnt); |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 216 | for (i = 0; i < ofs->numlower; i++) |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 217 | mntput(ofs->lower_layers[i].mnt); |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 218 | for (i = 0; i < ofs->numlowerfs; i++) |
| 219 | free_anon_bdev(ofs->lower_fs[i].pseudo_dev); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 220 | kfree(ofs->lower_layers); |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 221 | kfree(ofs->lower_fs); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 222 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 223 | kfree(ofs->config.lowerdir); |
| 224 | kfree(ofs->config.upperdir); |
| 225 | kfree(ofs->config.workdir); |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 226 | kfree(ofs->config.redirect_mode); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 227 | if (ofs->creator_cred) |
| 228 | put_cred(ofs->creator_cred); |
| 229 | kfree(ofs); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 232 | static void ovl_put_super(struct super_block *sb) |
| 233 | { |
| 234 | struct ovl_fs *ofs = sb->s_fs_info; |
| 235 | |
| 236 | ovl_free_fs(ofs); |
| 237 | } |
| 238 | |
Chengguang Xu | e8d4bfe | 2017-11-29 10:01:32 +0800 | [diff] [blame] | 239 | /* Sync real dirty inodes in upper filesystem (if it exists) */ |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 240 | static int ovl_sync_fs(struct super_block *sb, int wait) |
| 241 | { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 242 | struct ovl_fs *ofs = sb->s_fs_info; |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 243 | struct super_block *upper_sb; |
| 244 | int ret; |
| 245 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 246 | if (!ofs->upper_mnt) |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 247 | return 0; |
Chengguang Xu | e8d4bfe | 2017-11-29 10:01:32 +0800 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * If this is a sync(2) call or an emergency sync, all the super blocks |
| 251 | * will be iterated, including upper_sb, so no need to do anything. |
| 252 | * |
| 253 | * If this is a syncfs(2) call, then we do need to call |
| 254 | * sync_filesystem() on upper_sb, but enough if we do it when being |
| 255 | * called with wait == 1. |
| 256 | */ |
| 257 | if (!wait) |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 258 | return 0; |
| 259 | |
Chengguang Xu | e8d4bfe | 2017-11-29 10:01:32 +0800 | [diff] [blame] | 260 | upper_sb = ofs->upper_mnt->mnt_sb; |
| 261 | |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 262 | down_read(&upper_sb->s_umount); |
Chengguang Xu | e8d4bfe | 2017-11-29 10:01:32 +0800 | [diff] [blame] | 263 | ret = sync_filesystem(upper_sb); |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 264 | up_read(&upper_sb->s_umount); |
Chengguang Xu | e8d4bfe | 2017-11-29 10:01:32 +0800 | [diff] [blame] | 265 | |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 269 | /** |
| 270 | * ovl_statfs |
| 271 | * @sb: The overlayfs super block |
| 272 | * @buf: The struct kstatfs to fill in with stats |
| 273 | * |
| 274 | * Get the filesystem statistics. As writes always target the upper layer |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 275 | * filesystem pass the statfs to the upper filesystem (if it exists) |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 276 | */ |
| 277 | static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 278 | { |
| 279 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; |
| 280 | struct dentry *root_dentry = dentry->d_sb->s_root; |
| 281 | struct path path; |
| 282 | int err; |
| 283 | |
Miklos Szeredi | 4ebc581 | 2014-12-13 00:59:46 +0100 | [diff] [blame] | 284 | ovl_path_real(root_dentry, &path); |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 285 | |
| 286 | err = vfs_statfs(&path, buf); |
| 287 | if (!err) { |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 288 | buf->f_namelen = ofs->namelen; |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 289 | buf->f_type = OVERLAYFS_SUPER_MAGIC; |
| 290 | } |
| 291 | |
| 292 | return err; |
| 293 | } |
| 294 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 295 | /* Will this overlay be forced to mount/remount ro? */ |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 296 | static bool ovl_force_readonly(struct ovl_fs *ofs) |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 297 | { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 298 | return (!ofs->upper_mnt || !ofs->workdir); |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 299 | } |
| 300 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 301 | static const char *ovl_redirect_mode_def(void) |
| 302 | { |
| 303 | return ovl_redirect_dir_def ? "on" : "off"; |
| 304 | } |
| 305 | |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 306 | enum { |
| 307 | OVL_XINO_OFF, |
| 308 | OVL_XINO_AUTO, |
| 309 | OVL_XINO_ON, |
| 310 | }; |
| 311 | |
| 312 | static const char * const ovl_xino_str[] = { |
| 313 | "off", |
| 314 | "auto", |
| 315 | "on", |
| 316 | }; |
| 317 | |
| 318 | static inline int ovl_xino_def(void) |
| 319 | { |
| 320 | return ovl_xino_auto_def ? OVL_XINO_AUTO : OVL_XINO_OFF; |
| 321 | } |
| 322 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 323 | /** |
| 324 | * ovl_show_options |
| 325 | * |
| 326 | * Prints the mount options for a given superblock. |
| 327 | * Returns zero; does not fail. |
| 328 | */ |
| 329 | static int ovl_show_options(struct seq_file *m, struct dentry *dentry) |
| 330 | { |
| 331 | struct super_block *sb = dentry->d_sb; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 332 | struct ovl_fs *ofs = sb->s_fs_info; |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 333 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 334 | seq_show_option(m, "lowerdir", ofs->config.lowerdir); |
| 335 | if (ofs->config.upperdir) { |
| 336 | seq_show_option(m, "upperdir", ofs->config.upperdir); |
| 337 | seq_show_option(m, "workdir", ofs->config.workdir); |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 338 | } |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 339 | if (ofs->config.default_permissions) |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 340 | seq_puts(m, ",default_permissions"); |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 341 | if (strcmp(ofs->config.redirect_mode, ovl_redirect_mode_def()) != 0) |
| 342 | seq_printf(m, ",redirect_dir=%s", ofs->config.redirect_mode); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 343 | if (ofs->config.index != ovl_index_def) |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 344 | seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off"); |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 345 | if (ofs->config.nfs_export != ovl_nfs_export_def) |
| 346 | seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ? |
| 347 | "on" : "off"); |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 348 | if (ofs->config.xino != ovl_xino_def()) |
| 349 | seq_printf(m, ",xino=%s", ovl_xino_str[ofs->config.xino]); |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 353 | static int ovl_remount(struct super_block *sb, int *flags, char *data) |
| 354 | { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 355 | struct ovl_fs *ofs = sb->s_fs_info; |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 356 | |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 357 | if (!(*flags & SB_RDONLY) && ovl_force_readonly(ofs)) |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 358 | return -EROFS; |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 363 | static const struct super_operations ovl_super_operations = { |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 364 | .alloc_inode = ovl_alloc_inode, |
| 365 | .destroy_inode = ovl_destroy_inode, |
| 366 | .drop_inode = generic_delete_inode, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 367 | .put_super = ovl_put_super, |
Amir Goldstein | e593b2b | 2017-01-23 14:32:21 +0200 | [diff] [blame] | 368 | .sync_fs = ovl_sync_fs, |
Andy Whitcroft | cc25963 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 369 | .statfs = ovl_statfs, |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 370 | .show_options = ovl_show_options, |
Seunghun Lee | 3cdf6fe | 2015-01-03 02:26:49 +0900 | [diff] [blame] | 371 | .remount_fs = ovl_remount, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | enum { |
| 375 | OPT_LOWERDIR, |
| 376 | OPT_UPPERDIR, |
| 377 | OPT_WORKDIR, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 378 | OPT_DEFAULT_PERMISSIONS, |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 379 | OPT_REDIRECT_DIR, |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 380 | OPT_INDEX_ON, |
| 381 | OPT_INDEX_OFF, |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 382 | OPT_NFS_EXPORT_ON, |
| 383 | OPT_NFS_EXPORT_OFF, |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 384 | OPT_XINO_ON, |
| 385 | OPT_XINO_OFF, |
| 386 | OPT_XINO_AUTO, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 387 | OPT_ERR, |
| 388 | }; |
| 389 | |
| 390 | static const match_table_t ovl_tokens = { |
| 391 | {OPT_LOWERDIR, "lowerdir=%s"}, |
| 392 | {OPT_UPPERDIR, "upperdir=%s"}, |
| 393 | {OPT_WORKDIR, "workdir=%s"}, |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 394 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 395 | {OPT_REDIRECT_DIR, "redirect_dir=%s"}, |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 396 | {OPT_INDEX_ON, "index=on"}, |
| 397 | {OPT_INDEX_OFF, "index=off"}, |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 398 | {OPT_NFS_EXPORT_ON, "nfs_export=on"}, |
| 399 | {OPT_NFS_EXPORT_OFF, "nfs_export=off"}, |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 400 | {OPT_XINO_ON, "xino=on"}, |
| 401 | {OPT_XINO_OFF, "xino=off"}, |
| 402 | {OPT_XINO_AUTO, "xino=auto"}, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 403 | {OPT_ERR, NULL} |
| 404 | }; |
| 405 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 406 | static char *ovl_next_opt(char **s) |
| 407 | { |
| 408 | char *sbegin = *s; |
| 409 | char *p; |
| 410 | |
| 411 | if (sbegin == NULL) |
| 412 | return NULL; |
| 413 | |
| 414 | for (p = sbegin; *p; p++) { |
| 415 | if (*p == '\\') { |
| 416 | p++; |
| 417 | if (!*p) |
| 418 | break; |
| 419 | } else if (*p == ',') { |
| 420 | *p = '\0'; |
| 421 | *s = p + 1; |
| 422 | return sbegin; |
| 423 | } |
| 424 | } |
| 425 | *s = NULL; |
| 426 | return sbegin; |
| 427 | } |
| 428 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 429 | static int ovl_parse_redirect_mode(struct ovl_config *config, const char *mode) |
| 430 | { |
| 431 | if (strcmp(mode, "on") == 0) { |
| 432 | config->redirect_dir = true; |
| 433 | /* |
| 434 | * Does not make sense to have redirect creation without |
| 435 | * redirect following. |
| 436 | */ |
| 437 | config->redirect_follow = true; |
| 438 | } else if (strcmp(mode, "follow") == 0) { |
| 439 | config->redirect_follow = true; |
| 440 | } else if (strcmp(mode, "off") == 0) { |
| 441 | if (ovl_redirect_always_follow) |
| 442 | config->redirect_follow = true; |
| 443 | } else if (strcmp(mode, "nofollow") != 0) { |
| 444 | pr_err("overlayfs: bad mount option \"redirect_dir=%s\"\n", |
| 445 | mode); |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 452 | static int ovl_parse_opt(char *opt, struct ovl_config *config) |
| 453 | { |
| 454 | char *p; |
| 455 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 456 | config->redirect_mode = kstrdup(ovl_redirect_mode_def(), GFP_KERNEL); |
| 457 | if (!config->redirect_mode) |
| 458 | return -ENOMEM; |
| 459 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 460 | while ((p = ovl_next_opt(&opt)) != NULL) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 461 | int token; |
| 462 | substring_t args[MAX_OPT_ARGS]; |
| 463 | |
| 464 | if (!*p) |
| 465 | continue; |
| 466 | |
| 467 | token = match_token(p, ovl_tokens, args); |
| 468 | switch (token) { |
| 469 | case OPT_UPPERDIR: |
| 470 | kfree(config->upperdir); |
| 471 | config->upperdir = match_strdup(&args[0]); |
| 472 | if (!config->upperdir) |
| 473 | return -ENOMEM; |
| 474 | break; |
| 475 | |
| 476 | case OPT_LOWERDIR: |
| 477 | kfree(config->lowerdir); |
| 478 | config->lowerdir = match_strdup(&args[0]); |
| 479 | if (!config->lowerdir) |
| 480 | return -ENOMEM; |
| 481 | break; |
| 482 | |
| 483 | case OPT_WORKDIR: |
| 484 | kfree(config->workdir); |
| 485 | config->workdir = match_strdup(&args[0]); |
| 486 | if (!config->workdir) |
| 487 | return -ENOMEM; |
| 488 | break; |
| 489 | |
Miklos Szeredi | 8d3095f | 2015-10-12 17:11:44 +0200 | [diff] [blame] | 490 | case OPT_DEFAULT_PERMISSIONS: |
| 491 | config->default_permissions = true; |
| 492 | break; |
| 493 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 494 | case OPT_REDIRECT_DIR: |
| 495 | kfree(config->redirect_mode); |
| 496 | config->redirect_mode = match_strdup(&args[0]); |
| 497 | if (!config->redirect_mode) |
| 498 | return -ENOMEM; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 499 | break; |
| 500 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 501 | case OPT_INDEX_ON: |
| 502 | config->index = true; |
| 503 | break; |
| 504 | |
| 505 | case OPT_INDEX_OFF: |
| 506 | config->index = false; |
| 507 | break; |
| 508 | |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 509 | case OPT_NFS_EXPORT_ON: |
| 510 | config->nfs_export = true; |
| 511 | break; |
| 512 | |
| 513 | case OPT_NFS_EXPORT_OFF: |
| 514 | config->nfs_export = false; |
| 515 | break; |
| 516 | |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 517 | case OPT_XINO_ON: |
| 518 | config->xino = OVL_XINO_ON; |
| 519 | break; |
| 520 | |
| 521 | case OPT_XINO_OFF: |
| 522 | config->xino = OVL_XINO_OFF; |
| 523 | break; |
| 524 | |
| 525 | case OPT_XINO_AUTO: |
| 526 | config->xino = OVL_XINO_AUTO; |
| 527 | break; |
| 528 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 529 | default: |
hujianyang | bead55e | 2015-01-15 13:17:36 +0800 | [diff] [blame] | 530 | pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 531 | return -EINVAL; |
| 532 | } |
| 533 | } |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 534 | |
| 535 | /* Workdir is useless in non-upper mount */ |
| 536 | if (!config->upperdir && config->workdir) { |
| 537 | pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n", |
| 538 | config->workdir); |
| 539 | kfree(config->workdir); |
| 540 | config->workdir = NULL; |
| 541 | } |
| 542 | |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 543 | return ovl_parse_redirect_mode(config, config->redirect_mode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | #define OVL_WORKDIR_NAME "work" |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 547 | #define OVL_INDEXDIR_NAME "index" |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 548 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 549 | static struct dentry *ovl_workdir_create(struct ovl_fs *ofs, |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 550 | const char *name, bool persist) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 551 | { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 552 | struct inode *dir = ofs->workbasedir->d_inode; |
| 553 | struct vfsmount *mnt = ofs->upper_mnt; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 554 | struct dentry *work; |
| 555 | int err; |
| 556 | bool retried = false; |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 557 | bool locked = false; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 558 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 559 | inode_lock_nested(dir, I_MUTEX_PARENT); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 560 | locked = true; |
| 561 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 562 | retry: |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 563 | work = lookup_one_len(name, ofs->workbasedir, strlen(name)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 564 | |
| 565 | if (!IS_ERR(work)) { |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 566 | struct iattr attr = { |
| 567 | .ia_valid = ATTR_MODE, |
Al Viro | 32a3d84 | 2016-12-04 17:33:17 +0000 | [diff] [blame] | 568 | .ia_mode = S_IFDIR | 0, |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 569 | }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 570 | |
| 571 | if (work->d_inode) { |
| 572 | err = -EEXIST; |
| 573 | if (retried) |
| 574 | goto out_dput; |
| 575 | |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 576 | if (persist) |
| 577 | goto out_unlock; |
| 578 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 579 | retried = true; |
Miklos Szeredi | eea2fb4 | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 580 | ovl_workdir_cleanup(dir, mnt, work, 0); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 581 | dput(work); |
| 582 | goto retry; |
| 583 | } |
| 584 | |
Miklos Szeredi | 95a1c81 | 2018-05-16 17:51:25 +0300 | [diff] [blame] | 585 | work = ovl_create_real(dir, work, OVL_CATTR(attr.ia_mode)); |
| 586 | err = PTR_ERR(work); |
| 587 | if (IS_ERR(work)) |
| 588 | goto out_err; |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 589 | |
Miklos Szeredi | cb348ed | 2016-10-04 14:40:44 +0200 | [diff] [blame] | 590 | /* |
| 591 | * Try to remove POSIX ACL xattrs from workdir. We are good if: |
| 592 | * |
| 593 | * a) success (there was a POSIX ACL xattr and was removed) |
| 594 | * b) -ENODATA (there was no POSIX ACL xattr) |
| 595 | * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported) |
| 596 | * |
| 597 | * There are various other error values that could effectively |
| 598 | * mean that the xattr doesn't exist (e.g. -ERANGE is returned |
| 599 | * if the xattr name is too long), but the set of filesystems |
| 600 | * allowed as upper are limited to "normal" ones, where checking |
| 601 | * for the above two errors is sufficient. |
| 602 | */ |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 603 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 604 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 605 | goto out_dput; |
| 606 | |
| 607 | err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS); |
Miklos Szeredi | e1ff3dd | 2016-09-05 13:55:20 +0200 | [diff] [blame] | 608 | if (err && err != -ENODATA && err != -EOPNOTSUPP) |
Miklos Szeredi | c11b9fd | 2016-09-01 11:11:59 +0200 | [diff] [blame] | 609 | goto out_dput; |
| 610 | |
| 611 | /* Clear any inherited mode bits */ |
| 612 | inode_lock(work->d_inode); |
| 613 | err = notify_change(work, &attr, NULL); |
| 614 | inode_unlock(work->d_inode); |
| 615 | if (err) |
| 616 | goto out_dput; |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 617 | } else { |
| 618 | err = PTR_ERR(work); |
| 619 | goto out_err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 620 | } |
| 621 | out_unlock: |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 622 | if (locked) |
| 623 | inode_unlock(dir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 624 | |
| 625 | return work; |
| 626 | |
| 627 | out_dput: |
| 628 | dput(work); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 629 | out_err: |
| 630 | pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n", |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 631 | ofs->config.workdir, name, -err); |
Amir Goldstein | 6b8aa12 | 2017-06-21 15:28:35 +0300 | [diff] [blame] | 632 | work = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 633 | goto out_unlock; |
| 634 | } |
| 635 | |
Miklos Szeredi | 91c7794 | 2014-11-20 16:40:00 +0100 | [diff] [blame] | 636 | static void ovl_unescape(char *s) |
| 637 | { |
| 638 | char *d = s; |
| 639 | |
| 640 | for (;; s++, d++) { |
| 641 | if (*s == '\\') |
| 642 | s++; |
| 643 | *d = *s; |
| 644 | if (!*s) |
| 645 | break; |
| 646 | } |
| 647 | } |
| 648 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 649 | static int ovl_mount_dir_noesc(const char *name, struct path *path) |
| 650 | { |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 651 | int err = -EINVAL; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 652 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 653 | if (!*name) { |
| 654 | pr_err("overlayfs: empty lowerdir\n"); |
| 655 | goto out; |
| 656 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 657 | err = kern_path(name, LOOKUP_FOLLOW, path); |
| 658 | if (err) { |
| 659 | pr_err("overlayfs: failed to resolve '%s': %i\n", name, err); |
| 660 | goto out; |
| 661 | } |
| 662 | err = -EINVAL; |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 663 | if (ovl_dentry_weird(path->dentry)) { |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 664 | pr_err("overlayfs: filesystem on '%s' not supported\n", name); |
| 665 | goto out_put; |
| 666 | } |
Miklos Szeredi | 2b8c30e | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 667 | if (!d_is_dir(path->dentry)) { |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 668 | pr_err("overlayfs: '%s' not a directory\n", name); |
| 669 | goto out_put; |
| 670 | } |
| 671 | return 0; |
| 672 | |
| 673 | out_put: |
Miklos Szeredi | 8aafcb5 | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 674 | path_put_init(path); |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 675 | out: |
| 676 | return err; |
| 677 | } |
| 678 | |
| 679 | static int ovl_mount_dir(const char *name, struct path *path) |
| 680 | { |
| 681 | int err = -ENOMEM; |
| 682 | char *tmp = kstrdup(name, GFP_KERNEL); |
| 683 | |
| 684 | if (tmp) { |
| 685 | ovl_unescape(tmp); |
| 686 | err = ovl_mount_dir_noesc(tmp, path); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 687 | |
| 688 | if (!err) |
| 689 | if (ovl_dentry_remote(path->dentry)) { |
| 690 | pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n", |
| 691 | tmp); |
Miklos Szeredi | 8aafcb5 | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 692 | path_put_init(path); |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 693 | err = -EINVAL; |
| 694 | } |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 695 | kfree(tmp); |
| 696 | } |
| 697 | return err; |
| 698 | } |
| 699 | |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 700 | static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs, |
| 701 | const char *name) |
| 702 | { |
| 703 | struct kstatfs statfs; |
| 704 | int err = vfs_statfs(path, &statfs); |
| 705 | |
| 706 | if (err) |
| 707 | pr_err("overlayfs: statfs failed on '%s'\n", name); |
| 708 | else |
| 709 | ofs->namelen = max(ofs->namelen, statfs.f_namelen); |
| 710 | |
| 711 | return err; |
| 712 | } |
| 713 | |
| 714 | static int ovl_lower_dir(const char *name, struct path *path, |
| 715 | struct ovl_fs *ofs, int *stack_depth, bool *remote) |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 716 | { |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 717 | int fh_type; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 718 | int err; |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 719 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 720 | err = ovl_mount_dir_noesc(name, path); |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 721 | if (err) |
| 722 | goto out; |
| 723 | |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 724 | err = ovl_check_namelen(path, ofs, name); |
| 725 | if (err) |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 726 | goto out_put; |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 727 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 728 | *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth); |
| 729 | |
Miklos Szeredi | 7c03b5d | 2015-06-22 13:53:48 +0200 | [diff] [blame] | 730 | if (ovl_dentry_remote(path->dentry)) |
| 731 | *remote = true; |
| 732 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 733 | /* |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 734 | * The inodes index feature and NFS export need to encode and decode |
| 735 | * file handles, so they require that all layers support them. |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 736 | */ |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 737 | fh_type = ovl_can_decode_fh(path->dentry->d_sb); |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 738 | if ((ofs->config.nfs_export || |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 739 | (ofs->config.index && ofs->config.upperdir)) && !fh_type) { |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 740 | ofs->config.index = false; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 741 | ofs->config.nfs_export = false; |
| 742 | pr_warn("overlayfs: fs on '%s' does not support file handles, falling back to index=off,nfs_export=off.\n", |
| 743 | name); |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 744 | } |
| 745 | |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 746 | /* Check if lower fs has 32bit inode numbers */ |
| 747 | if (fh_type != FILEID_INO32_GEN) |
| 748 | ofs->xino_bits = 0; |
| 749 | |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 750 | return 0; |
| 751 | |
| 752 | out_put: |
Miklos Szeredi | 8aafcb5 | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 753 | path_put_init(path); |
Miklos Szeredi | ab50882 | 2014-12-13 00:59:49 +0100 | [diff] [blame] | 754 | out: |
| 755 | return err; |
| 756 | } |
| 757 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 758 | /* Workdir should not be subdir of upperdir and vice versa */ |
| 759 | static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir) |
| 760 | { |
| 761 | bool ok = false; |
| 762 | |
| 763 | if (workdir != upperdir) { |
| 764 | ok = (lock_rename(workdir, upperdir) == NULL); |
| 765 | unlock_rename(workdir, upperdir); |
| 766 | } |
| 767 | return ok; |
| 768 | } |
| 769 | |
Miklos Szeredi | a78d9f0 | 2014-12-13 00:59:52 +0100 | [diff] [blame] | 770 | static unsigned int ovl_split_lowerdirs(char *str) |
| 771 | { |
| 772 | unsigned int ctr = 1; |
| 773 | char *s, *d; |
| 774 | |
| 775 | for (s = d = str;; s++, d++) { |
| 776 | if (*s == '\\') { |
| 777 | s++; |
| 778 | } else if (*s == ':') { |
| 779 | *d = '\0'; |
| 780 | ctr++; |
| 781 | continue; |
| 782 | } |
| 783 | *d = *s; |
| 784 | if (!*s) |
| 785 | break; |
| 786 | } |
| 787 | return ctr; |
| 788 | } |
| 789 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 790 | static int __maybe_unused |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 791 | ovl_posix_acl_xattr_get(const struct xattr_handler *handler, |
| 792 | struct dentry *dentry, struct inode *inode, |
| 793 | const char *name, void *buffer, size_t size) |
| 794 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 795 | return ovl_xattr_get(dentry, inode, handler->name, buffer, size); |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static int __maybe_unused |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 799 | ovl_posix_acl_xattr_set(const struct xattr_handler *handler, |
| 800 | struct dentry *dentry, struct inode *inode, |
| 801 | const char *name, const void *value, |
| 802 | size_t size, int flags) |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 803 | { |
| 804 | struct dentry *workdir = ovl_workdir(dentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 805 | struct inode *realinode = ovl_inode_real(inode); |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 806 | struct posix_acl *acl = NULL; |
| 807 | int err; |
| 808 | |
| 809 | /* Check that everything is OK before copy-up */ |
| 810 | if (value) { |
| 811 | acl = posix_acl_from_xattr(&init_user_ns, value, size); |
| 812 | if (IS_ERR(acl)) |
| 813 | return PTR_ERR(acl); |
| 814 | } |
| 815 | err = -EOPNOTSUPP; |
| 816 | if (!IS_POSIXACL(d_inode(workdir))) |
| 817 | goto out_acl_release; |
| 818 | if (!realinode->i_op->set_acl) |
| 819 | goto out_acl_release; |
| 820 | if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) { |
| 821 | err = acl ? -EACCES : 0; |
| 822 | goto out_acl_release; |
| 823 | } |
| 824 | err = -EPERM; |
| 825 | if (!inode_owner_or_capable(inode)) |
| 826 | goto out_acl_release; |
| 827 | |
| 828 | posix_acl_release(acl); |
| 829 | |
Miklos Szeredi | fd3220d | 2016-10-31 14:42:14 +0100 | [diff] [blame] | 830 | /* |
| 831 | * Check if sgid bit needs to be cleared (actual setacl operation will |
| 832 | * be done with mounter's capabilities and so that won't do it for us). |
| 833 | */ |
| 834 | if (unlikely(inode->i_mode & S_ISGID) && |
| 835 | handler->flags == ACL_TYPE_ACCESS && |
| 836 | !in_group_p(inode->i_gid) && |
| 837 | !capable_wrt_inode_uidgid(inode, CAP_FSETID)) { |
| 838 | struct iattr iattr = { .ia_valid = ATTR_KILL_SGID }; |
| 839 | |
| 840 | err = ovl_setattr(dentry, &iattr); |
| 841 | if (err) |
| 842 | return err; |
| 843 | } |
| 844 | |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 845 | err = ovl_xattr_set(dentry, inode, handler->name, value, size, flags); |
Miklos Szeredi | ce31513 | 2016-09-01 11:12:00 +0200 | [diff] [blame] | 846 | if (!err) |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 847 | ovl_copyattr(ovl_inode_real(inode), inode); |
Miklos Szeredi | ce31513 | 2016-09-01 11:12:00 +0200 | [diff] [blame] | 848 | |
| 849 | return err; |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 850 | |
| 851 | out_acl_release: |
| 852 | posix_acl_release(acl); |
| 853 | return err; |
| 854 | } |
| 855 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 856 | static int ovl_own_xattr_get(const struct xattr_handler *handler, |
| 857 | struct dentry *dentry, struct inode *inode, |
| 858 | const char *name, void *buffer, size_t size) |
| 859 | { |
Amir Goldstein | 48fab5d | 2016-11-16 11:22:39 +0200 | [diff] [blame] | 860 | return -EOPNOTSUPP; |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 861 | } |
| 862 | |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 863 | static int ovl_own_xattr_set(const struct xattr_handler *handler, |
| 864 | struct dentry *dentry, struct inode *inode, |
| 865 | const char *name, const void *value, |
| 866 | size_t size, int flags) |
| 867 | { |
Amir Goldstein | 48fab5d | 2016-11-16 11:22:39 +0200 | [diff] [blame] | 868 | return -EOPNOTSUPP; |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 869 | } |
| 870 | |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 871 | static int ovl_other_xattr_get(const struct xattr_handler *handler, |
| 872 | struct dentry *dentry, struct inode *inode, |
| 873 | const char *name, void *buffer, size_t size) |
| 874 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 875 | return ovl_xattr_get(dentry, inode, name, buffer, size); |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Andreas Gruenbacher | 0e585cc | 2016-08-22 17:22:11 +0200 | [diff] [blame] | 878 | static int ovl_other_xattr_set(const struct xattr_handler *handler, |
| 879 | struct dentry *dentry, struct inode *inode, |
| 880 | const char *name, const void *value, |
| 881 | size_t size, int flags) |
| 882 | { |
Miklos Szeredi | 1d88f18 | 2017-07-20 11:08:21 +0200 | [diff] [blame] | 883 | return ovl_xattr_set(dentry, inode, name, value, size, flags); |
Andreas Gruenbacher | 0e585cc | 2016-08-22 17:22:11 +0200 | [diff] [blame] | 884 | } |
| 885 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 886 | static const struct xattr_handler __maybe_unused |
| 887 | ovl_posix_acl_access_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 888 | .name = XATTR_NAME_POSIX_ACL_ACCESS, |
| 889 | .flags = ACL_TYPE_ACCESS, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 890 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 891 | .set = ovl_posix_acl_xattr_set, |
| 892 | }; |
| 893 | |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 894 | static const struct xattr_handler __maybe_unused |
| 895 | ovl_posix_acl_default_xattr_handler = { |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 896 | .name = XATTR_NAME_POSIX_ACL_DEFAULT, |
| 897 | .flags = ACL_TYPE_DEFAULT, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 898 | .get = ovl_posix_acl_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 899 | .set = ovl_posix_acl_xattr_set, |
| 900 | }; |
| 901 | |
| 902 | static const struct xattr_handler ovl_own_xattr_handler = { |
| 903 | .prefix = OVL_XATTR_PREFIX, |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 904 | .get = ovl_own_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 905 | .set = ovl_own_xattr_set, |
| 906 | }; |
| 907 | |
| 908 | static const struct xattr_handler ovl_other_xattr_handler = { |
| 909 | .prefix = "", /* catch all */ |
Andreas Gruenbacher | 0eb45fc | 2016-08-22 17:52:55 +0200 | [diff] [blame] | 910 | .get = ovl_other_xattr_get, |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 911 | .set = ovl_other_xattr_set, |
| 912 | }; |
| 913 | |
| 914 | static const struct xattr_handler *ovl_xattr_handlers[] = { |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 915 | #ifdef CONFIG_FS_POSIX_ACL |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 916 | &ovl_posix_acl_access_xattr_handler, |
| 917 | &ovl_posix_acl_default_xattr_handler, |
Andreas Gruenbacher | 0c97be2 | 2016-08-22 16:36:49 +0200 | [diff] [blame] | 918 | #endif |
Miklos Szeredi | d837a49 | 2016-07-29 12:05:24 +0200 | [diff] [blame] | 919 | &ovl_own_xattr_handler, |
| 920 | &ovl_other_xattr_handler, |
| 921 | NULL |
| 922 | }; |
| 923 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 924 | static int ovl_get_upper(struct ovl_fs *ofs, struct path *upperpath) |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 925 | { |
Miklos Szeredi | 5064975 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 926 | struct vfsmount *upper_mnt; |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 927 | int err; |
| 928 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 929 | err = ovl_mount_dir(ofs->config.upperdir, upperpath); |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 930 | if (err) |
| 931 | goto out; |
| 932 | |
| 933 | /* Upper fs should not be r/o */ |
| 934 | if (sb_rdonly(upperpath->mnt->mnt_sb)) { |
| 935 | pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n"); |
| 936 | err = -EINVAL; |
| 937 | goto out; |
| 938 | } |
| 939 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 940 | err = ovl_check_namelen(upperpath, ofs, ofs->config.upperdir); |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 941 | if (err) |
| 942 | goto out; |
| 943 | |
| 944 | err = -EBUSY; |
| 945 | if (ovl_inuse_trylock(upperpath->dentry)) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 946 | ofs->upperdir_locked = true; |
| 947 | } else if (ofs->config.index) { |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 948 | pr_err("overlayfs: upperdir is in-use by another mount, mount with '-o index=off' to override exclusive upperdir protection.\n"); |
| 949 | goto out; |
| 950 | } else { |
| 951 | pr_warn("overlayfs: upperdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); |
| 952 | } |
Miklos Szeredi | 5064975 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 953 | |
| 954 | upper_mnt = clone_private_mount(upperpath); |
| 955 | err = PTR_ERR(upper_mnt); |
| 956 | if (IS_ERR(upper_mnt)) { |
| 957 | pr_err("overlayfs: failed to clone upperpath\n"); |
| 958 | goto out; |
| 959 | } |
| 960 | |
| 961 | /* Don't inherit atime flags */ |
| 962 | upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 963 | ofs->upper_mnt = upper_mnt; |
Miklos Szeredi | 6ee8acf | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 964 | err = 0; |
| 965 | out: |
| 966 | return err; |
| 967 | } |
| 968 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 969 | static int ovl_make_workdir(struct ovl_fs *ofs, struct path *workpath) |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 970 | { |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 971 | struct vfsmount *mnt = ofs->upper_mnt; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 972 | struct dentry *temp; |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 973 | int fh_type; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 974 | int err; |
| 975 | |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 976 | err = mnt_want_write(mnt); |
| 977 | if (err) |
| 978 | return err; |
| 979 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 980 | ofs->workdir = ovl_workdir_create(ofs, OVL_WORKDIR_NAME, false); |
| 981 | if (!ofs->workdir) |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 982 | goto out; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 983 | |
| 984 | /* |
| 985 | * Upper should support d_type, else whiteouts are visible. Given |
| 986 | * workdir and upper are on same fs, we can do iterate_dir() on |
| 987 | * workdir. This check requires successful creation of workdir in |
| 988 | * previous step. |
| 989 | */ |
| 990 | err = ovl_check_d_type_supported(workpath); |
| 991 | if (err < 0) |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 992 | goto out; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * We allowed this configuration and don't want to break users over |
| 996 | * kernel upgrade. So warn instead of erroring out. |
| 997 | */ |
| 998 | if (!err) |
| 999 | pr_warn("overlayfs: upper fs needs to support d_type.\n"); |
| 1000 | |
| 1001 | /* Check if upper/work fs supports O_TMPFILE */ |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1002 | temp = ovl_do_tmpfile(ofs->workdir, S_IFREG | 0); |
| 1003 | ofs->tmpfile = !IS_ERR(temp); |
| 1004 | if (ofs->tmpfile) |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1005 | dput(temp); |
| 1006 | else |
| 1007 | pr_warn("overlayfs: upper fs does not support tmpfile.\n"); |
| 1008 | |
| 1009 | /* |
| 1010 | * Check if upper/work fs supports trusted.overlay.* xattr |
| 1011 | */ |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1012 | err = ovl_do_setxattr(ofs->workdir, OVL_XATTR_OPAQUE, "0", 1, 0); |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1013 | if (err) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1014 | ofs->noxattr = true; |
Amir Goldstein | a683737 | 2017-09-19 12:14:18 +0300 | [diff] [blame] | 1015 | ofs->config.index = false; |
| 1016 | pr_warn("overlayfs: upper fs does not support xattr, falling back to index=off.\n"); |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 1017 | err = 0; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1018 | } else { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1019 | vfs_removexattr(ofs->workdir, OVL_XATTR_OPAQUE); |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /* Check if upper/work fs supports file handles */ |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1023 | fh_type = ovl_can_decode_fh(ofs->workdir->d_sb); |
| 1024 | if (ofs->config.index && !fh_type) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1025 | ofs->config.index = false; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1026 | pr_warn("overlayfs: upper fs does not support file handles, falling back to index=off.\n"); |
| 1027 | } |
| 1028 | |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1029 | /* Check if upper fs has 32bit inode numbers */ |
| 1030 | if (fh_type != FILEID_INO32_GEN) |
| 1031 | ofs->xino_bits = 0; |
| 1032 | |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 1033 | /* NFS export of r/w mount depends on index */ |
| 1034 | if (ofs->config.nfs_export && !ofs->config.index) { |
| 1035 | pr_warn("overlayfs: NFS export requires \"index=on\", falling back to nfs_export=off.\n"); |
| 1036 | ofs->config.nfs_export = false; |
| 1037 | } |
| 1038 | |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 1039 | out: |
| 1040 | mnt_drop_write(mnt); |
| 1041 | return err; |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1044 | static int ovl_get_workdir(struct ovl_fs *ofs, struct path *upperpath) |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1045 | { |
| 1046 | int err; |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1047 | struct path workpath = { }; |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1048 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1049 | err = ovl_mount_dir(ofs->config.workdir, &workpath); |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1050 | if (err) |
| 1051 | goto out; |
| 1052 | |
| 1053 | err = -EINVAL; |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1054 | if (upperpath->mnt != workpath.mnt) { |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1055 | pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); |
| 1056 | goto out; |
| 1057 | } |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1058 | if (!ovl_workdir_ok(workpath.dentry, upperpath->dentry)) { |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1059 | pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); |
| 1060 | goto out; |
| 1061 | } |
| 1062 | |
| 1063 | err = -EBUSY; |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1064 | if (ovl_inuse_trylock(workpath.dentry)) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1065 | ofs->workdir_locked = true; |
| 1066 | } else if (ofs->config.index) { |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1067 | pr_err("overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.\n"); |
| 1068 | goto out; |
| 1069 | } else { |
| 1070 | pr_warn("overlayfs: workdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); |
| 1071 | } |
| 1072 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1073 | ofs->workbasedir = dget(workpath.dentry); |
| 1074 | err = ovl_make_workdir(ofs, &workpath); |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1075 | if (err) |
| 1076 | goto out; |
| 1077 | |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1078 | err = 0; |
| 1079 | out: |
Miklos Szeredi | bca44b5 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1080 | path_put(&workpath); |
| 1081 | |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1082 | return err; |
| 1083 | } |
| 1084 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1085 | static int ovl_get_indexdir(struct ovl_fs *ofs, struct ovl_entry *oe, |
Miklos Szeredi | 95e6d41 | 2017-11-09 10:23:29 +0100 | [diff] [blame] | 1086 | struct path *upperpath) |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1087 | { |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 1088 | struct vfsmount *mnt = ofs->upper_mnt; |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1089 | int err; |
| 1090 | |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 1091 | err = mnt_want_write(mnt); |
| 1092 | if (err) |
| 1093 | return err; |
| 1094 | |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1095 | /* Verify lower root is upper root origin */ |
Amir Goldstein | d976807 | 2017-09-24 13:00:19 +0300 | [diff] [blame] | 1096 | err = ovl_verify_origin(upperpath->dentry, oe->lowerstack[0].dentry, |
Amir Goldstein | 0512244 | 2018-01-11 08:25:32 +0200 | [diff] [blame] | 1097 | true); |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1098 | if (err) { |
| 1099 | pr_err("overlayfs: failed to verify upper root origin\n"); |
| 1100 | goto out; |
| 1101 | } |
| 1102 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1103 | ofs->indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true); |
| 1104 | if (ofs->indexdir) { |
Amir Goldstein | ad1d615 | 2018-01-11 10:47:03 +0200 | [diff] [blame] | 1105 | /* |
| 1106 | * Verify upper root is exclusively associated with index dir. |
| 1107 | * Older kernels stored upper fh in "trusted.overlay.origin" |
| 1108 | * xattr. If that xattr exists, verify that it is a match to |
| 1109 | * upper dir file handle. In any case, verify or set xattr |
| 1110 | * "trusted.overlay.upper" to indicate that index may have |
| 1111 | * directory entries. |
| 1112 | */ |
| 1113 | if (ovl_check_origin_xattr(ofs->indexdir)) { |
| 1114 | err = ovl_verify_set_fh(ofs->indexdir, OVL_XATTR_ORIGIN, |
| 1115 | upperpath->dentry, true, false); |
| 1116 | if (err) |
| 1117 | pr_err("overlayfs: failed to verify index dir 'origin' xattr\n"); |
| 1118 | } |
| 1119 | err = ovl_verify_upper(ofs->indexdir, upperpath->dentry, true); |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1120 | if (err) |
Amir Goldstein | ad1d615 | 2018-01-11 10:47:03 +0200 | [diff] [blame] | 1121 | pr_err("overlayfs: failed to verify index dir 'upper' xattr\n"); |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1122 | |
| 1123 | /* Cleanup bad/stale/orphan index entries */ |
| 1124 | if (!err) |
Amir Goldstein | 1eff1a1 | 2017-12-12 22:40:46 +0200 | [diff] [blame] | 1125 | err = ovl_indexdir_cleanup(ofs); |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1126 | } |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1127 | if (err || !ofs->indexdir) |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1128 | pr_warn("overlayfs: try deleting index dir or mounting with '-o index=off' to disable inodes index.\n"); |
| 1129 | |
| 1130 | out: |
Amir Goldstein | 2ba9d57 | 2018-01-03 18:54:41 +0200 | [diff] [blame] | 1131 | mnt_drop_write(mnt); |
Miklos Szeredi | f7e3a7d | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1132 | return err; |
| 1133 | } |
| 1134 | |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1135 | /* Get a unique fsid for the layer */ |
| 1136 | static int ovl_get_fsid(struct ovl_fs *ofs, struct super_block *sb) |
| 1137 | { |
| 1138 | unsigned int i; |
| 1139 | dev_t dev; |
| 1140 | int err; |
| 1141 | |
| 1142 | /* fsid 0 is reserved for upper fs even with non upper overlay */ |
| 1143 | if (ofs->upper_mnt && ofs->upper_mnt->mnt_sb == sb) |
| 1144 | return 0; |
| 1145 | |
| 1146 | for (i = 0; i < ofs->numlowerfs; i++) { |
| 1147 | if (ofs->lower_fs[i].sb == sb) |
| 1148 | return i + 1; |
| 1149 | } |
| 1150 | |
| 1151 | err = get_anon_bdev(&dev); |
| 1152 | if (err) { |
| 1153 | pr_err("overlayfs: failed to get anonymous bdev for lowerpath\n"); |
| 1154 | return err; |
| 1155 | } |
| 1156 | |
| 1157 | ofs->lower_fs[ofs->numlowerfs].sb = sb; |
| 1158 | ofs->lower_fs[ofs->numlowerfs].pseudo_dev = dev; |
| 1159 | ofs->numlowerfs++; |
| 1160 | |
| 1161 | return ofs->numlowerfs; |
| 1162 | } |
| 1163 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1164 | static int ovl_get_lower_layers(struct ovl_fs *ofs, struct path *stack, |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1165 | unsigned int numlower) |
| 1166 | { |
| 1167 | int err; |
| 1168 | unsigned int i; |
| 1169 | |
| 1170 | err = -ENOMEM; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1171 | ofs->lower_layers = kcalloc(numlower, sizeof(struct ovl_layer), |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1172 | GFP_KERNEL); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1173 | if (ofs->lower_layers == NULL) |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1174 | goto out; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1175 | |
| 1176 | ofs->lower_fs = kcalloc(numlower, sizeof(struct ovl_sb), |
| 1177 | GFP_KERNEL); |
| 1178 | if (ofs->lower_fs == NULL) |
| 1179 | goto out; |
| 1180 | |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1181 | for (i = 0; i < numlower; i++) { |
| 1182 | struct vfsmount *mnt; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1183 | int fsid; |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1184 | |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1185 | err = fsid = ovl_get_fsid(ofs, stack[i].mnt->mnt_sb); |
| 1186 | if (err < 0) |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1187 | goto out; |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1188 | |
| 1189 | mnt = clone_private_mount(&stack[i]); |
| 1190 | err = PTR_ERR(mnt); |
| 1191 | if (IS_ERR(mnt)) { |
| 1192 | pr_err("overlayfs: failed to clone lowerpath\n"); |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1193 | goto out; |
| 1194 | } |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1195 | |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1196 | /* |
| 1197 | * Make lower layers R/O. That way fchmod/fchown on lower file |
| 1198 | * will fail instead of modifying lower fs. |
| 1199 | */ |
| 1200 | mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME; |
| 1201 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1202 | ofs->lower_layers[ofs->numlower].mnt = mnt; |
Amir Goldstein | d583ed7 | 2017-11-08 19:23:36 +0200 | [diff] [blame] | 1203 | ofs->lower_layers[ofs->numlower].idx = i + 1; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 1204 | ofs->lower_layers[ofs->numlower].fsid = fsid; |
| 1205 | if (fsid) { |
| 1206 | ofs->lower_layers[ofs->numlower].fs = |
| 1207 | &ofs->lower_fs[fsid - 1]; |
| 1208 | } |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1209 | ofs->numlower++; |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1210 | } |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1211 | |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 1212 | /* |
| 1213 | * When all layers on same fs, overlay can use real inode numbers. |
| 1214 | * With mount option "xino=on", mounter declares that there are enough |
| 1215 | * free high bits in underlying fs to hold the unique fsid. |
| 1216 | * If overlayfs does encounter underlying inodes using the high xino |
| 1217 | * bits reserved for fsid, it emits a warning and uses the original |
| 1218 | * inode number. |
| 1219 | */ |
| 1220 | if (!ofs->numlowerfs || (ofs->numlowerfs == 1 && !ofs->upper_mnt)) { |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1221 | ofs->xino_bits = 0; |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 1222 | ofs->config.xino = OVL_XINO_OFF; |
| 1223 | } else if (ofs->config.xino == OVL_XINO_ON && !ofs->xino_bits) { |
| 1224 | /* |
| 1225 | * This is a roundup of number of bits needed for numlowerfs+1 |
| 1226 | * (i.e. ilog2(numlowerfs+1 - 1) + 1). fsid 0 is reserved for |
| 1227 | * upper fs even with non upper overlay. |
| 1228 | */ |
| 1229 | BUILD_BUG_ON(ilog2(OVL_MAX_STACK) > 31); |
| 1230 | ofs->xino_bits = ilog2(ofs->numlowerfs) + 1; |
| 1231 | } |
| 1232 | |
| 1233 | if (ofs->xino_bits) { |
| 1234 | pr_info("overlayfs: \"xino\" feature enabled using %d upper inode bits.\n", |
| 1235 | ofs->xino_bits); |
| 1236 | } |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1237 | |
Miklos Szeredi | 520d7c8 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1238 | err = 0; |
| 1239 | out: |
| 1240 | return err; |
| 1241 | } |
| 1242 | |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1243 | static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1244 | struct ovl_fs *ofs) |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1245 | { |
| 1246 | int err; |
| 1247 | char *lowertmp, *lower; |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1248 | struct path *stack = NULL; |
| 1249 | unsigned int stacklen, numlower = 0, i; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1250 | bool remote = false; |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1251 | struct ovl_entry *oe; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1252 | |
| 1253 | err = -ENOMEM; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1254 | lowertmp = kstrdup(ofs->config.lowerdir, GFP_KERNEL); |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1255 | if (!lowertmp) |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1256 | goto out_err; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1257 | |
| 1258 | err = -EINVAL; |
| 1259 | stacklen = ovl_split_lowerdirs(lowertmp); |
| 1260 | if (stacklen > OVL_MAX_STACK) { |
| 1261 | pr_err("overlayfs: too many lower directories, limit is %d\n", |
| 1262 | OVL_MAX_STACK); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1263 | goto out_err; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1264 | } else if (!ofs->config.upperdir && stacklen == 1) { |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1265 | pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n"); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1266 | goto out_err; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 1267 | } else if (!ofs->config.upperdir && ofs->config.nfs_export && |
| 1268 | ofs->config.redirect_follow) { |
| 1269 | pr_warn("overlayfs: NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n"); |
| 1270 | ofs->config.nfs_export = false; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | err = -ENOMEM; |
| 1274 | stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL); |
| 1275 | if (!stack) |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1276 | goto out_err; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1277 | |
| 1278 | err = -EINVAL; |
| 1279 | lower = lowertmp; |
| 1280 | for (numlower = 0; numlower < stacklen; numlower++) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1281 | err = ovl_lower_dir(lower, &stack[numlower], ofs, |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1282 | &sb->s_stack_depth, &remote); |
| 1283 | if (err) |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1284 | goto out_err; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1285 | |
| 1286 | lower = strchr(lower, '\0') + 1; |
| 1287 | } |
| 1288 | |
| 1289 | err = -EINVAL; |
| 1290 | sb->s_stack_depth++; |
| 1291 | if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) { |
| 1292 | pr_err("overlayfs: maximum fs stacking depth exceeded\n"); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1293 | goto out_err; |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1294 | } |
| 1295 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1296 | err = ovl_get_lower_layers(ofs, stack, numlower); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1297 | if (err) |
| 1298 | goto out_err; |
| 1299 | |
| 1300 | err = -ENOMEM; |
| 1301 | oe = ovl_alloc_entry(numlower); |
| 1302 | if (!oe) |
| 1303 | goto out_err; |
| 1304 | |
| 1305 | for (i = 0; i < numlower; i++) { |
| 1306 | oe->lowerstack[i].dentry = dget(stack[i].dentry); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1307 | oe->lowerstack[i].layer = &ofs->lower_layers[i]; |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1308 | } |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1309 | |
| 1310 | if (remote) |
| 1311 | sb->s_d_op = &ovl_reval_dentry_operations; |
| 1312 | else |
| 1313 | sb->s_d_op = &ovl_dentry_operations; |
| 1314 | |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1315 | out: |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1316 | for (i = 0; i < numlower; i++) |
| 1317 | path_put(&stack[i]); |
| 1318 | kfree(stack); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1319 | kfree(lowertmp); |
| 1320 | |
| 1321 | return oe; |
| 1322 | |
| 1323 | out_err: |
| 1324 | oe = ERR_PTR(err); |
Miklos Szeredi | 53dbb0b | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1325 | goto out; |
| 1326 | } |
| 1327 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1328 | static int ovl_fill_super(struct super_block *sb, void *data, int silent) |
| 1329 | { |
Kees Cook | 33006cd | 2017-03-29 14:02:19 -0700 | [diff] [blame] | 1330 | struct path upperpath = { }; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1331 | struct dentry *root_dentry; |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1332 | struct ovl_entry *oe; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1333 | struct ovl_fs *ofs; |
Konstantin Khlebnikov | 51f8f3c | 2017-01-10 21:30:21 +0300 | [diff] [blame] | 1334 | struct cred *cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1335 | int err; |
| 1336 | |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1337 | err = -ENOMEM; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1338 | ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL); |
| 1339 | if (!ofs) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1340 | goto out; |
| 1341 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1342 | ofs->creator_cred = cred = prepare_creds(); |
Miklos Szeredi | c6fe625 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1343 | if (!cred) |
| 1344 | goto out_err; |
| 1345 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1346 | ofs->config.index = ovl_index_def; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 1347 | ofs->config.nfs_export = ovl_nfs_export_def; |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 1348 | ofs->config.xino = ovl_xino_def(); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1349 | err = ovl_parse_opt((char *) data, &ofs->config); |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1350 | if (err) |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1351 | goto out_err; |
Erez Zadok | f45827e8 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1352 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1353 | err = -EINVAL; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1354 | if (!ofs->config.lowerdir) { |
Konstantin Khlebnikov | 07f2af7 | 2015-06-29 20:18:56 +0300 | [diff] [blame] | 1355 | if (!silent) |
| 1356 | pr_err("overlayfs: missing 'lowerdir'\n"); |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1357 | goto out_err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1360 | sb->s_stack_depth = 0; |
Miklos Szeredi | cf9a678 | 2015-12-11 16:30:49 +0100 | [diff] [blame] | 1361 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 1362 | /* Assume underlaying fs uses 32bit inodes unless proven otherwise */ |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 1363 | if (ofs->config.xino != OVL_XINO_OFF) |
| 1364 | ofs->xino_bits = BITS_PER_LONG - 32; |
| 1365 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1366 | if (ofs->config.upperdir) { |
| 1367 | if (!ofs->config.workdir) { |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1368 | pr_err("overlayfs: missing 'workdir'\n"); |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1369 | goto out_err; |
Miklos Szeredi | 53a08cb | 2014-12-13 00:59:51 +0100 | [diff] [blame] | 1370 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1371 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1372 | err = ovl_get_upper(ofs, &upperpath); |
Miklos Szeredi | 21a3b31 | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1373 | if (err) |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1374 | goto out_err; |
Miklos Szeredi | d719e8f | 2016-07-29 12:05:23 +0200 | [diff] [blame] | 1375 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1376 | err = ovl_get_workdir(ofs, &upperpath); |
Miklos Szeredi | 8ed61dc | 2017-11-09 10:23:28 +0100 | [diff] [blame] | 1377 | if (err) |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1378 | goto out_err; |
Miklos Szeredi | c6fe625 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1379 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1380 | if (!ofs->workdir) |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1381 | sb->s_flags |= SB_RDONLY; |
Miklos Szeredi | 6e88256 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1382 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1383 | sb->s_stack_depth = ofs->upper_mnt->mnt_sb->s_stack_depth; |
| 1384 | sb->s_time_gran = ofs->upper_mnt->mnt_sb->s_time_gran; |
Miklos Szeredi | c6fe625 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1385 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1386 | } |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1387 | oe = ovl_get_lowerstack(sb, ofs); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1388 | err = PTR_ERR(oe); |
| 1389 | if (IS_ERR(oe)) |
Miklos Szeredi | a9075cd | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1390 | goto out_err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1391 | |
hujianyang | 71cbad7 | 2015-01-15 13:20:57 +0800 | [diff] [blame] | 1392 | /* If the upper fs is nonexistent, we mark overlayfs r/o too */ |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1393 | if (!ofs->upper_mnt) |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1394 | sb->s_flags |= SB_RDONLY; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1395 | |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1396 | if (!(ovl_force_readonly(ofs)) && ofs->config.index) { |
| 1397 | err = ovl_get_indexdir(ofs, oe, &upperpath); |
Amir Goldstein | 54fb347 | 2017-06-21 15:28:38 +0300 | [diff] [blame] | 1398 | if (err) |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1399 | goto out_free_oe; |
Miklos Szeredi | 6e88256 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1400 | |
Amir Goldstein | 972d009 | 2017-09-19 12:14:18 +0300 | [diff] [blame] | 1401 | /* Force r/o mount with no index dir */ |
| 1402 | if (!ofs->indexdir) { |
| 1403 | dput(ofs->workdir); |
| 1404 | ofs->workdir = NULL; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1405 | sb->s_flags |= SB_RDONLY; |
Amir Goldstein | 972d009 | 2017-09-19 12:14:18 +0300 | [diff] [blame] | 1406 | } |
| 1407 | |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1408 | } |
| 1409 | |
Amir Goldstein | 972d009 | 2017-09-19 12:14:18 +0300 | [diff] [blame] | 1410 | /* Show index=off in /proc/mounts for forced r/o mount */ |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 1411 | if (!ofs->indexdir) { |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1412 | ofs->config.index = false; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 1413 | if (ofs->upper_mnt && ofs->config.nfs_export) { |
| 1414 | pr_warn("overlayfs: NFS export requires an index dir, falling back to nfs_export=off.\n"); |
| 1415 | ofs->config.nfs_export = false; |
| 1416 | } |
| 1417 | } |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 1418 | |
Amir Goldstein | 8383f17 | 2017-10-02 11:31:42 +0300 | [diff] [blame] | 1419 | if (ofs->config.nfs_export) |
| 1420 | sb->s_export_op = &ovl_export_operations; |
| 1421 | |
Konstantin Khlebnikov | 51f8f3c | 2017-01-10 21:30:21 +0300 | [diff] [blame] | 1422 | /* Never override disk quota limits or use reserved space */ |
| 1423 | cap_lower(cred->cap_effective, CAP_SYS_RESOURCE); |
| 1424 | |
Vivek Goyal | 655042c | 2016-10-14 03:03:36 +0200 | [diff] [blame] | 1425 | sb->s_magic = OVERLAYFS_SUPER_MAGIC; |
| 1426 | sb->s_op = &ovl_super_operations; |
| 1427 | sb->s_xattr = ovl_xattr_handlers; |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1428 | sb->s_fs_info = ofs; |
Miklos Szeredi | de2a4a5 | 2018-07-18 15:44:43 +0200 | [diff] [blame] | 1429 | sb->s_flags |= SB_POSIXACL; |
Vivek Goyal | 655042c | 2016-10-14 03:03:36 +0200 | [diff] [blame] | 1430 | |
Miklos Szeredi | c6fe625 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1431 | err = -ENOMEM; |
Miklos Szeredi | ca4c8a3 | 2016-12-16 11:02:55 +0100 | [diff] [blame] | 1432 | root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0)); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1433 | if (!root_dentry) |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1434 | goto out_free_oe; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1435 | |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 1436 | root_dentry->d_fsdata = oe; |
| 1437 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1438 | mntput(upperpath.mnt); |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame] | 1439 | if (upperpath.dentry) { |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 1440 | ovl_dentry_set_upper_alias(root_dentry); |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 1441 | if (ovl_is_impuredir(upperpath.dentry)) |
| 1442 | ovl_set_flag(OVL_IMPURE, d_inode(root_dentry)); |
Amir Goldstein | f3a1568 | 2017-05-24 15:29:33 +0300 | [diff] [blame] | 1443 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1444 | |
Amir Goldstein | b79e05a | 2017-06-25 16:37:17 +0300 | [diff] [blame] | 1445 | /* Root is always merge -> can have whiteouts */ |
| 1446 | ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry)); |
Amir Goldstein | 2ca3c14 | 2018-01-30 13:31:09 +0200 | [diff] [blame] | 1447 | ovl_dentry_set_flag(OVL_E_CONNECTED, root_dentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 1448 | ovl_inode_init(d_inode(root_dentry), upperpath.dentry, |
| 1449 | ovl_dentry_lower(root_dentry)); |
Miklos Szeredi | ed06e06 | 2015-12-09 16:11:59 +0100 | [diff] [blame] | 1450 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1451 | sb->s_root = root_dentry; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1452 | |
| 1453 | return 0; |
| 1454 | |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1455 | out_free_oe: |
| 1456 | ovl_entry_stack_free(oe); |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 1457 | kfree(oe); |
Miklos Szeredi | 4155c10 | 2017-11-10 09:39:15 +0100 | [diff] [blame] | 1458 | out_err: |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1459 | path_put(&upperpath); |
Miklos Szeredi | ad20448 | 2017-11-10 09:39:16 +0100 | [diff] [blame] | 1460 | ovl_free_fs(ofs); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1461 | out: |
| 1462 | return err; |
| 1463 | } |
| 1464 | |
| 1465 | static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags, |
| 1466 | const char *dev_name, void *raw_data) |
| 1467 | { |
| 1468 | return mount_nodev(fs_type, flags, raw_data, ovl_fill_super); |
| 1469 | } |
| 1470 | |
| 1471 | static struct file_system_type ovl_fs_type = { |
| 1472 | .owner = THIS_MODULE, |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1473 | .name = "overlay", |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1474 | .mount = ovl_mount, |
| 1475 | .kill_sb = kill_anon_super, |
| 1476 | }; |
Miklos Szeredi | ef94b18 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 1477 | MODULE_ALIAS_FS("overlay"); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1478 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1479 | static void ovl_inode_init_once(void *foo) |
| 1480 | { |
| 1481 | struct ovl_inode *oi = foo; |
| 1482 | |
| 1483 | inode_init_once(&oi->vfs_inode); |
| 1484 | } |
| 1485 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1486 | static int __init ovl_init(void) |
| 1487 | { |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1488 | int err; |
| 1489 | |
| 1490 | ovl_inode_cachep = kmem_cache_create("ovl_inode", |
| 1491 | sizeof(struct ovl_inode), 0, |
| 1492 | (SLAB_RECLAIM_ACCOUNT| |
| 1493 | SLAB_MEM_SPREAD|SLAB_ACCOUNT), |
| 1494 | ovl_inode_init_once); |
| 1495 | if (ovl_inode_cachep == NULL) |
| 1496 | return -ENOMEM; |
| 1497 | |
| 1498 | err = register_filesystem(&ovl_fs_type); |
| 1499 | if (err) |
| 1500 | kmem_cache_destroy(ovl_inode_cachep); |
| 1501 | |
| 1502 | return err; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | static void __exit ovl_exit(void) |
| 1506 | { |
| 1507 | unregister_filesystem(&ovl_fs_type); |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 1508 | |
| 1509 | /* |
| 1510 | * Make sure all delayed rcu free inodes are flushed before we |
| 1511 | * destroy cache. |
| 1512 | */ |
| 1513 | rcu_barrier(); |
| 1514 | kmem_cache_destroy(ovl_inode_cachep); |
| 1515 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | module_init(ovl_init); |
| 1519 | module_exit(ovl_exit); |