blob: f82defec02c16806adf0ed3f4dba309e92402ca4 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Miklos Szeredie9be9d52014-10-24 00:14:38 +02002/*
3 *
4 * Copyright (C) 2011 Novell Inc.
Miklos Szeredie9be9d52014-10-24 00:14:38 +02005 */
6
Ingo Molnar5b825c32017-02-02 17:54:15 +01007#include <uapi/linux/magic.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +02008#include <linux/fs.h>
9#include <linux/namei.h>
10#include <linux/xattr.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +020011#include <linux/mount.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +020012#include <linux/parser.h>
13#include <linux/module.h>
Andy Whitcroftcc259632014-10-24 00:14:38 +020014#include <linux/statfs.h>
Erez Zadokf45827e82014-10-24 00:14:38 +020015#include <linux/seq_file.h>
Miklos Szeredid837a492016-07-29 12:05:24 +020016#include <linux/posix_acl_xattr.h>
Amir Goldsteine487d882017-11-07 13:55:04 +020017#include <linux/exportfs.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +020018#include "overlayfs.h"
19
20MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
21MODULE_DESCRIPTION("Overlay filesystem");
22MODULE_LICENSE("GPL");
23
Miklos Szeredie9be9d52014-10-24 00:14:38 +020024
25struct ovl_dir_cache;
26
Miklos Szeredia78d9f02014-12-13 00:59:52 +010027#define OVL_MAX_STACK 500
28
Miklos Szeredi688ea0e2016-12-16 11:02:57 +010029static bool ovl_redirect_dir_def = IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR);
30module_param_named(redirect_dir, ovl_redirect_dir_def, bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020031MODULE_PARM_DESC(redirect_dir,
Miklos Szeredi688ea0e2016-12-16 11:02:57 +010032 "Default to on or off for the redirect_dir feature");
Miklos Szeredie9be9d52014-10-24 00:14:38 +020033
Miklos Szeredi438c84c2017-12-11 11:28:10 +010034static bool ovl_redirect_always_follow =
35 IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW);
36module_param_named(redirect_always_follow, ovl_redirect_always_follow,
37 bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020038MODULE_PARM_DESC(redirect_always_follow,
Miklos Szeredi438c84c2017-12-11 11:28:10 +010039 "Follow redirects even if redirect_dir feature is turned off");
40
Amir Goldstein02bcd152017-06-21 15:28:36 +030041static bool ovl_index_def = IS_ENABLED(CONFIG_OVERLAY_FS_INDEX);
42module_param_named(index, ovl_index_def, bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020043MODULE_PARM_DESC(index,
Amir Goldstein02bcd152017-06-21 15:28:36 +030044 "Default to on or off for the inodes index feature");
45
Amir Goldsteinf168f102018-01-19 11:26:53 +020046static bool ovl_nfs_export_def = IS_ENABLED(CONFIG_OVERLAY_FS_NFS_EXPORT);
47module_param_named(nfs_export, ovl_nfs_export_def, bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020048MODULE_PARM_DESC(nfs_export,
Amir Goldsteinf168f102018-01-19 11:26:53 +020049 "Default to on or off for the NFS export feature");
50
Amir Goldstein795939a2018-03-29 09:08:18 +030051static bool ovl_xino_auto_def = IS_ENABLED(CONFIG_OVERLAY_FS_XINO_AUTO);
52module_param_named(xino_auto, ovl_xino_auto_def, bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020053MODULE_PARM_DESC(xino_auto,
Amir Goldstein795939a2018-03-29 09:08:18 +030054 "Auto enable xino feature");
55
Miklos Szeredi4155c102017-11-10 09:39:15 +010056static void ovl_entry_stack_free(struct ovl_entry *oe)
57{
58 unsigned int i;
59
60 for (i = 0; i < oe->numlower; i++)
61 dput(oe->lowerstack[i].dentry);
62}
63
Vivek Goyald5791042018-05-11 11:49:27 -040064static bool ovl_metacopy_def = IS_ENABLED(CONFIG_OVERLAY_FS_METACOPY);
65module_param_named(metacopy, ovl_metacopy_def, bool, 0644);
Nicolas Schier253e7482019-06-17 09:39:00 +020066MODULE_PARM_DESC(metacopy,
Vivek Goyald5791042018-05-11 11:49:27 -040067 "Default to on or off for the metadata only copy up feature");
68
Miklos Szeredie9be9d52014-10-24 00:14:38 +020069static void ovl_dentry_release(struct dentry *dentry)
70{
71 struct ovl_entry *oe = dentry->d_fsdata;
72
73 if (oe) {
Miklos Szeredi4155c102017-11-10 09:39:15 +010074 ovl_entry_stack_free(oe);
Miklos Szeredie9be9d52014-10-24 00:14:38 +020075 kfree_rcu(oe, rcu);
76 }
77}
78
Miklos Szeredi2d902672016-06-30 08:53:27 +020079static struct dentry *ovl_d_real(struct dentry *dentry,
Miklos Szeredifb160432018-07-18 15:44:44 +020080 const struct inode *inode)
Miklos Szeredid101a122016-03-26 16:14:37 -040081{
82 struct dentry *real;
83
Miklos Szeredie8c985b2018-07-18 15:44:41 +020084 /* It's an overlay file */
85 if (inode && d_inode(dentry) == inode)
86 return dentry;
87
Miklos Szeredica4c8a32016-12-16 11:02:55 +010088 if (!d_is_reg(dentry)) {
Miklos Szeredid101a122016-03-26 16:14:37 -040089 if (!inode || inode == d_inode(dentry))
90 return dentry;
91 goto bug;
92 }
93
94 real = ovl_dentry_upper(dentry);
Vivek Goyal2c3d7352018-05-11 11:49:31 -040095 if (real && (inode == d_inode(real)))
Miklos Szeredid101a122016-03-26 16:14:37 -040096 return real;
97
Vivek Goyal2c3d7352018-05-11 11:49:31 -040098 if (real && !inode && ovl_has_upperdata(d_inode(dentry)))
99 return real;
100
101 real = ovl_dentry_lowerdata(dentry);
Miklos Szeredid101a122016-03-26 16:14:37 -0400102 if (!real)
103 goto bug;
104
Miklos Szeredic4fcfc12016-11-29 10:20:24 +0100105 /* Handle recursion */
Miklos Szeredifb160432018-07-18 15:44:44 +0200106 real = d_real(real, inode);
Miklos Szeredic4fcfc12016-11-29 10:20:24 +0100107
Miklos Szeredid101a122016-03-26 16:14:37 -0400108 if (!inode || inode == d_inode(real))
109 return real;
Miklos Szeredid101a122016-03-26 16:14:37 -0400110bug:
Miklos Szeredi656189d2016-07-29 12:05:24 +0200111 WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry,
Miklos Szeredid101a122016-03-26 16:14:37 -0400112 inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
113 return dentry;
114}
115
Miklos Szeredi3bb7df92020-03-17 15:04:22 +0100116static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
117{
118 int ret = 1;
119
120 if (weak) {
121 if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE)
122 ret = d->d_op->d_weak_revalidate(d, flags);
123 } else if (d->d_flags & DCACHE_OP_REVALIDATE) {
124 ret = d->d_op->d_revalidate(d, flags);
125 if (!ret) {
126 if (!(flags & LOOKUP_RCU))
127 d_invalidate(d);
128 ret = -ESTALE;
129 }
130 }
131 return ret;
132}
133
134static int ovl_dentry_revalidate_common(struct dentry *dentry,
135 unsigned int flags, bool weak)
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200136{
137 struct ovl_entry *oe = dentry->d_fsdata;
Miklos Szeredibccece12020-03-17 15:04:22 +0100138 struct dentry *upper;
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200139 unsigned int i;
140 int ret = 1;
141
Miklos Szeredibccece12020-03-17 15:04:22 +0100142 upper = ovl_dentry_upper(dentry);
143 if (upper)
144 ret = ovl_revalidate_real(upper, flags, weak);
145
Miklos Szeredi3bb7df92020-03-17 15:04:22 +0100146 for (i = 0; ret > 0 && i < oe->numlower; i++) {
147 ret = ovl_revalidate_real(oe->lowerstack[i].dentry, flags,
148 weak);
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200149 }
Miklos Szeredi3bb7df92020-03-17 15:04:22 +0100150 return ret;
151}
152
153static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
154{
155 return ovl_dentry_revalidate_common(dentry, flags, false);
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200156}
157
158static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
159{
Miklos Szeredi3bb7df92020-03-17 15:04:22 +0100160 return ovl_dentry_revalidate_common(dentry, flags, true);
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200161}
162
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200163static const struct dentry_operations ovl_dentry_operations = {
164 .d_release = ovl_dentry_release,
Miklos Szeredid101a122016-03-26 16:14:37 -0400165 .d_real = ovl_d_real,
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200166 .d_revalidate = ovl_dentry_revalidate,
167 .d_weak_revalidate = ovl_dentry_weak_revalidate,
168};
169
Amir Goldstein13cf1992017-06-12 09:54:40 +0300170static struct kmem_cache *ovl_inode_cachep;
171
172static 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 Nakagawab3885bd2017-09-26 03:09:53 +0900176 if (!oi)
177 return NULL;
178
Miklos Szeredi04a01ac2017-07-04 22:03:16 +0200179 oi->cache = NULL;
Miklos Szeredicf31c462017-07-04 22:03:16 +0200180 oi->redirect = NULL;
Miklos Szeredi04a01ac2017-07-04 22:03:16 +0200181 oi->version = 0;
Miklos Szeredi13c72072017-07-04 22:03:16 +0200182 oi->flags = 0;
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200183 oi->__upperdentry = NULL;
Miklos Szeredi25b77132017-07-04 22:03:16 +0200184 oi->lower = NULL;
Vivek Goyal2664bd02018-05-11 11:49:30 -0400185 oi->lowerdata = NULL;
Amir Goldsteina015daf2017-06-21 15:28:51 +0300186 mutex_init(&oi->lock);
Miklos Szeredi25b77132017-07-04 22:03:16 +0200187
Amir Goldstein13cf1992017-06-12 09:54:40 +0300188 return &oi->vfs_inode;
189}
190
Al Viro0b269de2019-04-15 22:52:17 -0400191static void ovl_free_inode(struct inode *inode)
Amir Goldstein13cf1992017-06-12 09:54:40 +0300192{
Al Viro0b269de2019-04-15 22:52:17 -0400193 struct ovl_inode *oi = OVL_I(inode);
Amir Goldstein13cf1992017-06-12 09:54:40 +0300194
Al Viro0b269de2019-04-15 22:52:17 -0400195 kfree(oi->redirect);
196 mutex_destroy(&oi->lock);
197 kmem_cache_free(ovl_inode_cachep, oi);
Amir Goldstein13cf1992017-06-12 09:54:40 +0300198}
199
200static void ovl_destroy_inode(struct inode *inode)
201{
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200202 struct ovl_inode *oi = OVL_I(inode);
203
204 dput(oi->__upperdentry);
Amir Goldstein31747ed2018-01-14 18:35:40 +0200205 iput(oi->lower);
Vivek Goyal2664bd02018-05-11 11:49:30 -0400206 if (S_ISDIR(inode->i_mode))
207 ovl_dir_cache_free(inode);
208 else
209 iput(oi->lowerdata);
Amir Goldstein13cf1992017-06-12 09:54:40 +0300210}
211
Miklos Szerediad204482017-11-10 09:39:16 +0100212static void ovl_free_fs(struct ovl_fs *ofs)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200213{
Miklos Szeredidf820f82020-06-04 10:48:19 +0200214 struct vfsmount **mounts;
Miklos Szeredidd662662014-12-13 00:59:43 +0100215 unsigned i;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200216
Amir Goldstein0be0bfd2019-07-12 15:24:34 +0300217 iput(ofs->workbasedir_trap);
Amir Goldstein146d62e2019-04-18 17:42:08 +0300218 iput(ofs->indexdir_trap);
219 iput(ofs->workdir_trap);
Chengguang Xuc21c8392020-04-24 10:55:17 +0800220 dput(ofs->whiteout);
Miklos Szerediad204482017-11-10 09:39:16 +0100221 dput(ofs->indexdir);
222 dput(ofs->workdir);
223 if (ofs->workdir_locked)
224 ovl_inuse_unlock(ofs->workbasedir);
225 dput(ofs->workbasedir);
226 if (ofs->upperdir_locked)
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200227 ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root);
Miklos Szeredidf820f82020-06-04 10:48:19 +0200228
229 /* Hack! Reuse ofs->layers as a vfsmount array before freeing it */
230 mounts = (struct vfsmount **) ofs->layers;
Miklos Szeredib8e42a62020-06-04 10:48:19 +0200231 for (i = 0; i < ofs->numlayer; i++) {
Amir Goldstein94375f92019-11-15 14:12:40 +0200232 iput(ofs->layers[i].trap);
Miklos Szeredidf820f82020-06-04 10:48:19 +0200233 mounts[i] = ofs->layers[i].mnt;
Amir Goldstein146d62e2019-04-18 17:42:08 +0300234 }
Miklos Szeredidf820f82020-06-04 10:48:19 +0200235 kern_unmount_array(mounts, ofs->numlayer);
Amir Goldstein94375f92019-11-15 14:12:40 +0200236 kfree(ofs->layers);
Amir Goldsteinb7bf9902020-01-14 22:17:25 +0200237 for (i = 0; i < ofs->numfs; i++)
Amir Goldstein07f1e592020-01-14 21:59:22 +0200238 free_anon_bdev(ofs->fs[i].pseudo_dev);
239 kfree(ofs->fs);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200240
Miklos Szerediad204482017-11-10 09:39:16 +0100241 kfree(ofs->config.lowerdir);
242 kfree(ofs->config.upperdir);
243 kfree(ofs->config.workdir);
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100244 kfree(ofs->config.redirect_mode);
Miklos Szerediad204482017-11-10 09:39:16 +0100245 if (ofs->creator_cred)
246 put_cred(ofs->creator_cred);
247 kfree(ofs);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200248}
249
Miklos Szeredia9075cd2017-11-10 09:39:15 +0100250static void ovl_put_super(struct super_block *sb)
251{
252 struct ovl_fs *ofs = sb->s_fs_info;
253
254 ovl_free_fs(ofs);
255}
256
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800257/* Sync real dirty inodes in upper filesystem (if it exists) */
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200258static int ovl_sync_fs(struct super_block *sb, int wait)
259{
Miklos Szerediad204482017-11-10 09:39:16 +0100260 struct ovl_fs *ofs = sb->s_fs_info;
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200261 struct super_block *upper_sb;
262 int ret;
263
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200264 if (!ovl_upper_mnt(ofs))
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200265 return 0;
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800266
267 /*
Konstantin Khlebnikov32b1924b22020-04-09 11:29:47 +0300268 * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC).
269 * All the super blocks will be iterated, including upper_sb.
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800270 *
271 * If this is a syncfs(2) call, then we do need to call
272 * sync_filesystem() on upper_sb, but enough if we do it when being
273 * called with wait == 1.
274 */
275 if (!wait)
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200276 return 0;
277
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200278 upper_sb = ovl_upper_mnt(ofs)->mnt_sb;
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800279
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200280 down_read(&upper_sb->s_umount);
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800281 ret = sync_filesystem(upper_sb);
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200282 up_read(&upper_sb->s_umount);
Chengguang Xue8d4bfe2017-11-29 10:01:32 +0800283
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200284 return ret;
285}
286
Andy Whitcroftcc259632014-10-24 00:14:38 +0200287/**
288 * ovl_statfs
289 * @sb: The overlayfs super block
290 * @buf: The struct kstatfs to fill in with stats
291 *
292 * Get the filesystem statistics. As writes always target the upper layer
Miklos Szeredi4ebc5812014-12-13 00:59:46 +0100293 * filesystem pass the statfs to the upper filesystem (if it exists)
Andy Whitcroftcc259632014-10-24 00:14:38 +0200294 */
295static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
296{
297 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
298 struct dentry *root_dentry = dentry->d_sb->s_root;
299 struct path path;
300 int err;
301
Miklos Szeredi4ebc5812014-12-13 00:59:46 +0100302 ovl_path_real(root_dentry, &path);
Andy Whitcroftcc259632014-10-24 00:14:38 +0200303
304 err = vfs_statfs(&path, buf);
305 if (!err) {
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +0100306 buf->f_namelen = ofs->namelen;
Andy Whitcroftcc259632014-10-24 00:14:38 +0200307 buf->f_type = OVERLAYFS_SUPER_MAGIC;
308 }
309
310 return err;
311}
312
Amir Goldstein02bcd152017-06-21 15:28:36 +0300313/* Will this overlay be forced to mount/remount ro? */
Miklos Szerediad204482017-11-10 09:39:16 +0100314static bool ovl_force_readonly(struct ovl_fs *ofs)
Amir Goldstein02bcd152017-06-21 15:28:36 +0300315{
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200316 return (!ovl_upper_mnt(ofs) || !ofs->workdir);
Amir Goldstein02bcd152017-06-21 15:28:36 +0300317}
318
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100319static const char *ovl_redirect_mode_def(void)
320{
321 return ovl_redirect_dir_def ? "on" : "off";
322}
323
Amir Goldstein795939a2018-03-29 09:08:18 +0300324static const char * const ovl_xino_str[] = {
325 "off",
326 "auto",
327 "on",
328};
329
330static inline int ovl_xino_def(void)
331{
332 return ovl_xino_auto_def ? OVL_XINO_AUTO : OVL_XINO_OFF;
333}
334
Erez Zadokf45827e82014-10-24 00:14:38 +0200335/**
336 * ovl_show_options
337 *
338 * Prints the mount options for a given superblock.
339 * Returns zero; does not fail.
340 */
341static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
342{
343 struct super_block *sb = dentry->d_sb;
Miklos Szerediad204482017-11-10 09:39:16 +0100344 struct ovl_fs *ofs = sb->s_fs_info;
Erez Zadokf45827e82014-10-24 00:14:38 +0200345
Miklos Szerediad204482017-11-10 09:39:16 +0100346 seq_show_option(m, "lowerdir", ofs->config.lowerdir);
347 if (ofs->config.upperdir) {
348 seq_show_option(m, "upperdir", ofs->config.upperdir);
349 seq_show_option(m, "workdir", ofs->config.workdir);
Miklos Szeredi53a08cb2014-12-13 00:59:51 +0100350 }
Miklos Szerediad204482017-11-10 09:39:16 +0100351 if (ofs->config.default_permissions)
Miklos Szeredi8d3095f2015-10-12 17:11:44 +0200352 seq_puts(m, ",default_permissions");
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100353 if (strcmp(ofs->config.redirect_mode, ovl_redirect_mode_def()) != 0)
354 seq_printf(m, ",redirect_dir=%s", ofs->config.redirect_mode);
Miklos Szerediad204482017-11-10 09:39:16 +0100355 if (ofs->config.index != ovl_index_def)
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100356 seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off");
Amir Goldsteinf168f102018-01-19 11:26:53 +0200357 if (ofs->config.nfs_export != ovl_nfs_export_def)
358 seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ?
359 "on" : "off");
Amir Goldstein0f831ec2019-11-16 18:14:41 +0200360 if (ofs->config.xino != ovl_xino_def() && !ovl_same_fs(sb))
Amir Goldstein795939a2018-03-29 09:08:18 +0300361 seq_printf(m, ",xino=%s", ovl_xino_str[ofs->config.xino]);
Vivek Goyald5791042018-05-11 11:49:27 -0400362 if (ofs->config.metacopy != ovl_metacopy_def)
363 seq_printf(m, ",metacopy=%s",
364 ofs->config.metacopy ? "on" : "off");
Erez Zadokf45827e82014-10-24 00:14:38 +0200365 return 0;
366}
367
Seunghun Lee3cdf6fe2015-01-03 02:26:49 +0900368static int ovl_remount(struct super_block *sb, int *flags, char *data)
369{
Miklos Szerediad204482017-11-10 09:39:16 +0100370 struct ovl_fs *ofs = sb->s_fs_info;
Chengguang Xu399c1092020-04-22 12:28:43 +0800371 struct super_block *upper_sb;
372 int ret = 0;
Seunghun Lee3cdf6fe2015-01-03 02:26:49 +0900373
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800374 if (!(*flags & SB_RDONLY) && ovl_force_readonly(ofs))
Seunghun Lee3cdf6fe2015-01-03 02:26:49 +0900375 return -EROFS;
376
Chengguang Xu399c1092020-04-22 12:28:43 +0800377 if (*flags & SB_RDONLY && !sb_rdonly(sb)) {
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200378 upper_sb = ovl_upper_mnt(ofs)->mnt_sb;
Chengguang Xu399c1092020-04-22 12:28:43 +0800379 down_read(&upper_sb->s_umount);
380 ret = sync_filesystem(upper_sb);
381 up_read(&upper_sb->s_umount);
382 }
383
384 return ret;
Seunghun Lee3cdf6fe2015-01-03 02:26:49 +0900385}
386
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200387static const struct super_operations ovl_super_operations = {
Amir Goldstein13cf1992017-06-12 09:54:40 +0300388 .alloc_inode = ovl_alloc_inode,
Al Viro0b269de2019-04-15 22:52:17 -0400389 .free_inode = ovl_free_inode,
Amir Goldstein13cf1992017-06-12 09:54:40 +0300390 .destroy_inode = ovl_destroy_inode,
391 .drop_inode = generic_delete_inode,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200392 .put_super = ovl_put_super,
Amir Goldsteine593b2b2017-01-23 14:32:21 +0200393 .sync_fs = ovl_sync_fs,
Andy Whitcroftcc259632014-10-24 00:14:38 +0200394 .statfs = ovl_statfs,
Erez Zadokf45827e82014-10-24 00:14:38 +0200395 .show_options = ovl_show_options,
Seunghun Lee3cdf6fe2015-01-03 02:26:49 +0900396 .remount_fs = ovl_remount,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200397};
398
399enum {
400 OPT_LOWERDIR,
401 OPT_UPPERDIR,
402 OPT_WORKDIR,
Miklos Szeredi8d3095f2015-10-12 17:11:44 +0200403 OPT_DEFAULT_PERMISSIONS,
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100404 OPT_REDIRECT_DIR,
Amir Goldstein02bcd152017-06-21 15:28:36 +0300405 OPT_INDEX_ON,
406 OPT_INDEX_OFF,
Amir Goldsteinf168f102018-01-19 11:26:53 +0200407 OPT_NFS_EXPORT_ON,
408 OPT_NFS_EXPORT_OFF,
Amir Goldstein795939a2018-03-29 09:08:18 +0300409 OPT_XINO_ON,
410 OPT_XINO_OFF,
411 OPT_XINO_AUTO,
Vivek Goyald5791042018-05-11 11:49:27 -0400412 OPT_METACOPY_ON,
413 OPT_METACOPY_OFF,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200414 OPT_ERR,
415};
416
417static const match_table_t ovl_tokens = {
418 {OPT_LOWERDIR, "lowerdir=%s"},
419 {OPT_UPPERDIR, "upperdir=%s"},
420 {OPT_WORKDIR, "workdir=%s"},
Miklos Szeredi8d3095f2015-10-12 17:11:44 +0200421 {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100422 {OPT_REDIRECT_DIR, "redirect_dir=%s"},
Amir Goldstein02bcd152017-06-21 15:28:36 +0300423 {OPT_INDEX_ON, "index=on"},
424 {OPT_INDEX_OFF, "index=off"},
Amir Goldsteinf168f102018-01-19 11:26:53 +0200425 {OPT_NFS_EXPORT_ON, "nfs_export=on"},
426 {OPT_NFS_EXPORT_OFF, "nfs_export=off"},
Amir Goldstein795939a2018-03-29 09:08:18 +0300427 {OPT_XINO_ON, "xino=on"},
428 {OPT_XINO_OFF, "xino=off"},
429 {OPT_XINO_AUTO, "xino=auto"},
Vivek Goyald5791042018-05-11 11:49:27 -0400430 {OPT_METACOPY_ON, "metacopy=on"},
431 {OPT_METACOPY_OFF, "metacopy=off"},
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200432 {OPT_ERR, NULL}
433};
434
Miklos Szeredi91c77942014-11-20 16:40:00 +0100435static char *ovl_next_opt(char **s)
436{
437 char *sbegin = *s;
438 char *p;
439
440 if (sbegin == NULL)
441 return NULL;
442
443 for (p = sbegin; *p; p++) {
444 if (*p == '\\') {
445 p++;
446 if (!*p)
447 break;
448 } else if (*p == ',') {
449 *p = '\0';
450 *s = p + 1;
451 return sbegin;
452 }
453 }
454 *s = NULL;
455 return sbegin;
456}
457
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100458static int ovl_parse_redirect_mode(struct ovl_config *config, const char *mode)
459{
460 if (strcmp(mode, "on") == 0) {
461 config->redirect_dir = true;
462 /*
463 * Does not make sense to have redirect creation without
464 * redirect following.
465 */
466 config->redirect_follow = true;
467 } else if (strcmp(mode, "follow") == 0) {
468 config->redirect_follow = true;
469 } else if (strcmp(mode, "off") == 0) {
470 if (ovl_redirect_always_follow)
471 config->redirect_follow = true;
472 } else if (strcmp(mode, "nofollow") != 0) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800473 pr_err("bad mount option \"redirect_dir=%s\"\n",
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100474 mode);
475 return -EINVAL;
476 }
477
478 return 0;
479}
480
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200481static int ovl_parse_opt(char *opt, struct ovl_config *config)
482{
483 char *p;
Vivek Goyald5791042018-05-11 11:49:27 -0400484 int err;
Miklos Szeredid47748e2018-11-01 21:31:39 +0100485 bool metacopy_opt = false, redirect_opt = false;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300486 bool nfs_export_opt = false, index_opt = false;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200487
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100488 config->redirect_mode = kstrdup(ovl_redirect_mode_def(), GFP_KERNEL);
489 if (!config->redirect_mode)
490 return -ENOMEM;
491
Miklos Szeredi91c77942014-11-20 16:40:00 +0100492 while ((p = ovl_next_opt(&opt)) != NULL) {
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200493 int token;
494 substring_t args[MAX_OPT_ARGS];
495
496 if (!*p)
497 continue;
498
499 token = match_token(p, ovl_tokens, args);
500 switch (token) {
501 case OPT_UPPERDIR:
502 kfree(config->upperdir);
503 config->upperdir = match_strdup(&args[0]);
504 if (!config->upperdir)
505 return -ENOMEM;
506 break;
507
508 case OPT_LOWERDIR:
509 kfree(config->lowerdir);
510 config->lowerdir = match_strdup(&args[0]);
511 if (!config->lowerdir)
512 return -ENOMEM;
513 break;
514
515 case OPT_WORKDIR:
516 kfree(config->workdir);
517 config->workdir = match_strdup(&args[0]);
518 if (!config->workdir)
519 return -ENOMEM;
520 break;
521
Miklos Szeredi8d3095f2015-10-12 17:11:44 +0200522 case OPT_DEFAULT_PERMISSIONS:
523 config->default_permissions = true;
524 break;
525
Miklos Szeredi438c84c2017-12-11 11:28:10 +0100526 case OPT_REDIRECT_DIR:
527 kfree(config->redirect_mode);
528 config->redirect_mode = match_strdup(&args[0]);
529 if (!config->redirect_mode)
530 return -ENOMEM;
Miklos Szeredid47748e2018-11-01 21:31:39 +0100531 redirect_opt = true;
Miklos Szeredia6c60652016-12-16 11:02:56 +0100532 break;
533
Amir Goldstein02bcd152017-06-21 15:28:36 +0300534 case OPT_INDEX_ON:
535 config->index = true;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300536 index_opt = true;
Amir Goldstein02bcd152017-06-21 15:28:36 +0300537 break;
538
539 case OPT_INDEX_OFF:
540 config->index = false;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300541 index_opt = true;
Amir Goldstein02bcd152017-06-21 15:28:36 +0300542 break;
543
Amir Goldsteinf168f102018-01-19 11:26:53 +0200544 case OPT_NFS_EXPORT_ON:
545 config->nfs_export = true;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300546 nfs_export_opt = true;
Amir Goldsteinf168f102018-01-19 11:26:53 +0200547 break;
548
549 case OPT_NFS_EXPORT_OFF:
550 config->nfs_export = false;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300551 nfs_export_opt = true;
Amir Goldsteinf168f102018-01-19 11:26:53 +0200552 break;
553
Amir Goldstein795939a2018-03-29 09:08:18 +0300554 case OPT_XINO_ON:
555 config->xino = OVL_XINO_ON;
556 break;
557
558 case OPT_XINO_OFF:
559 config->xino = OVL_XINO_OFF;
560 break;
561
562 case OPT_XINO_AUTO:
563 config->xino = OVL_XINO_AUTO;
564 break;
565
Vivek Goyald5791042018-05-11 11:49:27 -0400566 case OPT_METACOPY_ON:
567 config->metacopy = true;
Miklos Szeredid47748e2018-11-01 21:31:39 +0100568 metacopy_opt = true;
Vivek Goyald5791042018-05-11 11:49:27 -0400569 break;
570
571 case OPT_METACOPY_OFF:
572 config->metacopy = false;
Amir Goldsteinb0def882020-04-09 18:58:34 +0300573 metacopy_opt = true;
Vivek Goyald5791042018-05-11 11:49:27 -0400574 break;
575
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200576 default:
lijiazi1bd0a3a2019-12-16 19:12:32 +0800577 pr_err("unrecognized mount option \"%s\" or missing value\n",
578 p);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200579 return -EINVAL;
580 }
581 }
hujianyang71cbad72015-01-15 13:20:57 +0800582
Amir Goldsteinf0e1266e2020-07-13 17:19:44 +0300583 /* Workdir/index are useless in non-upper mount */
584 if (!config->upperdir) {
585 if (config->workdir) {
586 pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
587 config->workdir);
588 kfree(config->workdir);
589 config->workdir = NULL;
590 }
591 if (config->index && index_opt) {
592 pr_info("option \"index=on\" is useless in a non-upper mount, ignore\n");
593 index_opt = false;
594 }
595 config->index = false;
hujianyang71cbad72015-01-15 13:20:57 +0800596 }
597
Vivek Goyald5791042018-05-11 11:49:27 -0400598 err = ovl_parse_redirect_mode(config, config->redirect_mode);
599 if (err)
600 return err;
601
Miklos Szeredid47748e2018-11-01 21:31:39 +0100602 /*
603 * This is to make the logic below simpler. It doesn't make any other
604 * difference, since config->redirect_dir is only used for upper.
605 */
606 if (!config->upperdir && config->redirect_follow)
607 config->redirect_dir = true;
608
609 /* Resolve metacopy -> redirect_dir dependency */
610 if (config->metacopy && !config->redirect_dir) {
611 if (metacopy_opt && redirect_opt) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800612 pr_err("conflicting options: metacopy=on,redirect_dir=%s\n",
Miklos Szeredid47748e2018-11-01 21:31:39 +0100613 config->redirect_mode);
614 return -EINVAL;
615 }
616 if (redirect_opt) {
617 /*
618 * There was an explicit redirect_dir=... that resulted
619 * in this conflict.
620 */
lijiazi1bd0a3a2019-12-16 19:12:32 +0800621 pr_info("disabling metacopy due to redirect_dir=%s\n",
Miklos Szeredid47748e2018-11-01 21:31:39 +0100622 config->redirect_mode);
623 config->metacopy = false;
624 } else {
625 /* Automatically enable redirect otherwise. */
626 config->redirect_follow = config->redirect_dir = true;
627 }
Vivek Goyald5791042018-05-11 11:49:27 -0400628 }
629
Amir Goldsteinb0def882020-04-09 18:58:34 +0300630 /* Resolve nfs_export -> index dependency */
631 if (config->nfs_export && !config->index) {
Amir Goldsteinf0e1266e2020-07-13 17:19:44 +0300632 if (!config->upperdir && config->redirect_follow) {
633 pr_info("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n");
634 config->nfs_export = false;
635 } else if (nfs_export_opt && index_opt) {
Amir Goldsteinb0def882020-04-09 18:58:34 +0300636 pr_err("conflicting options: nfs_export=on,index=off\n");
637 return -EINVAL;
Amir Goldsteinf0e1266e2020-07-13 17:19:44 +0300638 } else if (index_opt) {
Amir Goldsteinb0def882020-04-09 18:58:34 +0300639 /*
640 * There was an explicit index=off that resulted
641 * in this conflict.
642 */
643 pr_info("disabling nfs_export due to index=off\n");
644 config->nfs_export = false;
645 } else {
646 /* Automatically enable index otherwise. */
647 config->index = true;
648 }
649 }
650
651 /* Resolve nfs_export -> !metacopy dependency */
652 if (config->nfs_export && config->metacopy) {
653 if (nfs_export_opt && metacopy_opt) {
654 pr_err("conflicting options: nfs_export=on,metacopy=on\n");
655 return -EINVAL;
656 }
657 if (metacopy_opt) {
658 /*
659 * There was an explicit metacopy=on that resulted
660 * in this conflict.
661 */
662 pr_info("disabling nfs_export due to metacopy=on\n");
663 config->nfs_export = false;
664 } else {
665 /*
666 * There was an explicit nfs_export=on that resulted
667 * in this conflict.
668 */
669 pr_info("disabling metacopy due to nfs_export=on\n");
670 config->metacopy = false;
671 }
672 }
673
Vivek Goyald5791042018-05-11 11:49:27 -0400674 return 0;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200675}
676
677#define OVL_WORKDIR_NAME "work"
Amir Goldstein02bcd152017-06-21 15:28:36 +0300678#define OVL_INDEXDIR_NAME "index"
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200679
Miklos Szerediad204482017-11-10 09:39:16 +0100680static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
Amir Goldstein6b8aa122017-06-21 15:28:35 +0300681 const char *name, bool persist)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200682{
Miklos Szerediad204482017-11-10 09:39:16 +0100683 struct inode *dir = ofs->workbasedir->d_inode;
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +0200684 struct vfsmount *mnt = ovl_upper_mnt(ofs);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200685 struct dentry *work;
686 int err;
687 bool retried = false;
688
Al Viro59551022016-01-22 15:40:57 -0500689 inode_lock_nested(dir, I_MUTEX_PARENT);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200690retry:
Miklos Szerediad204482017-11-10 09:39:16 +0100691 work = lookup_one_len(name, ofs->workbasedir, strlen(name));
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200692
693 if (!IS_ERR(work)) {
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200694 struct iattr attr = {
695 .ia_valid = ATTR_MODE,
Al Viro32a3d842016-12-04 17:33:17 +0000696 .ia_mode = S_IFDIR | 0,
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200697 };
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200698
699 if (work->d_inode) {
700 err = -EEXIST;
701 if (retried)
702 goto out_dput;
703
Amir Goldstein6b8aa122017-06-21 15:28:35 +0300704 if (persist)
705 goto out_unlock;
706
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200707 retried = true;
Amir Goldstein235ce9e2020-08-30 23:28:03 +0300708 err = ovl_workdir_cleanup(dir, mnt, work, 0);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200709 dput(work);
Amir Goldstein235ce9e2020-08-30 23:28:03 +0300710 if (err == -EINVAL) {
711 work = ERR_PTR(err);
712 goto out_unlock;
713 }
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200714 goto retry;
715 }
716
Miklos Szeredi95a1c812018-05-16 17:51:25 +0300717 work = ovl_create_real(dir, work, OVL_CATTR(attr.ia_mode));
718 err = PTR_ERR(work);
719 if (IS_ERR(work))
720 goto out_err;
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200721
Miklos Szeredicb348ed2016-10-04 14:40:44 +0200722 /*
723 * Try to remove POSIX ACL xattrs from workdir. We are good if:
724 *
725 * a) success (there was a POSIX ACL xattr and was removed)
726 * b) -ENODATA (there was no POSIX ACL xattr)
727 * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported)
728 *
729 * There are various other error values that could effectively
730 * mean that the xattr doesn't exist (e.g. -ERANGE is returned
731 * if the xattr name is too long), but the set of filesystems
732 * allowed as upper are limited to "normal" ones, where checking
733 * for the above two errors is sufficient.
734 */
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200735 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT);
Miklos Szeredie1ff3dd2016-09-05 13:55:20 +0200736 if (err && err != -ENODATA && err != -EOPNOTSUPP)
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200737 goto out_dput;
738
739 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS);
Miklos Szeredie1ff3dd2016-09-05 13:55:20 +0200740 if (err && err != -ENODATA && err != -EOPNOTSUPP)
Miklos Szeredic11b9fd2016-09-01 11:11:59 +0200741 goto out_dput;
742
743 /* Clear any inherited mode bits */
744 inode_lock(work->d_inode);
745 err = notify_change(work, &attr, NULL);
746 inode_unlock(work->d_inode);
747 if (err)
748 goto out_dput;
Amir Goldstein6b8aa122017-06-21 15:28:35 +0300749 } else {
750 err = PTR_ERR(work);
751 goto out_err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200752 }
753out_unlock:
youngjun2068cf72020-06-07 02:04:06 -0700754 inode_unlock(dir);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200755 return work;
756
757out_dput:
758 dput(work);
Amir Goldstein6b8aa122017-06-21 15:28:35 +0300759out_err:
lijiazi1bd0a3a2019-12-16 19:12:32 +0800760 pr_warn("failed to create directory %s/%s (errno: %i); mounting read-only\n",
Miklos Szerediad204482017-11-10 09:39:16 +0100761 ofs->config.workdir, name, -err);
Amir Goldstein6b8aa122017-06-21 15:28:35 +0300762 work = NULL;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200763 goto out_unlock;
764}
765
Miklos Szeredi91c77942014-11-20 16:40:00 +0100766static void ovl_unescape(char *s)
767{
768 char *d = s;
769
770 for (;; s++, d++) {
771 if (*s == '\\')
772 s++;
773 *d = *s;
774 if (!*s)
775 break;
776 }
777}
778
Miklos Szerediab508822014-12-13 00:59:49 +0100779static int ovl_mount_dir_noesc(const char *name, struct path *path)
780{
Miklos Szeredia78d9f02014-12-13 00:59:52 +0100781 int err = -EINVAL;
Miklos Szerediab508822014-12-13 00:59:49 +0100782
Miklos Szeredia78d9f02014-12-13 00:59:52 +0100783 if (!*name) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800784 pr_err("empty lowerdir\n");
Miklos Szeredia78d9f02014-12-13 00:59:52 +0100785 goto out;
786 }
Miklos Szerediab508822014-12-13 00:59:49 +0100787 err = kern_path(name, LOOKUP_FOLLOW, path);
788 if (err) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800789 pr_err("failed to resolve '%s': %i\n", name, err);
Miklos Szerediab508822014-12-13 00:59:49 +0100790 goto out;
791 }
792 err = -EINVAL;
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200793 if (ovl_dentry_weird(path->dentry)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800794 pr_err("filesystem on '%s' not supported\n", name);
Miklos Szerediab508822014-12-13 00:59:49 +0100795 goto out_put;
796 }
Miklos Szeredi2b8c30e2016-12-16 11:02:56 +0100797 if (!d_is_dir(path->dentry)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +0800798 pr_err("'%s' not a directory\n", name);
Miklos Szerediab508822014-12-13 00:59:49 +0100799 goto out_put;
800 }
801 return 0;
802
803out_put:
Miklos Szeredi8aafcb52017-11-09 10:23:28 +0100804 path_put_init(path);
Miklos Szerediab508822014-12-13 00:59:49 +0100805out:
806 return err;
807}
808
809static int ovl_mount_dir(const char *name, struct path *path)
810{
811 int err = -ENOMEM;
812 char *tmp = kstrdup(name, GFP_KERNEL);
813
814 if (tmp) {
815 ovl_unescape(tmp);
816 err = ovl_mount_dir_noesc(tmp, path);
Miklos Szeredi7c03b5d2015-06-22 13:53:48 +0200817
Miklos Szeredibccece12020-03-17 15:04:22 +0100818 if (!err && path->dentry->d_flags & DCACHE_OP_REAL) {
Miklos Szeredi7925dad2020-03-17 15:04:22 +0100819 pr_err("filesystem on '%s' not supported as upperdir\n",
820 tmp);
821 path_put_init(path);
822 err = -EINVAL;
823 }
Miklos Szerediab508822014-12-13 00:59:49 +0100824 kfree(tmp);
825 }
826 return err;
827}
828
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +0100829static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs,
830 const char *name)
831{
832 struct kstatfs statfs;
833 int err = vfs_statfs(path, &statfs);
834
835 if (err)
lijiazi1bd0a3a2019-12-16 19:12:32 +0800836 pr_err("statfs failed on '%s'\n", name);
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +0100837 else
838 ofs->namelen = max(ofs->namelen, statfs.f_namelen);
839
840 return err;
841}
842
843static int ovl_lower_dir(const char *name, struct path *path,
Miklos Szeredif4288842020-03-17 15:04:22 +0100844 struct ovl_fs *ofs, int *stack_depth)
Miklos Szerediab508822014-12-13 00:59:49 +0100845{
Amir Goldsteine487d882017-11-07 13:55:04 +0200846 int fh_type;
Miklos Szerediab508822014-12-13 00:59:49 +0100847 int err;
Miklos Szerediab508822014-12-13 00:59:49 +0100848
Miklos Szeredia78d9f02014-12-13 00:59:52 +0100849 err = ovl_mount_dir_noesc(name, path);
Miklos Szerediab508822014-12-13 00:59:49 +0100850 if (err)
Miklos Szeredib8e42a62020-06-04 10:48:19 +0200851 return err;
Miklos Szerediab508822014-12-13 00:59:49 +0100852
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +0100853 err = ovl_check_namelen(path, ofs, name);
854 if (err)
Miklos Szeredib8e42a62020-06-04 10:48:19 +0200855 return err;
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +0100856
Miklos Szerediab508822014-12-13 00:59:49 +0100857 *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth);
858
Amir Goldstein02bcd152017-06-21 15:28:36 +0300859 /*
Amir Goldsteinf168f102018-01-19 11:26:53 +0200860 * The inodes index feature and NFS export need to encode and decode
861 * file handles, so they require that all layers support them.
Amir Goldstein02bcd152017-06-21 15:28:36 +0300862 */
Amir Goldsteine487d882017-11-07 13:55:04 +0200863 fh_type = ovl_can_decode_fh(path->dentry->d_sb);
Amir Goldsteinf168f102018-01-19 11:26:53 +0200864 if ((ofs->config.nfs_export ||
Amir Goldsteine487d882017-11-07 13:55:04 +0200865 (ofs->config.index && ofs->config.upperdir)) && !fh_type) {
Amir Goldstein02bcd152017-06-21 15:28:36 +0300866 ofs->config.index = false;
Amir Goldsteinf168f102018-01-19 11:26:53 +0200867 ofs->config.nfs_export = false;
lijiazi1bd0a3a2019-12-16 19:12:32 +0800868 pr_warn("fs on '%s' does not support file handles, falling back to index=off,nfs_export=off.\n",
Amir Goldsteinf168f102018-01-19 11:26:53 +0200869 name);
Amir Goldstein02bcd152017-06-21 15:28:36 +0300870 }
871
Amir Goldsteine487d882017-11-07 13:55:04 +0200872 /* Check if lower fs has 32bit inode numbers */
873 if (fh_type != FILEID_INO32_GEN)
Amir Goldstein0f831ec2019-11-16 18:14:41 +0200874 ofs->xino_mode = -1;
Amir Goldsteine487d882017-11-07 13:55:04 +0200875
Miklos Szerediab508822014-12-13 00:59:49 +0100876 return 0;
Miklos Szerediab508822014-12-13 00:59:49 +0100877}
878
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200879/* Workdir should not be subdir of upperdir and vice versa */
880static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
881{
882 bool ok = false;
883
884 if (workdir != upperdir) {
885 ok = (lock_rename(workdir, upperdir) == NULL);
886 unlock_rename(workdir, upperdir);
887 }
888 return ok;
889}
890
Miklos Szeredia78d9f02014-12-13 00:59:52 +0100891static unsigned int ovl_split_lowerdirs(char *str)
892{
893 unsigned int ctr = 1;
894 char *s, *d;
895
896 for (s = d = str;; s++, d++) {
897 if (*s == '\\') {
898 s++;
899 } else if (*s == ':') {
900 *d = '\0';
901 ctr++;
902 continue;
903 }
904 *d = *s;
905 if (!*s)
906 break;
907 }
908 return ctr;
909}
910
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +0200911static int __maybe_unused
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200912ovl_posix_acl_xattr_get(const struct xattr_handler *handler,
913 struct dentry *dentry, struct inode *inode,
914 const char *name, void *buffer, size_t size)
915{
Miklos Szeredi1d88f182017-07-20 11:08:21 +0200916 return ovl_xattr_get(dentry, inode, handler->name, buffer, size);
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200917}
918
919static int __maybe_unused
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +0200920ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
921 struct dentry *dentry, struct inode *inode,
922 const char *name, const void *value,
923 size_t size, int flags)
Miklos Szeredid837a492016-07-29 12:05:24 +0200924{
925 struct dentry *workdir = ovl_workdir(dentry);
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200926 struct inode *realinode = ovl_inode_real(inode);
Miklos Szeredid837a492016-07-29 12:05:24 +0200927 struct posix_acl *acl = NULL;
928 int err;
929
930 /* Check that everything is OK before copy-up */
931 if (value) {
932 acl = posix_acl_from_xattr(&init_user_ns, value, size);
933 if (IS_ERR(acl))
934 return PTR_ERR(acl);
935 }
936 err = -EOPNOTSUPP;
937 if (!IS_POSIXACL(d_inode(workdir)))
938 goto out_acl_release;
939 if (!realinode->i_op->set_acl)
940 goto out_acl_release;
941 if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) {
942 err = acl ? -EACCES : 0;
943 goto out_acl_release;
944 }
945 err = -EPERM;
946 if (!inode_owner_or_capable(inode))
947 goto out_acl_release;
948
949 posix_acl_release(acl);
950
Miklos Szeredifd3220d2016-10-31 14:42:14 +0100951 /*
952 * Check if sgid bit needs to be cleared (actual setacl operation will
953 * be done with mounter's capabilities and so that won't do it for us).
954 */
955 if (unlikely(inode->i_mode & S_ISGID) &&
956 handler->flags == ACL_TYPE_ACCESS &&
957 !in_group_p(inode->i_gid) &&
958 !capable_wrt_inode_uidgid(inode, CAP_FSETID)) {
959 struct iattr iattr = { .ia_valid = ATTR_KILL_SGID };
960
961 err = ovl_setattr(dentry, &iattr);
962 if (err)
963 return err;
964 }
965
Miklos Szeredi1d88f182017-07-20 11:08:21 +0200966 err = ovl_xattr_set(dentry, inode, handler->name, value, size, flags);
Miklos Szeredice315132016-09-01 11:12:00 +0200967 if (!err)
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200968 ovl_copyattr(ovl_inode_real(inode), inode);
Miklos Szeredice315132016-09-01 11:12:00 +0200969
970 return err;
Miklos Szeredid837a492016-07-29 12:05:24 +0200971
972out_acl_release:
973 posix_acl_release(acl);
974 return err;
975}
976
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200977static int ovl_own_xattr_get(const struct xattr_handler *handler,
978 struct dentry *dentry, struct inode *inode,
979 const char *name, void *buffer, size_t size)
980{
Amir Goldstein48fab5d2016-11-16 11:22:39 +0200981 return -EOPNOTSUPP;
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200982}
983
Miklos Szeredid837a492016-07-29 12:05:24 +0200984static int ovl_own_xattr_set(const struct xattr_handler *handler,
985 struct dentry *dentry, struct inode *inode,
986 const char *name, const void *value,
987 size_t size, int flags)
988{
Amir Goldstein48fab5d2016-11-16 11:22:39 +0200989 return -EOPNOTSUPP;
Miklos Szeredid837a492016-07-29 12:05:24 +0200990}
991
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200992static int ovl_other_xattr_get(const struct xattr_handler *handler,
993 struct dentry *dentry, struct inode *inode,
994 const char *name, void *buffer, size_t size)
995{
Miklos Szeredi1d88f182017-07-20 11:08:21 +0200996 return ovl_xattr_get(dentry, inode, name, buffer, size);
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200997}
998
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200999static int ovl_other_xattr_set(const struct xattr_handler *handler,
1000 struct dentry *dentry, struct inode *inode,
1001 const char *name, const void *value,
1002 size_t size, int flags)
1003{
Miklos Szeredi1d88f182017-07-20 11:08:21 +02001004 return ovl_xattr_set(dentry, inode, name, value, size, flags);
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +02001005}
1006
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +02001007static const struct xattr_handler __maybe_unused
1008ovl_posix_acl_access_xattr_handler = {
Miklos Szeredid837a492016-07-29 12:05:24 +02001009 .name = XATTR_NAME_POSIX_ACL_ACCESS,
1010 .flags = ACL_TYPE_ACCESS,
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +02001011 .get = ovl_posix_acl_xattr_get,
Miklos Szeredid837a492016-07-29 12:05:24 +02001012 .set = ovl_posix_acl_xattr_set,
1013};
1014
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +02001015static const struct xattr_handler __maybe_unused
1016ovl_posix_acl_default_xattr_handler = {
Miklos Szeredid837a492016-07-29 12:05:24 +02001017 .name = XATTR_NAME_POSIX_ACL_DEFAULT,
1018 .flags = ACL_TYPE_DEFAULT,
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +02001019 .get = ovl_posix_acl_xattr_get,
Miklos Szeredid837a492016-07-29 12:05:24 +02001020 .set = ovl_posix_acl_xattr_set,
1021};
1022
1023static const struct xattr_handler ovl_own_xattr_handler = {
1024 .prefix = OVL_XATTR_PREFIX,
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +02001025 .get = ovl_own_xattr_get,
Miklos Szeredid837a492016-07-29 12:05:24 +02001026 .set = ovl_own_xattr_set,
1027};
1028
1029static const struct xattr_handler ovl_other_xattr_handler = {
1030 .prefix = "", /* catch all */
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +02001031 .get = ovl_other_xattr_get,
Miklos Szeredid837a492016-07-29 12:05:24 +02001032 .set = ovl_other_xattr_set,
1033};
1034
1035static const struct xattr_handler *ovl_xattr_handlers[] = {
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +02001036#ifdef CONFIG_FS_POSIX_ACL
Miklos Szeredid837a492016-07-29 12:05:24 +02001037 &ovl_posix_acl_access_xattr_handler,
1038 &ovl_posix_acl_default_xattr_handler,
Andreas Gruenbacher0c97be22016-08-22 16:36:49 +02001039#endif
Miklos Szeredid837a492016-07-29 12:05:24 +02001040 &ovl_own_xattr_handler,
1041 &ovl_other_xattr_handler,
1042 NULL
1043};
1044
Amir Goldstein146d62e2019-04-18 17:42:08 +03001045static int ovl_setup_trap(struct super_block *sb, struct dentry *dir,
1046 struct inode **ptrap, const char *name)
1047{
1048 struct inode *trap;
1049 int err;
1050
1051 trap = ovl_get_trap_inode(sb, dir);
Arnd Bergmann1dac6f5b2019-06-17 14:39:29 +02001052 err = PTR_ERR_OR_ZERO(trap);
1053 if (err) {
Amir Goldstein146d62e2019-04-18 17:42:08 +03001054 if (err == -ELOOP)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001055 pr_err("conflicting %s path\n", name);
Amir Goldstein146d62e2019-04-18 17:42:08 +03001056 return err;
1057 }
1058
1059 *ptrap = trap;
1060 return 0;
1061}
1062
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001063/*
1064 * Determine how we treat concurrent use of upperdir/workdir based on the
1065 * index feature. This is papering over mount leaks of container runtimes,
1066 * for example, an old overlay mount is leaked and now its upperdir is
1067 * attempted to be used as a lower layer in a new overlay mount.
1068 */
1069static int ovl_report_in_use(struct ovl_fs *ofs, const char *name)
1070{
1071 if (ofs->config.index) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001072 pr_err("%s is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection.\n",
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001073 name);
1074 return -EBUSY;
1075 } else {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001076 pr_warn("%s is in-use as upperdir/workdir of another mount, accessing files from both mounts will result in undefined behavior.\n",
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001077 name);
1078 return 0;
1079 }
1080}
1081
Amir Goldstein146d62e2019-04-18 17:42:08 +03001082static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001083 struct ovl_layer *upper_layer, struct path *upperpath)
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001084{
Miklos Szeredi50649752017-11-10 09:39:15 +01001085 struct vfsmount *upper_mnt;
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001086 int err;
1087
Miklos Szerediad204482017-11-10 09:39:16 +01001088 err = ovl_mount_dir(ofs->config.upperdir, upperpath);
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001089 if (err)
1090 goto out;
1091
1092 /* Upper fs should not be r/o */
1093 if (sb_rdonly(upperpath->mnt->mnt_sb)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001094 pr_err("upper fs is r/o, try multi-lower layers mount\n");
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001095 err = -EINVAL;
1096 goto out;
1097 }
1098
Miklos Szerediad204482017-11-10 09:39:16 +01001099 err = ovl_check_namelen(upperpath, ofs, ofs->config.upperdir);
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001100 if (err)
1101 goto out;
1102
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001103 err = ovl_setup_trap(sb, upperpath->dentry, &upper_layer->trap,
Amir Goldstein146d62e2019-04-18 17:42:08 +03001104 "upperdir");
1105 if (err)
1106 goto out;
1107
Miklos Szeredi50649752017-11-10 09:39:15 +01001108 upper_mnt = clone_private_mount(upperpath);
1109 err = PTR_ERR(upper_mnt);
1110 if (IS_ERR(upper_mnt)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001111 pr_err("failed to clone upperpath\n");
Miklos Szeredi50649752017-11-10 09:39:15 +01001112 goto out;
1113 }
1114
1115 /* Don't inherit atime flags */
1116 upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME);
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001117 upper_layer->mnt = upper_mnt;
1118 upper_layer->idx = 0;
1119 upper_layer->fsid = 0;
Miklos Szeredi8c257412018-09-10 11:43:29 +02001120
Jeffle Xu654255f2020-04-23 19:06:55 +08001121 /*
1122 * Inherit SB_NOSEC flag from upperdir.
1123 *
1124 * This optimization changes behavior when a security related attribute
1125 * (suid/sgid/security.*) is changed on an underlying layer. This is
1126 * okay because we don't yet have guarantees in that case, but it will
1127 * need careful treatment once we want to honour changes to underlying
1128 * filesystems.
1129 */
1130 if (upper_mnt->mnt_sb->s_flags & SB_NOSEC)
1131 sb->s_flags |= SB_NOSEC;
1132
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001133 if (ovl_inuse_trylock(ovl_upper_mnt(ofs)->mnt_root)) {
Miklos Szeredi8c257412018-09-10 11:43:29 +02001134 ofs->upperdir_locked = true;
Miklos Szeredi8c257412018-09-10 11:43:29 +02001135 } else {
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001136 err = ovl_report_in_use(ofs, "upperdir");
1137 if (err)
1138 goto out;
Miklos Szeredi8c257412018-09-10 11:43:29 +02001139 }
1140
Miklos Szeredi6ee8acf2017-11-09 10:23:28 +01001141 err = 0;
1142out:
1143 return err;
1144}
1145
Amir Goldsteincad218a2020-02-20 09:00:19 +02001146/*
1147 * Returns 1 if RENAME_WHITEOUT is supported, 0 if not supported and
1148 * negative values if error is encountered.
1149 */
1150static int ovl_check_rename_whiteout(struct dentry *workdir)
1151{
1152 struct inode *dir = d_inode(workdir);
1153 struct dentry *temp;
1154 struct dentry *dest;
1155 struct dentry *whiteout;
1156 struct name_snapshot name;
1157 int err;
1158
1159 inode_lock_nested(dir, I_MUTEX_PARENT);
1160
1161 temp = ovl_create_temp(workdir, OVL_CATTR(S_IFREG | 0));
1162 err = PTR_ERR(temp);
1163 if (IS_ERR(temp))
1164 goto out_unlock;
1165
1166 dest = ovl_lookup_temp(workdir);
1167 err = PTR_ERR(dest);
1168 if (IS_ERR(dest)) {
1169 dput(temp);
1170 goto out_unlock;
1171 }
1172
1173 /* Name is inline and stable - using snapshot as a copy helper */
1174 take_dentry_name_snapshot(&name, temp);
1175 err = ovl_do_rename(dir, temp, dir, dest, RENAME_WHITEOUT);
1176 if (err) {
1177 if (err == -EINVAL)
1178 err = 0;
1179 goto cleanup_temp;
1180 }
1181
1182 whiteout = lookup_one_len(name.name.name, workdir, name.name.len);
1183 err = PTR_ERR(whiteout);
1184 if (IS_ERR(whiteout))
1185 goto cleanup_temp;
1186
1187 err = ovl_is_whiteout(whiteout);
1188
1189 /* Best effort cleanup of whiteout and temp file */
1190 if (err)
1191 ovl_cleanup(dir, whiteout);
1192 dput(whiteout);
1193
1194cleanup_temp:
1195 ovl_cleanup(dir, temp);
1196 release_dentry_name_snapshot(&name);
1197 dput(temp);
1198 dput(dest);
1199
1200out_unlock:
1201 inode_unlock(dir);
1202
1203 return err;
1204}
1205
Amir Goldstein146d62e2019-04-18 17:42:08 +03001206static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
1207 struct path *workpath)
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001208{
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001209 struct vfsmount *mnt = ovl_upper_mnt(ofs);
Amir Goldstein235ce9e2020-08-30 23:28:03 +03001210 struct dentry *temp, *workdir;
Amir Goldsteind80172c2020-02-20 09:03:08 +02001211 bool rename_whiteout;
1212 bool d_type;
Amir Goldsteine487d882017-11-07 13:55:04 +02001213 int fh_type;
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001214 int err;
1215
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001216 err = mnt_want_write(mnt);
1217 if (err)
1218 return err;
1219
Amir Goldstein235ce9e2020-08-30 23:28:03 +03001220 workdir = ovl_workdir_create(ofs, OVL_WORKDIR_NAME, false);
1221 err = PTR_ERR(workdir);
1222 if (IS_ERR_OR_NULL(workdir))
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001223 goto out;
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001224
Amir Goldstein235ce9e2020-08-30 23:28:03 +03001225 ofs->workdir = workdir;
1226
Amir Goldstein146d62e2019-04-18 17:42:08 +03001227 err = ovl_setup_trap(sb, ofs->workdir, &ofs->workdir_trap, "workdir");
1228 if (err)
1229 goto out;
1230
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001231 /*
1232 * Upper should support d_type, else whiteouts are visible. Given
1233 * workdir and upper are on same fs, we can do iterate_dir() on
1234 * workdir. This check requires successful creation of workdir in
1235 * previous step.
1236 */
1237 err = ovl_check_d_type_supported(workpath);
1238 if (err < 0)
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001239 goto out;
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001240
Amir Goldsteind80172c2020-02-20 09:03:08 +02001241 d_type = err;
1242 if (!d_type)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001243 pr_warn("upper fs needs to support d_type.\n");
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001244
1245 /* Check if upper/work fs supports O_TMPFILE */
Miklos Szerediad204482017-11-10 09:39:16 +01001246 temp = ovl_do_tmpfile(ofs->workdir, S_IFREG | 0);
1247 ofs->tmpfile = !IS_ERR(temp);
1248 if (ofs->tmpfile)
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001249 dput(temp);
1250 else
lijiazi1bd0a3a2019-12-16 19:12:32 +08001251 pr_warn("upper fs does not support tmpfile.\n");
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001252
Amir Goldsteincad218a2020-02-20 09:00:19 +02001253
1254 /* Check if upper/work fs supports RENAME_WHITEOUT */
1255 err = ovl_check_rename_whiteout(ofs->workdir);
1256 if (err < 0)
1257 goto out;
1258
Amir Goldsteind80172c2020-02-20 09:03:08 +02001259 rename_whiteout = err;
1260 if (!rename_whiteout)
Amir Goldsteincad218a2020-02-20 09:00:19 +02001261 pr_warn("upper fs does not support RENAME_WHITEOUT.\n");
1262
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001263 /*
1264 * Check if upper/work fs supports trusted.overlay.* xattr
1265 */
Miklos Szerediad204482017-11-10 09:39:16 +01001266 err = ovl_do_setxattr(ofs->workdir, OVL_XATTR_OPAQUE, "0", 1, 0);
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001267 if (err) {
Miklos Szerediad204482017-11-10 09:39:16 +01001268 ofs->noxattr = true;
Amir Goldsteina6837372017-09-19 12:14:18 +03001269 ofs->config.index = false;
Vivek Goyald5791042018-05-11 11:49:27 -04001270 ofs->config.metacopy = false;
lijiazi1bd0a3a2019-12-16 19:12:32 +08001271 pr_warn("upper fs does not support xattr, falling back to index=off and metacopy=off.\n");
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001272 err = 0;
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001273 } else {
Miklos Szerediad204482017-11-10 09:39:16 +01001274 vfs_removexattr(ofs->workdir, OVL_XATTR_OPAQUE);
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001275 }
1276
Amir Goldsteind80172c2020-02-20 09:03:08 +02001277 /*
1278 * We allowed sub-optimal upper fs configuration and don't want to break
1279 * users over kernel upgrade, but we never allowed remote upper fs, so
1280 * we can enforce strict requirements for remote upper fs.
1281 */
1282 if (ovl_dentry_remote(ofs->workdir) &&
1283 (!d_type || !rename_whiteout || ofs->noxattr)) {
1284 pr_err("upper fs missing required features.\n");
1285 err = -EINVAL;
1286 goto out;
1287 }
1288
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001289 /* Check if upper/work fs supports file handles */
Amir Goldsteine487d882017-11-07 13:55:04 +02001290 fh_type = ovl_can_decode_fh(ofs->workdir->d_sb);
1291 if (ofs->config.index && !fh_type) {
Miklos Szerediad204482017-11-10 09:39:16 +01001292 ofs->config.index = false;
lijiazi1bd0a3a2019-12-16 19:12:32 +08001293 pr_warn("upper fs does not support file handles, falling back to index=off.\n");
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001294 }
1295
Amir Goldsteine487d882017-11-07 13:55:04 +02001296 /* Check if upper fs has 32bit inode numbers */
1297 if (fh_type != FILEID_INO32_GEN)
Amir Goldstein0f831ec2019-11-16 18:14:41 +02001298 ofs->xino_mode = -1;
Amir Goldsteine487d882017-11-07 13:55:04 +02001299
Amir Goldsteinf168f102018-01-19 11:26:53 +02001300 /* NFS export of r/w mount depends on index */
1301 if (ofs->config.nfs_export && !ofs->config.index) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001302 pr_warn("NFS export requires \"index=on\", falling back to nfs_export=off.\n");
Amir Goldsteinf168f102018-01-19 11:26:53 +02001303 ofs->config.nfs_export = false;
1304 }
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001305out:
1306 mnt_drop_write(mnt);
1307 return err;
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001308}
1309
Amir Goldstein146d62e2019-04-18 17:42:08 +03001310static int ovl_get_workdir(struct super_block *sb, struct ovl_fs *ofs,
1311 struct path *upperpath)
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001312{
1313 int err;
Miklos Szeredibca44b52017-11-10 09:39:15 +01001314 struct path workpath = { };
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001315
Miklos Szerediad204482017-11-10 09:39:16 +01001316 err = ovl_mount_dir(ofs->config.workdir, &workpath);
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001317 if (err)
1318 goto out;
1319
1320 err = -EINVAL;
Miklos Szeredibca44b52017-11-10 09:39:15 +01001321 if (upperpath->mnt != workpath.mnt) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001322 pr_err("workdir and upperdir must reside under the same mount\n");
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001323 goto out;
1324 }
Miklos Szeredibca44b52017-11-10 09:39:15 +01001325 if (!ovl_workdir_ok(workpath.dentry, upperpath->dentry)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001326 pr_err("workdir and upperdir must be separate subtrees\n");
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001327 goto out;
1328 }
1329
Miklos Szeredi8c257412018-09-10 11:43:29 +02001330 ofs->workbasedir = dget(workpath.dentry);
1331
Miklos Szeredi8c257412018-09-10 11:43:29 +02001332 if (ovl_inuse_trylock(ofs->workbasedir)) {
Miklos Szerediad204482017-11-10 09:39:16 +01001333 ofs->workdir_locked = true;
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001334 } else {
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001335 err = ovl_report_in_use(ofs, "workdir");
1336 if (err)
1337 goto out;
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001338 }
1339
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001340 err = ovl_setup_trap(sb, ofs->workbasedir, &ofs->workbasedir_trap,
1341 "workdir");
1342 if (err)
1343 goto out;
1344
Amir Goldstein146d62e2019-04-18 17:42:08 +03001345 err = ovl_make_workdir(sb, ofs, &workpath);
Miklos Szeredibca44b52017-11-10 09:39:15 +01001346
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001347out:
Miklos Szeredibca44b52017-11-10 09:39:15 +01001348 path_put(&workpath);
1349
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001350 return err;
1351}
1352
Amir Goldstein146d62e2019-04-18 17:42:08 +03001353static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
1354 struct ovl_entry *oe, struct path *upperpath)
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001355{
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001356 struct vfsmount *mnt = ovl_upper_mnt(ofs);
Amir Goldstein235ce9e2020-08-30 23:28:03 +03001357 struct dentry *indexdir;
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001358 int err;
1359
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001360 err = mnt_want_write(mnt);
1361 if (err)
1362 return err;
1363
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001364 /* Verify lower root is upper root origin */
Amir Goldsteind9768072017-09-24 13:00:19 +03001365 err = ovl_verify_origin(upperpath->dentry, oe->lowerstack[0].dentry,
Amir Goldstein05122442018-01-11 08:25:32 +02001366 true);
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001367 if (err) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001368 pr_err("failed to verify upper root origin\n");
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001369 goto out;
1370 }
1371
Amir Goldstein470c1562020-07-13 17:19:43 +03001372 /* index dir will act also as workdir */
1373 iput(ofs->workdir_trap);
1374 ofs->workdir_trap = NULL;
1375 dput(ofs->workdir);
1376 ofs->workdir = NULL;
Amir Goldstein235ce9e2020-08-30 23:28:03 +03001377 indexdir = ovl_workdir_create(ofs, OVL_INDEXDIR_NAME, true);
1378 if (IS_ERR(indexdir)) {
1379 err = PTR_ERR(indexdir);
1380 } else if (indexdir) {
1381 ofs->indexdir = indexdir;
1382 ofs->workdir = dget(indexdir);
Amir Goldstein20396362020-06-21 09:37:59 +03001383
Amir Goldstein146d62e2019-04-18 17:42:08 +03001384 err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,
1385 "indexdir");
1386 if (err)
1387 goto out;
1388
Amir Goldsteinad1d6152018-01-11 10:47:03 +02001389 /*
1390 * Verify upper root is exclusively associated with index dir.
1391 * Older kernels stored upper fh in "trusted.overlay.origin"
1392 * xattr. If that xattr exists, verify that it is a match to
1393 * upper dir file handle. In any case, verify or set xattr
1394 * "trusted.overlay.upper" to indicate that index may have
1395 * directory entries.
1396 */
1397 if (ovl_check_origin_xattr(ofs->indexdir)) {
1398 err = ovl_verify_set_fh(ofs->indexdir, OVL_XATTR_ORIGIN,
1399 upperpath->dentry, true, false);
1400 if (err)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001401 pr_err("failed to verify index dir 'origin' xattr\n");
Amir Goldsteinad1d6152018-01-11 10:47:03 +02001402 }
1403 err = ovl_verify_upper(ofs->indexdir, upperpath->dentry, true);
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001404 if (err)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001405 pr_err("failed to verify index dir 'upper' xattr\n");
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001406
1407 /* Cleanup bad/stale/orphan index entries */
1408 if (!err)
Amir Goldstein1eff1a12017-12-12 22:40:46 +02001409 err = ovl_indexdir_cleanup(ofs);
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001410 }
Miklos Szerediad204482017-11-10 09:39:16 +01001411 if (err || !ofs->indexdir)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001412 pr_warn("try deleting index dir or mounting with '-o index=off' to disable inodes index.\n");
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001413
1414out:
Amir Goldstein2ba9d572018-01-03 18:54:41 +02001415 mnt_drop_write(mnt);
Miklos Szeredif7e3a7d2017-11-09 10:23:28 +01001416 return err;
1417}
1418
Amir Goldstein9df085f2018-09-03 09:12:09 +03001419static bool ovl_lower_uuid_ok(struct ovl_fs *ofs, const uuid_t *uuid)
Amir Goldstein51486262018-03-28 20:22:41 +03001420{
1421 unsigned int i;
Amir Goldstein9df085f2018-09-03 09:12:09 +03001422
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001423 if (!ofs->config.nfs_export && !ovl_upper_mnt(ofs))
Amir Goldstein9df085f2018-09-03 09:12:09 +03001424 return true;
1425
Amir Goldsteina888db32020-07-08 16:16:13 +03001426 /*
1427 * We allow using single lower with null uuid for index and nfs_export
1428 * for example to support those features with single lower squashfs.
1429 * To avoid regressions in setups of overlay with re-formatted lower
1430 * squashfs, do not allow decoding origin with lower null uuid unless
1431 * user opted-in to one of the new features that require following the
1432 * lower inode of non-dir upper.
1433 */
1434 if (!ofs->config.index && !ofs->config.metacopy && !ofs->config.xino &&
1435 uuid_is_null(uuid))
1436 return false;
1437
Amir Goldstein1b81ddd2019-11-16 18:52:20 +02001438 for (i = 0; i < ofs->numfs; i++) {
Amir Goldstein9df085f2018-09-03 09:12:09 +03001439 /*
1440 * We use uuid to associate an overlay lower file handle with a
1441 * lower layer, so we can accept lower fs with null uuid as long
1442 * as all lower layers with null uuid are on the same fs.
Amir Goldstein7e63c872019-11-14 22:28:41 +02001443 * if we detect multiple lower fs with the same uuid, we
1444 * disable lower file handle decoding on all of them.
Amir Goldstein9df085f2018-09-03 09:12:09 +03001445 */
Amir Goldstein1b81ddd2019-11-16 18:52:20 +02001446 if (ofs->fs[i].is_lower &&
1447 uuid_equal(&ofs->fs[i].sb->s_uuid, uuid)) {
Amir Goldstein07f1e592020-01-14 21:59:22 +02001448 ofs->fs[i].bad_uuid = true;
Amir Goldstein9df085f2018-09-03 09:12:09 +03001449 return false;
Amir Goldstein7e63c872019-11-14 22:28:41 +02001450 }
Amir Goldstein9df085f2018-09-03 09:12:09 +03001451 }
1452 return true;
1453}
1454
1455/* Get a unique fsid for the layer */
1456static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
1457{
1458 struct super_block *sb = path->mnt->mnt_sb;
1459 unsigned int i;
Amir Goldstein51486262018-03-28 20:22:41 +03001460 dev_t dev;
1461 int err;
Amir Goldstein7e63c872019-11-14 22:28:41 +02001462 bool bad_uuid = false;
Amir Goldstein51486262018-03-28 20:22:41 +03001463
Amir Goldstein07f1e592020-01-14 21:59:22 +02001464 for (i = 0; i < ofs->numfs; i++) {
1465 if (ofs->fs[i].sb == sb)
1466 return i;
Amir Goldstein51486262018-03-28 20:22:41 +03001467 }
1468
Amir Goldstein9df085f2018-09-03 09:12:09 +03001469 if (!ovl_lower_uuid_ok(ofs, &sb->s_uuid)) {
Amir Goldstein7e63c872019-11-14 22:28:41 +02001470 bad_uuid = true;
1471 if (ofs->config.index || ofs->config.nfs_export) {
1472 ofs->config.index = false;
1473 ofs->config.nfs_export = false;
lijiazi1bd0a3a2019-12-16 19:12:32 +08001474 pr_warn("%s uuid detected in lower fs '%pd2', falling back to index=off,nfs_export=off.\n",
Amir Goldstein7e63c872019-11-14 22:28:41 +02001475 uuid_is_null(&sb->s_uuid) ? "null" :
1476 "conflicting",
1477 path->dentry);
1478 }
Amir Goldstein9df085f2018-09-03 09:12:09 +03001479 }
1480
Amir Goldstein51486262018-03-28 20:22:41 +03001481 err = get_anon_bdev(&dev);
1482 if (err) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001483 pr_err("failed to get anonymous bdev for lowerpath\n");
Amir Goldstein51486262018-03-28 20:22:41 +03001484 return err;
1485 }
1486
Amir Goldstein07f1e592020-01-14 21:59:22 +02001487 ofs->fs[ofs->numfs].sb = sb;
1488 ofs->fs[ofs->numfs].pseudo_dev = dev;
1489 ofs->fs[ofs->numfs].bad_uuid = bad_uuid;
Amir Goldstein51486262018-03-28 20:22:41 +03001490
Amir Goldstein07f1e592020-01-14 21:59:22 +02001491 return ofs->numfs++;
Amir Goldstein51486262018-03-28 20:22:41 +03001492}
1493
Amir Goldstein94375f92019-11-15 14:12:40 +02001494static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001495 struct path *stack, unsigned int numlower,
1496 struct ovl_layer *layers)
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001497{
1498 int err;
1499 unsigned int i;
1500
1501 err = -ENOMEM;
Amir Goldstein07f1e592020-01-14 21:59:22 +02001502 ofs->fs = kcalloc(numlower + 1, sizeof(struct ovl_sb), GFP_KERNEL);
1503 if (ofs->fs == NULL)
Amir Goldstein51486262018-03-28 20:22:41 +03001504 goto out;
1505
Amir Goldstein07f1e592020-01-14 21:59:22 +02001506 /* idx/fsid 0 are reserved for upper fs even with lower only overlay */
1507 ofs->numfs++;
1508
Amir Goldstein07f1e592020-01-14 21:59:22 +02001509 /*
Amir Goldsteinb7bf9902020-01-14 22:17:25 +02001510 * All lower layers that share the same fs as upper layer, use the same
1511 * pseudo_dev as upper layer. Allocate fs[0].pseudo_dev even for lower
1512 * only overlay to simplify ovl_fs_free().
Amir Goldstein1b81ddd2019-11-16 18:52:20 +02001513 * is_lower will be set if upper fs is shared with a lower layer.
Amir Goldstein07f1e592020-01-14 21:59:22 +02001514 */
Amir Goldsteinb7bf9902020-01-14 22:17:25 +02001515 err = get_anon_bdev(&ofs->fs[0].pseudo_dev);
1516 if (err) {
1517 pr_err("failed to get anonymous bdev for upper fs\n");
1518 goto out;
1519 }
1520
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001521 if (ovl_upper_mnt(ofs)) {
1522 ofs->fs[0].sb = ovl_upper_mnt(ofs)->mnt_sb;
Amir Goldstein1b81ddd2019-11-16 18:52:20 +02001523 ofs->fs[0].is_lower = false;
Amir Goldstein07f1e592020-01-14 21:59:22 +02001524 }
1525
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001526 for (i = 0; i < numlower; i++) {
1527 struct vfsmount *mnt;
Amir Goldstein146d62e2019-04-18 17:42:08 +03001528 struct inode *trap;
Amir Goldstein51486262018-03-28 20:22:41 +03001529 int fsid;
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001530
Amir Goldstein9df085f2018-09-03 09:12:09 +03001531 err = fsid = ovl_get_fsid(ofs, &stack[i]);
Amir Goldstein51486262018-03-28 20:22:41 +03001532 if (err < 0)
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001533 goto out;
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001534
youngjun24f14002020-06-16 17:30:43 +09001535 /*
1536 * Check if lower root conflicts with this overlay layers before
1537 * checking if it is in-use as upperdir/workdir of "another"
1538 * mount, because we do not bother to check in ovl_is_inuse() if
1539 * the upperdir/workdir is in fact in-use by our
1540 * upperdir/workdir.
1541 */
Amir Goldstein146d62e2019-04-18 17:42:08 +03001542 err = ovl_setup_trap(sb, stack[i].dentry, &trap, "lowerdir");
1543 if (err)
1544 goto out;
1545
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001546 if (ovl_is_inuse(stack[i].dentry)) {
1547 err = ovl_report_in_use(ofs, "lowerdir");
youngjun24f14002020-06-16 17:30:43 +09001548 if (err) {
1549 iput(trap);
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001550 goto out;
youngjun24f14002020-06-16 17:30:43 +09001551 }
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001552 }
1553
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001554 mnt = clone_private_mount(&stack[i]);
1555 err = PTR_ERR(mnt);
1556 if (IS_ERR(mnt)) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001557 pr_err("failed to clone lowerpath\n");
Amir Goldstein146d62e2019-04-18 17:42:08 +03001558 iput(trap);
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001559 goto out;
1560 }
Amir Goldstein51486262018-03-28 20:22:41 +03001561
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001562 /*
1563 * Make lower layers R/O. That way fchmod/fchown on lower file
1564 * will fail instead of modifying lower fs.
1565 */
1566 mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME;
1567
Miklos Szeredi13464162020-01-24 09:46:45 +01001568 layers[ofs->numlayer].trap = trap;
1569 layers[ofs->numlayer].mnt = mnt;
1570 layers[ofs->numlayer].idx = ofs->numlayer;
1571 layers[ofs->numlayer].fsid = fsid;
1572 layers[ofs->numlayer].fs = &ofs->fs[fsid];
Amir Goldstein94375f92019-11-15 14:12:40 +02001573 ofs->numlayer++;
Amir Goldstein1b81ddd2019-11-16 18:52:20 +02001574 ofs->fs[fsid].is_lower = true;
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001575 }
Amir Goldsteine487d882017-11-07 13:55:04 +02001576
Amir Goldstein795939a2018-03-29 09:08:18 +03001577 /*
1578 * When all layers on same fs, overlay can use real inode numbers.
Amir Goldstein926e94d2020-02-21 16:34:45 +02001579 * With mount option "xino=<on|auto>", mounter declares that there are
1580 * enough free high bits in underlying fs to hold the unique fsid.
Amir Goldstein795939a2018-03-29 09:08:18 +03001581 * If overlayfs does encounter underlying inodes using the high xino
1582 * bits reserved for fsid, it emits a warning and uses the original
Amir Goldsteindfe51d42020-02-21 16:34:44 +02001583 * inode number or a non persistent inode number allocated from a
1584 * dedicated range.
Amir Goldstein795939a2018-03-29 09:08:18 +03001585 */
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001586 if (ofs->numfs - !ovl_upper_mnt(ofs) == 1) {
Amir Goldstein0f831ec2019-11-16 18:14:41 +02001587 if (ofs->config.xino == OVL_XINO_ON)
1588 pr_info("\"xino=on\" is useless with all layers on same fs, ignore.\n");
1589 ofs->xino_mode = 0;
Amir Goldstein53afcd32020-02-21 16:34:42 +02001590 } else if (ofs->config.xino == OVL_XINO_OFF) {
1591 ofs->xino_mode = -1;
Amir Goldstein926e94d2020-02-21 16:34:45 +02001592 } else if (ofs->xino_mode < 0) {
Amir Goldstein795939a2018-03-29 09:08:18 +03001593 /*
Amir Goldstein07f1e592020-01-14 21:59:22 +02001594 * This is a roundup of number of bits needed for encoding
Amir Goldsteindfe51d42020-02-21 16:34:44 +02001595 * fsid, where fsid 0 is reserved for upper fs (even with
1596 * lower only overlay) +1 extra bit is reserved for the non
1597 * persistent inode number range that is used for resolving
1598 * xino lower bits overflow.
Amir Goldstein795939a2018-03-29 09:08:18 +03001599 */
Amir Goldsteindfe51d42020-02-21 16:34:44 +02001600 BUILD_BUG_ON(ilog2(OVL_MAX_STACK) > 30);
1601 ofs->xino_mode = ilog2(ofs->numfs - 1) + 2;
Amir Goldstein795939a2018-03-29 09:08:18 +03001602 }
1603
Amir Goldstein0f831ec2019-11-16 18:14:41 +02001604 if (ofs->xino_mode > 0) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001605 pr_info("\"xino\" feature enabled using %d upper inode bits.\n",
Amir Goldstein0f831ec2019-11-16 18:14:41 +02001606 ofs->xino_mode);
Amir Goldstein795939a2018-03-29 09:08:18 +03001607 }
Amir Goldsteine487d882017-11-07 13:55:04 +02001608
Miklos Szeredi520d7c82017-11-10 09:39:15 +01001609 err = 0;
1610out:
1611 return err;
1612}
1613
Miklos Szeredi4155c102017-11-10 09:39:15 +01001614static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001615 const char *lower, unsigned int numlower,
1616 struct ovl_fs *ofs, struct ovl_layer *layers)
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001617{
1618 int err;
Miklos Szeredi4155c102017-11-10 09:39:15 +01001619 struct path *stack = NULL;
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001620 unsigned int i;
Miklos Szeredi4155c102017-11-10 09:39:15 +01001621 struct ovl_entry *oe;
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001622
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001623 if (!ofs->config.upperdir && numlower == 1) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001624 pr_err("at least 2 lowerdir are needed while upperdir nonexistent\n");
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001625 return ERR_PTR(-EINVAL);
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001626 }
1627
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001628 stack = kcalloc(numlower, sizeof(struct path), GFP_KERNEL);
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001629 if (!stack)
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001630 return ERR_PTR(-ENOMEM);
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001631
1632 err = -EINVAL;
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001633 for (i = 0; i < numlower; i++) {
1634 err = ovl_lower_dir(lower, &stack[i], ofs, &sb->s_stack_depth);
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001635 if (err)
Miklos Szeredi4155c102017-11-10 09:39:15 +01001636 goto out_err;
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001637
1638 lower = strchr(lower, '\0') + 1;
1639 }
1640
1641 err = -EINVAL;
1642 sb->s_stack_depth++;
1643 if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001644 pr_err("maximum fs stacking depth exceeded\n");
Miklos Szeredi4155c102017-11-10 09:39:15 +01001645 goto out_err;
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001646 }
1647
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001648 err = ovl_get_layers(sb, ofs, stack, numlower, layers);
Miklos Szeredi4155c102017-11-10 09:39:15 +01001649 if (err)
1650 goto out_err;
1651
1652 err = -ENOMEM;
1653 oe = ovl_alloc_entry(numlower);
1654 if (!oe)
1655 goto out_err;
1656
1657 for (i = 0; i < numlower; i++) {
1658 oe->lowerstack[i].dentry = dget(stack[i].dentry);
Amir Goldstein94375f92019-11-15 14:12:40 +02001659 oe->lowerstack[i].layer = &ofs->layers[i+1];
Miklos Szeredi4155c102017-11-10 09:39:15 +01001660 }
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001661
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001662out:
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001663 for (i = 0; i < numlower; i++)
1664 path_put(&stack[i]);
1665 kfree(stack);
Miklos Szeredi4155c102017-11-10 09:39:15 +01001666
1667 return oe;
1668
1669out_err:
1670 oe = ERR_PTR(err);
Miklos Szeredi53dbb0b2017-11-09 10:23:28 +01001671 goto out;
1672}
1673
Amir Goldstein146d62e2019-04-18 17:42:08 +03001674/*
1675 * Check if this layer root is a descendant of:
1676 * - another layer of this overlayfs instance
1677 * - upper/work dir of any overlayfs instance
Amir Goldstein146d62e2019-04-18 17:42:08 +03001678 */
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001679static int ovl_check_layer(struct super_block *sb, struct ovl_fs *ofs,
1680 struct dentry *dentry, const char *name)
Amir Goldstein146d62e2019-04-18 17:42:08 +03001681{
Miklos Szeredi9179c21d2019-06-18 15:06:16 +02001682 struct dentry *next = dentry, *parent;
Amir Goldstein146d62e2019-04-18 17:42:08 +03001683 int err = 0;
1684
Miklos Szeredi9179c21d2019-06-18 15:06:16 +02001685 if (!dentry)
Amir Goldstein146d62e2019-04-18 17:42:08 +03001686 return 0;
1687
Miklos Szeredi9179c21d2019-06-18 15:06:16 +02001688 parent = dget_parent(next);
1689
1690 /* Walk back ancestors to root (inclusive) looking for traps */
1691 while (!err && parent != next) {
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001692 if (ovl_lookup_trap_inode(sb, parent)) {
Amir Goldstein146d62e2019-04-18 17:42:08 +03001693 err = -ELOOP;
lijiazi1bd0a3a2019-12-16 19:12:32 +08001694 pr_err("overlapping %s path\n", name);
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001695 } else if (ovl_is_inuse(parent)) {
1696 err = ovl_report_in_use(ofs, name);
Amir Goldstein146d62e2019-04-18 17:42:08 +03001697 }
Amir Goldstein146d62e2019-04-18 17:42:08 +03001698 next = parent;
Miklos Szeredi9179c21d2019-06-18 15:06:16 +02001699 parent = dget_parent(next);
1700 dput(next);
Amir Goldstein146d62e2019-04-18 17:42:08 +03001701 }
1702
Miklos Szeredi9179c21d2019-06-18 15:06:16 +02001703 dput(parent);
Amir Goldstein146d62e2019-04-18 17:42:08 +03001704
1705 return err;
1706}
1707
1708/*
1709 * Check if any of the layers or work dirs overlap.
1710 */
1711static int ovl_check_overlapping_layers(struct super_block *sb,
1712 struct ovl_fs *ofs)
1713{
1714 int i, err;
1715
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001716 if (ovl_upper_mnt(ofs)) {
1717 err = ovl_check_layer(sb, ofs, ovl_upper_mnt(ofs)->mnt_root,
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001718 "upperdir");
Amir Goldstein146d62e2019-04-18 17:42:08 +03001719 if (err)
1720 return err;
1721
1722 /*
1723 * Checking workbasedir avoids hitting ovl_is_inuse(parent) of
1724 * this instance and covers overlapping work and index dirs,
1725 * unless work or index dir have been moved since created inside
1726 * workbasedir. In that case, we already have their traps in
1727 * inode cache and we will catch that case on lookup.
1728 */
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001729 err = ovl_check_layer(sb, ofs, ofs->workbasedir, "workdir");
Amir Goldstein146d62e2019-04-18 17:42:08 +03001730 if (err)
1731 return err;
1732 }
1733
Amir Goldstein94375f92019-11-15 14:12:40 +02001734 for (i = 1; i < ofs->numlayer; i++) {
Amir Goldstein0be0bfd2019-07-12 15:24:34 +03001735 err = ovl_check_layer(sb, ofs,
Amir Goldstein94375f92019-11-15 14:12:40 +02001736 ofs->layers[i].mnt->mnt_root,
Amir Goldstein146d62e2019-04-18 17:42:08 +03001737 "lowerdir");
1738 if (err)
1739 return err;
1740 }
1741
1742 return 0;
1743}
1744
Amir Goldstein2effc5c2019-11-19 17:49:17 +02001745static struct dentry *ovl_get_root(struct super_block *sb,
1746 struct dentry *upperdentry,
1747 struct ovl_entry *oe)
1748{
1749 struct dentry *root;
Amir Goldstein62c832e2019-11-19 15:31:46 +02001750 struct ovl_path *lowerpath = &oe->lowerstack[0];
1751 unsigned long ino = d_inode(lowerpath->dentry)->i_ino;
1752 int fsid = lowerpath->layer->fsid;
1753 struct ovl_inode_params oip = {
1754 .upperdentry = upperdentry,
1755 .lowerpath = lowerpath,
1756 };
Amir Goldstein2effc5c2019-11-19 17:49:17 +02001757
1758 root = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
1759 if (!root)
1760 return NULL;
1761
1762 root->d_fsdata = oe;
1763
1764 if (upperdentry) {
Amir Goldstein62c832e2019-11-19 15:31:46 +02001765 /* Root inode uses upper st_ino/i_ino */
1766 ino = d_inode(upperdentry)->i_ino;
1767 fsid = 0;
Amir Goldstein2effc5c2019-11-19 17:49:17 +02001768 ovl_dentry_set_upper_alias(root);
1769 if (ovl_is_impuredir(upperdentry))
1770 ovl_set_flag(OVL_IMPURE, d_inode(root));
1771 }
1772
1773 /* Root is always merge -> can have whiteouts */
1774 ovl_set_flag(OVL_WHITEOUTS, d_inode(root));
1775 ovl_dentry_set_flag(OVL_E_CONNECTED, root);
1776 ovl_set_upperdata(d_inode(root));
Amir Goldstein62c832e2019-11-19 15:31:46 +02001777 ovl_inode_init(d_inode(root), &oip, ino, fsid);
Miklos Szeredif4288842020-03-17 15:04:22 +01001778 ovl_dentry_update_reval(root, upperdentry, DCACHE_OP_WEAK_REVALIDATE);
Amir Goldstein2effc5c2019-11-19 17:49:17 +02001779
1780 return root;
1781}
1782
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001783static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1784{
Kees Cook33006cd2017-03-29 14:02:19 -07001785 struct path upperpath = { };
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001786 struct dentry *root_dentry;
Miklos Szeredi4155c102017-11-10 09:39:15 +01001787 struct ovl_entry *oe;
Miklos Szerediad204482017-11-10 09:39:16 +01001788 struct ovl_fs *ofs;
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001789 struct ovl_layer *layers;
Konstantin Khlebnikov51f8f3c2017-01-10 21:30:21 +03001790 struct cred *cred;
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001791 char *splitlower = NULL;
1792 unsigned int numlower;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001793 int err;
1794
Miklos Szeredif4288842020-03-17 15:04:22 +01001795 sb->s_d_op = &ovl_dentry_operations;
1796
Erez Zadokf45827e82014-10-24 00:14:38 +02001797 err = -ENOMEM;
Miklos Szerediad204482017-11-10 09:39:16 +01001798 ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL);
1799 if (!ofs)
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001800 goto out;
1801
Miklos Szerediad204482017-11-10 09:39:16 +01001802 ofs->creator_cred = cred = prepare_creds();
Miklos Szeredic6fe6252017-11-10 09:39:15 +01001803 if (!cred)
1804 goto out_err;
1805
Chengguang Xuc21c8392020-04-24 10:55:17 +08001806 /* Is there a reason anyone would want not to share whiteouts? */
1807 ofs->share_whiteout = true;
1808
Miklos Szerediad204482017-11-10 09:39:16 +01001809 ofs->config.index = ovl_index_def;
Amir Goldsteinf168f102018-01-19 11:26:53 +02001810 ofs->config.nfs_export = ovl_nfs_export_def;
Amir Goldstein795939a2018-03-29 09:08:18 +03001811 ofs->config.xino = ovl_xino_def();
Vivek Goyald5791042018-05-11 11:49:27 -04001812 ofs->config.metacopy = ovl_metacopy_def;
Miklos Szerediad204482017-11-10 09:39:16 +01001813 err = ovl_parse_opt((char *) data, &ofs->config);
Erez Zadokf45827e82014-10-24 00:14:38 +02001814 if (err)
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001815 goto out_err;
Erez Zadokf45827e82014-10-24 00:14:38 +02001816
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001817 err = -EINVAL;
Miklos Szerediad204482017-11-10 09:39:16 +01001818 if (!ofs->config.lowerdir) {
Konstantin Khlebnikov07f2af72015-06-29 20:18:56 +03001819 if (!silent)
lijiazi1bd0a3a2019-12-16 19:12:32 +08001820 pr_err("missing 'lowerdir'\n");
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001821 goto out_err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001822 }
1823
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001824 err = -ENOMEM;
1825 splitlower = kstrdup(ofs->config.lowerdir, GFP_KERNEL);
1826 if (!splitlower)
1827 goto out_err;
1828
1829 numlower = ovl_split_lowerdirs(splitlower);
1830 if (numlower > OVL_MAX_STACK) {
1831 pr_err("too many lower directories, limit is %d\n",
1832 OVL_MAX_STACK);
1833 goto out_err;
1834 }
1835
1836 layers = kcalloc(numlower + 1, sizeof(struct ovl_layer), GFP_KERNEL);
1837 if (!layers)
1838 goto out_err;
1839
1840 ofs->layers = layers;
1841 /* Layer 0 is reserved for upper even if there's no upper */
1842 ofs->numlayer = 1;
1843
Miklos Szeredi53a08cb2014-12-13 00:59:51 +01001844 sb->s_stack_depth = 0;
Miklos Szeredicf9a6782015-12-11 16:30:49 +01001845 sb->s_maxbytes = MAX_LFS_FILESIZE;
Amir Goldstein4d314f72020-02-21 16:34:43 +02001846 atomic_long_set(&ofs->last_ino, 1);
Amir Goldsteine487d882017-11-07 13:55:04 +02001847 /* Assume underlaying fs uses 32bit inodes unless proven otherwise */
Amir Goldstein53afcd32020-02-21 16:34:42 +02001848 if (ofs->config.xino != OVL_XINO_OFF) {
Amir Goldstein0f831ec2019-11-16 18:14:41 +02001849 ofs->xino_mode = BITS_PER_LONG - 32;
Amir Goldstein53afcd32020-02-21 16:34:42 +02001850 if (!ofs->xino_mode) {
1851 pr_warn("xino not supported on 32bit kernel, falling back to xino=off.\n");
1852 ofs->config.xino = OVL_XINO_OFF;
1853 }
1854 }
Amir Goldstein795939a2018-03-29 09:08:18 +03001855
Amir Goldstein146d62e2019-04-18 17:42:08 +03001856 /* alloc/destroy_inode needed for setting up traps in inode cache */
1857 sb->s_op = &ovl_super_operations;
1858
Miklos Szerediad204482017-11-10 09:39:16 +01001859 if (ofs->config.upperdir) {
1860 if (!ofs->config.workdir) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001861 pr_err("missing 'workdir'\n");
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001862 goto out_err;
Miklos Szeredi53a08cb2014-12-13 00:59:51 +01001863 }
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001864
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001865 err = ovl_get_upper(sb, ofs, &layers[0], &upperpath);
Miklos Szeredi21a3b312017-11-09 10:23:28 +01001866 if (err)
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001867 goto out_err;
Miklos Szeredid719e8f2016-07-29 12:05:23 +02001868
Amir Goldstein146d62e2019-04-18 17:42:08 +03001869 err = ovl_get_workdir(sb, ofs, &upperpath);
Miklos Szeredi8ed61dc2017-11-09 10:23:28 +01001870 if (err)
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001871 goto out_err;
Miklos Szeredic6fe6252017-11-10 09:39:15 +01001872
Miklos Szerediad204482017-11-10 09:39:16 +01001873 if (!ofs->workdir)
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001874 sb->s_flags |= SB_RDONLY;
Miklos Szeredi6e882562017-11-10 09:39:15 +01001875
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001876 sb->s_stack_depth = ovl_upper_mnt(ofs)->mnt_sb->s_stack_depth;
1877 sb->s_time_gran = ovl_upper_mnt(ofs)->mnt_sb->s_time_gran;
Miklos Szeredic6fe6252017-11-10 09:39:15 +01001878
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001879 }
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001880 oe = ovl_get_lowerstack(sb, splitlower, numlower, ofs, layers);
Miklos Szeredi4155c102017-11-10 09:39:15 +01001881 err = PTR_ERR(oe);
1882 if (IS_ERR(oe))
Miklos Szeredia9075cd2017-11-10 09:39:15 +01001883 goto out_err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001884
hujianyang71cbad72015-01-15 13:20:57 +08001885 /* If the upper fs is nonexistent, we mark overlayfs r/o too */
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001886 if (!ovl_upper_mnt(ofs))
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001887 sb->s_flags |= SB_RDONLY;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001888
Amir Goldstein470c1562020-07-13 17:19:43 +03001889 if (!ovl_force_readonly(ofs) && ofs->config.index) {
Amir Goldstein146d62e2019-04-18 17:42:08 +03001890 err = ovl_get_indexdir(sb, ofs, oe, &upperpath);
Amir Goldstein54fb3472017-06-21 15:28:38 +03001891 if (err)
Miklos Szeredi4155c102017-11-10 09:39:15 +01001892 goto out_free_oe;
Miklos Szeredi6e882562017-11-10 09:39:15 +01001893
Amir Goldstein972d0092017-09-19 12:14:18 +03001894 /* Force r/o mount with no index dir */
Amir Goldstein20396362020-06-21 09:37:59 +03001895 if (!ofs->indexdir)
Linus Torvalds1751e8a2017-11-27 13:05:09 -08001896 sb->s_flags |= SB_RDONLY;
Amir Goldstein02bcd152017-06-21 15:28:36 +03001897 }
1898
Amir Goldstein146d62e2019-04-18 17:42:08 +03001899 err = ovl_check_overlapping_layers(sb, ofs);
1900 if (err)
1901 goto out_free_oe;
1902
Amir Goldstein972d0092017-09-19 12:14:18 +03001903 /* Show index=off in /proc/mounts for forced r/o mount */
Amir Goldsteinf168f102018-01-19 11:26:53 +02001904 if (!ofs->indexdir) {
Miklos Szerediad204482017-11-10 09:39:16 +01001905 ofs->config.index = false;
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +02001906 if (ovl_upper_mnt(ofs) && ofs->config.nfs_export) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001907 pr_warn("NFS export requires an index dir, falling back to nfs_export=off.\n");
Amir Goldsteinf168f102018-01-19 11:26:53 +02001908 ofs->config.nfs_export = false;
1909 }
1910 }
Amir Goldstein02bcd152017-06-21 15:28:36 +03001911
Vivek Goyald5791042018-05-11 11:49:27 -04001912 if (ofs->config.metacopy && ofs->config.nfs_export) {
lijiazi1bd0a3a2019-12-16 19:12:32 +08001913 pr_warn("NFS export is not supported with metadata only copy up, falling back to nfs_export=off.\n");
Vivek Goyald5791042018-05-11 11:49:27 -04001914 ofs->config.nfs_export = false;
1915 }
1916
Amir Goldstein8383f172017-10-02 11:31:42 +03001917 if (ofs->config.nfs_export)
1918 sb->s_export_op = &ovl_export_operations;
1919
Konstantin Khlebnikov51f8f3c2017-01-10 21:30:21 +03001920 /* Never override disk quota limits or use reserved space */
1921 cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
1922
Vivek Goyal655042c2016-10-14 03:03:36 +02001923 sb->s_magic = OVERLAYFS_SUPER_MAGIC;
Vivek Goyal655042c2016-10-14 03:03:36 +02001924 sb->s_xattr = ovl_xattr_handlers;
Miklos Szerediad204482017-11-10 09:39:16 +01001925 sb->s_fs_info = ofs;
Miklos Szeredide2a4a52018-07-18 15:44:43 +02001926 sb->s_flags |= SB_POSIXACL;
Konstantin Khlebnikov32b1924b22020-04-09 11:29:47 +03001927 sb->s_iflags |= SB_I_SKIP_SYNC;
Vivek Goyal655042c2016-10-14 03:03:36 +02001928
Miklos Szeredic6fe6252017-11-10 09:39:15 +01001929 err = -ENOMEM;
Amir Goldstein2effc5c2019-11-19 17:49:17 +02001930 root_dentry = ovl_get_root(sb, upperpath.dentry, oe);
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001931 if (!root_dentry)
Miklos Szeredi4155c102017-11-10 09:39:15 +01001932 goto out_free_oe;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001933
1934 mntput(upperpath.mnt);
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001935 kfree(splitlower);
Miklos Szeredied06e062015-12-09 16:11:59 +01001936
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001937 sb->s_root = root_dentry;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001938
1939 return 0;
1940
Miklos Szeredi4155c102017-11-10 09:39:15 +01001941out_free_oe:
1942 ovl_entry_stack_free(oe);
Chandan Rajendrab9343632017-07-24 01:57:54 -05001943 kfree(oe);
Miklos Szeredi4155c102017-11-10 09:39:15 +01001944out_err:
Miklos Szeredib8e42a62020-06-04 10:48:19 +02001945 kfree(splitlower);
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001946 path_put(&upperpath);
Miklos Szerediad204482017-11-10 09:39:16 +01001947 ovl_free_fs(ofs);
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001948out:
1949 return err;
1950}
1951
1952static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
1953 const char *dev_name, void *raw_data)
1954{
1955 return mount_nodev(fs_type, flags, raw_data, ovl_fill_super);
1956}
1957
1958static struct file_system_type ovl_fs_type = {
1959 .owner = THIS_MODULE,
Miklos Szeredief94b182014-11-20 16:39:59 +01001960 .name = "overlay",
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001961 .mount = ovl_mount,
1962 .kill_sb = kill_anon_super,
1963};
Miklos Szeredief94b182014-11-20 16:39:59 +01001964MODULE_ALIAS_FS("overlay");
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001965
Amir Goldstein13cf1992017-06-12 09:54:40 +03001966static void ovl_inode_init_once(void *foo)
1967{
1968 struct ovl_inode *oi = foo;
1969
1970 inode_init_once(&oi->vfs_inode);
1971}
1972
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001973static int __init ovl_init(void)
1974{
Amir Goldstein13cf1992017-06-12 09:54:40 +03001975 int err;
1976
1977 ovl_inode_cachep = kmem_cache_create("ovl_inode",
1978 sizeof(struct ovl_inode), 0,
1979 (SLAB_RECLAIM_ACCOUNT|
1980 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1981 ovl_inode_init_once);
1982 if (ovl_inode_cachep == NULL)
1983 return -ENOMEM;
1984
Jiufei Xue2406a302019-11-20 17:45:26 +08001985 err = ovl_aio_request_cache_init();
1986 if (!err) {
1987 err = register_filesystem(&ovl_fs_type);
1988 if (!err)
1989 return 0;
1990
1991 ovl_aio_request_cache_destroy();
1992 }
1993 kmem_cache_destroy(ovl_inode_cachep);
Amir Goldstein13cf1992017-06-12 09:54:40 +03001994
1995 return err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001996}
1997
1998static void __exit ovl_exit(void)
1999{
2000 unregister_filesystem(&ovl_fs_type);
Amir Goldstein13cf1992017-06-12 09:54:40 +03002001
2002 /*
2003 * Make sure all delayed rcu free inodes are flushed before we
2004 * destroy cache.
2005 */
2006 rcu_barrier();
2007 kmem_cache_destroy(ovl_inode_cachep);
Jiufei Xue2406a302019-11-20 17:45:26 +08002008 ovl_aio_request_cache_destroy();
Miklos Szeredie9be9d52014-10-24 00:14:38 +02002009}
2010
2011module_init(ovl_init);
2012module_exit(ovl_exit);