1 // SPDX-License-Identifier: GPL-2.0-only
4 #include <linux/module.h>
5 #include <linux/namei.h>
6 #include <linux/fs_context.h>
7 #include <linux/fs_parser.h>
8 #include <linux/posix_acl_xattr.h>
9 #include <linux/seq_file.h>
10 #include <linux/xattr.h>
11 #include "overlayfs.h"
14 static bool ovl_redirect_dir_def
= IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR
);
15 module_param_named(redirect_dir
, ovl_redirect_dir_def
, bool, 0644);
16 MODULE_PARM_DESC(redirect_dir
,
17 "Default to on or off for the redirect_dir feature");
19 static bool ovl_redirect_always_follow
=
20 IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_ALWAYS_FOLLOW
);
21 module_param_named(redirect_always_follow
, ovl_redirect_always_follow
,
23 MODULE_PARM_DESC(redirect_always_follow
,
24 "Follow redirects even if redirect_dir feature is turned off");
26 static bool ovl_xino_auto_def
= IS_ENABLED(CONFIG_OVERLAY_FS_XINO_AUTO
);
27 module_param_named(xino_auto
, ovl_xino_auto_def
, bool, 0644);
28 MODULE_PARM_DESC(xino_auto
,
29 "Auto enable xino feature");
31 static bool ovl_index_def
= IS_ENABLED(CONFIG_OVERLAY_FS_INDEX
);
32 module_param_named(index
, ovl_index_def
, bool, 0644);
33 MODULE_PARM_DESC(index
,
34 "Default to on or off for the inodes index feature");
36 static bool ovl_nfs_export_def
= IS_ENABLED(CONFIG_OVERLAY_FS_NFS_EXPORT
);
37 module_param_named(nfs_export
, ovl_nfs_export_def
, bool, 0644);
38 MODULE_PARM_DESC(nfs_export
,
39 "Default to on or off for the NFS export feature");
41 static bool ovl_metacopy_def
= IS_ENABLED(CONFIG_OVERLAY_FS_METACOPY
);
42 module_param_named(metacopy
, ovl_metacopy_def
, bool, 0644);
43 MODULE_PARM_DESC(metacopy
,
44 "Default to on or off for the metadata only copy up feature");
52 Opt_default_permissions
,
64 static const struct constant_table ovl_parameter_bool
[] = {
70 static const struct constant_table ovl_parameter_uuid
[] = {
71 { "off", OVL_UUID_OFF
},
72 { "null", OVL_UUID_NULL
},
73 { "auto", OVL_UUID_AUTO
},
74 { "on", OVL_UUID_ON
},
78 static const char *ovl_uuid_mode(struct ovl_config
*config
)
80 return ovl_parameter_uuid
[config
->uuid
].name
;
83 static int ovl_uuid_def(void)
88 static const struct constant_table ovl_parameter_xino
[] = {
89 { "off", OVL_XINO_OFF
},
90 { "auto", OVL_XINO_AUTO
},
91 { "on", OVL_XINO_ON
},
95 const char *ovl_xino_mode(struct ovl_config
*config
)
97 return ovl_parameter_xino
[config
->xino
].name
;
100 static int ovl_xino_def(void)
102 return ovl_xino_auto_def
? OVL_XINO_AUTO
: OVL_XINO_OFF
;
105 const struct constant_table ovl_parameter_redirect_dir
[] = {
106 { "off", OVL_REDIRECT_OFF
},
107 { "follow", OVL_REDIRECT_FOLLOW
},
108 { "nofollow", OVL_REDIRECT_NOFOLLOW
},
109 { "on", OVL_REDIRECT_ON
},
113 static const char *ovl_redirect_mode(struct ovl_config
*config
)
115 return ovl_parameter_redirect_dir
[config
->redirect_mode
].name
;
118 static int ovl_redirect_mode_def(void)
120 return ovl_redirect_dir_def
? OVL_REDIRECT_ON
:
121 ovl_redirect_always_follow
? OVL_REDIRECT_FOLLOW
:
122 OVL_REDIRECT_NOFOLLOW
;
125 static const struct constant_table ovl_parameter_verity
[] = {
126 { "off", OVL_VERITY_OFF
},
127 { "on", OVL_VERITY_ON
},
128 { "require", OVL_VERITY_REQUIRE
},
132 static const char *ovl_verity_mode(struct ovl_config
*config
)
134 return ovl_parameter_verity
[config
->verity_mode
].name
;
137 static int ovl_verity_mode_def(void)
139 return OVL_VERITY_OFF
;
142 const struct fs_parameter_spec ovl_parameter_spec
[] = {
143 fsparam_string_empty("lowerdir", Opt_lowerdir
),
144 fsparam_file_or_string("lowerdir+", Opt_lowerdir_add
),
145 fsparam_file_or_string("datadir+", Opt_datadir_add
),
146 fsparam_file_or_string("upperdir", Opt_upperdir
),
147 fsparam_file_or_string("workdir", Opt_workdir
),
148 fsparam_flag("default_permissions", Opt_default_permissions
),
149 fsparam_enum("redirect_dir", Opt_redirect_dir
, ovl_parameter_redirect_dir
),
150 fsparam_enum("index", Opt_index
, ovl_parameter_bool
),
151 fsparam_enum("uuid", Opt_uuid
, ovl_parameter_uuid
),
152 fsparam_enum("nfs_export", Opt_nfs_export
, ovl_parameter_bool
),
153 fsparam_flag("userxattr", Opt_userxattr
),
154 fsparam_enum("xino", Opt_xino
, ovl_parameter_xino
),
155 fsparam_enum("metacopy", Opt_metacopy
, ovl_parameter_bool
),
156 fsparam_enum("verity", Opt_verity
, ovl_parameter_verity
),
157 fsparam_flag("volatile", Opt_volatile
),
161 static char *ovl_next_opt(char **s
)
169 for (p
= sbegin
; *p
; p
++) {
174 } else if (*p
== ',') {
184 static int ovl_parse_monolithic(struct fs_context
*fc
, void *data
)
186 return vfs_parse_monolithic_sep(fc
, data
, ovl_next_opt
);
189 static ssize_t
ovl_parse_param_split_lowerdirs(char *str
)
191 ssize_t nr_layers
= 1, nr_colons
= 0;
194 for (s
= d
= str
;; s
++, d
++) {
196 /* keep esc chars in split lowerdir */
198 } else if (*s
== ':') {
199 bool next_colon
= (*(s
+ 1) == ':');
202 if (nr_colons
== 2 && next_colon
) {
203 pr_err("only single ':' or double '::' sequences of unescaped colons in lowerdir mount option allowed.\n");
206 /* count layers, not colons */
216 /* trailing colons */
218 pr_err("unescaped trailing colons in lowerdir mount option.\n");
229 static int ovl_mount_dir_noesc(const char *name
, struct path
*path
)
234 pr_err("empty lowerdir\n");
237 err
= kern_path(name
, LOOKUP_FOLLOW
, path
);
239 pr_err("failed to resolve '%s': %i\n", name
, err
);
248 static void ovl_unescape(char *s
)
261 static int ovl_mount_dir(const char *name
, struct path
*path
)
264 char *tmp
= kstrdup(name
, GFP_KERNEL
);
268 err
= ovl_mount_dir_noesc(tmp
, path
);
274 static int ovl_mount_dir_check(struct fs_context
*fc
, const struct path
*path
,
275 enum ovl_opt layer
, const char *name
, bool upper
)
277 struct ovl_fs_context
*ctx
= fc
->fs_private
;
279 if (!d_is_dir(path
->dentry
))
280 return invalfc(fc
, "%s is not a directory", name
);
283 * Root dentries of case-insensitive capable filesystems might
284 * not have the dentry operations set, but still be incompatible
285 * with overlayfs. Check explicitly to prevent post-mount
288 if (sb_has_encoding(path
->mnt
->mnt_sb
))
289 return invalfc(fc
, "case-insensitive capable filesystem on %s not supported", name
);
291 if (ovl_dentry_weird(path
->dentry
))
292 return invalfc(fc
, "filesystem on %s not supported", name
);
295 * Check whether upper path is read-only here to report failures
296 * early. Don't forget to recheck when the superblock is created
297 * as the mount attributes could change.
300 if (path
->dentry
->d_flags
& DCACHE_OP_REAL
)
301 return invalfc(fc
, "filesystem on %s not supported as upperdir", name
);
302 if (__mnt_is_readonly(path
->mnt
))
303 return invalfc(fc
, "filesystem on %s is read-only", name
);
305 if (ctx
->lowerdir_all
&& layer
!= Opt_lowerdir
)
306 return invalfc(fc
, "lowerdir+ and datadir+ cannot follow lowerdir");
307 if (ctx
->nr_data
&& layer
== Opt_lowerdir_add
)
308 return invalfc(fc
, "regular lower layers cannot follow data layers");
309 if (ctx
->nr
== OVL_MAX_STACK
)
310 return invalfc(fc
, "too many lower directories, limit is %d",
316 static int ovl_ctx_realloc_lower(struct fs_context
*fc
)
318 struct ovl_fs_context
*ctx
= fc
->fs_private
;
319 struct ovl_fs_context_layer
*l
;
322 if (ctx
->nr
< ctx
->capacity
)
325 nr
= min_t(size_t, max(4096 / sizeof(*l
), ctx
->capacity
* 2),
327 l
= krealloc_array(ctx
->lower
, nr
, sizeof(*l
), GFP_KERNEL_ACCOUNT
);
336 static void ovl_add_layer(struct fs_context
*fc
, enum ovl_opt layer
,
337 struct path
*path
, char **pname
)
339 struct ovl_fs
*ofs
= fc
->s_fs_info
;
340 struct ovl_config
*config
= &ofs
->config
;
341 struct ovl_fs_context
*ctx
= fc
->fs_private
;
342 struct ovl_fs_context_layer
*l
;
346 swap(config
->workdir
, *pname
);
347 swap(ctx
->work
, *path
);
350 swap(config
->upperdir
, *pname
);
351 swap(ctx
->upper
, *path
);
353 case Opt_datadir_add
:
358 case Opt_lowerdir_add
:
359 WARN_ON(ctx
->nr
>= ctx
->capacity
);
360 l
= &ctx
->lower
[ctx
->nr
++];
361 memset(l
, 0, sizeof(*l
));
362 swap(l
->name
, *pname
);
363 swap(l
->path
, *path
);
370 static inline bool is_upper_layer(enum ovl_opt layer
)
372 return layer
== Opt_upperdir
|| layer
== Opt_workdir
;
375 /* Handle non-file descriptor-based layer options that require path lookup. */
376 static inline int ovl_kern_path(const char *layer_name
, struct path
*layer_path
,
387 err
= ovl_mount_dir(layer_name
, layer_path
);
389 case Opt_lowerdir_add
:
391 case Opt_datadir_add
:
392 err
= ovl_mount_dir_noesc(layer_name
, layer_path
);
402 static int ovl_do_parse_layer(struct fs_context
*fc
, const char *layer_name
,
403 struct path
*layer_path
, enum ovl_opt layer
)
405 char *name
__free(kfree
) = kstrdup(layer_name
, GFP_KERNEL
);
412 upper
= is_upper_layer(layer
);
413 err
= ovl_mount_dir_check(fc
, layer_path
, layer
, name
, upper
);
418 err
= ovl_ctx_realloc_lower(fc
);
423 /* Store the user provided path string in ctx to show in mountinfo */
424 ovl_add_layer(fc
, layer
, layer_path
, &name
);
428 static int ovl_parse_layer(struct fs_context
*fc
, struct fs_parameter
*param
,
431 struct path layer_path
__free(path_put
) = {};
434 switch (param
->type
) {
435 case fs_value_is_string
:
436 err
= ovl_kern_path(param
->string
, &layer_path
, layer
);
439 err
= ovl_do_parse_layer(fc
, param
->string
, &layer_path
, layer
);
441 case fs_value_is_file
: {
442 char *buf
__free(kfree
);
445 buf
= kmalloc(PATH_MAX
, GFP_KERNEL_ACCOUNT
);
449 layer_path
= param
->file
->f_path
;
450 path_get(&layer_path
);
452 layer_name
= d_path(&layer_path
, buf
, PATH_MAX
);
453 if (IS_ERR(layer_name
))
454 return PTR_ERR(layer_name
);
456 err
= ovl_do_parse_layer(fc
, layer_name
, &layer_path
, layer
);
467 static void ovl_reset_lowerdirs(struct ovl_fs_context
*ctx
)
469 struct ovl_fs_context_layer
*l
= ctx
->lower
;
471 // Reset old user provided lowerdir string
472 kfree(ctx
->lowerdir_all
);
473 ctx
->lowerdir_all
= NULL
;
475 for (size_t nr
= 0; nr
< ctx
->nr
; nr
++, l
++) {
485 * Parse lowerdir= mount option:
487 * e.g.: lowerdir=/lower1:/lower2:/lower3::/data1::/data2
488 * Set "/lower1", "/lower2", and "/lower3" as lower layers and
489 * "/data1" and "/data2" as data lower layers. Any existing lower
490 * layers are replaced.
492 static int ovl_parse_param_lowerdir(const char *name
, struct fs_context
*fc
)
495 struct ovl_fs_context
*ctx
= fc
->fs_private
;
496 char *dup
= NULL
, *iter
;
497 ssize_t nr_lower
, nr
;
498 bool data_layer
= false;
501 * Ensure we're backwards compatible with mount(2)
502 * by allowing relative paths.
505 /* drop all existing lower layers */
506 ovl_reset_lowerdirs(ctx
);
512 pr_err("cannot append lower layer\n");
516 // Store user provided lowerdir string to show in mount options
517 ctx
->lowerdir_all
= kstrdup(name
, GFP_KERNEL
);
518 if (!ctx
->lowerdir_all
)
521 dup
= kstrdup(name
, GFP_KERNEL
);
526 nr_lower
= ovl_parse_param_split_lowerdirs(dup
);
530 if (nr_lower
> OVL_MAX_STACK
) {
531 pr_err("too many lower directories, limit is %d\n", OVL_MAX_STACK
);
536 for (nr
= 0; nr
< nr_lower
; nr
++) {
537 struct path path
__free(path_put
) = {};
539 err
= ovl_kern_path(iter
, &path
, Opt_lowerdir
);
543 err
= ovl_do_parse_layer(fc
, iter
, &path
, Opt_lowerdir
);
550 /* Calling strchr() again would overrun. */
551 if (ctx
->nr
== nr_lower
)
555 iter
= strchr(iter
, '\0') + 1;
558 * This is a regular layer so we require that
559 * there are no data layers.
561 if (ctx
->nr_data
> 0) {
562 pr_err("regular lower layers cannot follow data lower layers\n");
570 /* This is a data lower layer. */
580 /* Intentionally don't realloc to a smaller size. */
584 static int ovl_parse_param(struct fs_context
*fc
, struct fs_parameter
*param
)
587 struct fs_parse_result result
;
588 struct ovl_fs
*ofs
= fc
->s_fs_info
;
589 struct ovl_config
*config
= &ofs
->config
;
590 struct ovl_fs_context
*ctx
= fc
->fs_private
;
593 if (fc
->purpose
== FS_CONTEXT_FOR_RECONFIGURE
) {
595 * On remount overlayfs has always ignored all mount
596 * options no matter if malformed or not so for
597 * backwards compatibility we do the same here.
603 * Give us the freedom to allow changing mount options
604 * with the new mount api in the future. So instead of
605 * silently ignoring everything we report a proper
606 * error. This is only visible for users of the new
609 return invalfc(fc
, "No changes allowed in reconfigure");
612 opt
= fs_parse(fc
, ovl_parameter_spec
, param
, &result
);
618 err
= ovl_parse_param_lowerdir(param
->string
, fc
);
620 case Opt_lowerdir_add
:
621 case Opt_datadir_add
:
624 err
= ovl_parse_layer(fc
, param
, opt
);
626 case Opt_default_permissions
:
627 config
->default_permissions
= true;
629 case Opt_redirect_dir
:
630 config
->redirect_mode
= result
.uint_32
;
631 if (config
->redirect_mode
== OVL_REDIRECT_OFF
) {
632 config
->redirect_mode
= ovl_redirect_always_follow
?
633 OVL_REDIRECT_FOLLOW
:
634 OVL_REDIRECT_NOFOLLOW
;
636 ctx
->set
.redirect
= true;
639 config
->index
= result
.uint_32
;
640 ctx
->set
.index
= true;
643 config
->uuid
= result
.uint_32
;
646 config
->nfs_export
= result
.uint_32
;
647 ctx
->set
.nfs_export
= true;
650 config
->xino
= result
.uint_32
;
653 config
->metacopy
= result
.uint_32
;
654 ctx
->set
.metacopy
= true;
657 config
->verity_mode
= result
.uint_32
;
660 config
->ovl_volatile
= true;
663 config
->userxattr
= true;
666 pr_err("unrecognized mount option \"%s\" or missing value\n",
674 static int ovl_get_tree(struct fs_context
*fc
)
676 return get_tree_nodev(fc
, ovl_fill_super
);
679 static inline void ovl_fs_context_free(struct ovl_fs_context
*ctx
)
681 ovl_reset_lowerdirs(ctx
);
682 path_put(&ctx
->upper
);
683 path_put(&ctx
->work
);
688 static void ovl_free(struct fs_context
*fc
)
690 struct ovl_fs
*ofs
= fc
->s_fs_info
;
691 struct ovl_fs_context
*ctx
= fc
->fs_private
;
694 * ofs is stored in the fs_context when it is initialized.
695 * ofs is transferred to the superblock on a successful mount,
696 * but if an error occurs before the transfer we have to free
703 ovl_fs_context_free(ctx
);
706 static int ovl_reconfigure(struct fs_context
*fc
)
708 struct super_block
*sb
= fc
->root
->d_sb
;
709 struct ovl_fs
*ofs
= OVL_FS(sb
);
710 struct super_block
*upper_sb
;
713 if (!(fc
->sb_flags
& SB_RDONLY
) && ovl_force_readonly(ofs
))
716 if (fc
->sb_flags
& SB_RDONLY
&& !sb_rdonly(sb
)) {
717 upper_sb
= ovl_upper_mnt(ofs
)->mnt_sb
;
718 if (ovl_should_sync(ofs
)) {
719 down_read(&upper_sb
->s_umount
);
720 ret
= sync_filesystem(upper_sb
);
721 up_read(&upper_sb
->s_umount
);
728 static const struct fs_context_operations ovl_context_ops
= {
729 .parse_monolithic
= ovl_parse_monolithic
,
730 .parse_param
= ovl_parse_param
,
731 .get_tree
= ovl_get_tree
,
732 .reconfigure
= ovl_reconfigure
,
737 * This is called during fsopen() and will record the user namespace of
738 * the caller in fc->user_ns since we've raised FS_USERNS_MOUNT. We'll
739 * need it when we actually create the superblock to verify that the
740 * process creating the superblock is in the same user namespace as
741 * process that called fsopen().
743 int ovl_init_fs_context(struct fs_context
*fc
)
745 struct ovl_fs_context
*ctx
;
748 ctx
= kzalloc(sizeof(*ctx
), GFP_KERNEL_ACCOUNT
);
753 * By default we allocate for three lower layers. It's likely
754 * that it'll cover most users.
756 ctx
->lower
= kmalloc_array(3, sizeof(*ctx
->lower
), GFP_KERNEL_ACCOUNT
);
761 ofs
= kzalloc(sizeof(struct ovl_fs
), GFP_KERNEL
);
765 ofs
->config
.redirect_mode
= ovl_redirect_mode_def();
766 ofs
->config
.index
= ovl_index_def
;
767 ofs
->config
.uuid
= ovl_uuid_def();
768 ofs
->config
.nfs_export
= ovl_nfs_export_def
;
769 ofs
->config
.xino
= ovl_xino_def();
770 ofs
->config
.metacopy
= ovl_metacopy_def
;
773 fc
->fs_private
= ctx
;
774 fc
->ops
= &ovl_context_ops
;
778 ovl_fs_context_free(ctx
);
783 void ovl_free_fs(struct ovl_fs
*ofs
)
785 struct vfsmount
**mounts
;
788 iput(ofs
->workbasedir_trap
);
789 iput(ofs
->workdir_trap
);
792 if (ofs
->workdir_locked
)
793 ovl_inuse_unlock(ofs
->workbasedir
);
794 dput(ofs
->workbasedir
);
795 if (ofs
->upperdir_locked
)
796 ovl_inuse_unlock(ovl_upper_mnt(ofs
)->mnt_root
);
798 /* Reuse ofs->config.lowerdirs as a vfsmount array before freeing it */
799 mounts
= (struct vfsmount
**) ofs
->config
.lowerdirs
;
800 for (i
= 0; i
< ofs
->numlayer
; i
++) {
801 iput(ofs
->layers
[i
].trap
);
802 kfree(ofs
->config
.lowerdirs
[i
]);
803 mounts
[i
] = ofs
->layers
[i
].mnt
;
805 kern_unmount_array(mounts
, ofs
->numlayer
);
807 for (i
= 0; i
< ofs
->numfs
; i
++)
808 free_anon_bdev(ofs
->fs
[i
].pseudo_dev
);
811 kfree(ofs
->config
.lowerdirs
);
812 kfree(ofs
->config
.upperdir
);
813 kfree(ofs
->config
.workdir
);
814 if (ofs
->creator_cred
)
815 put_cred(ofs
->creator_cred
);
819 int ovl_fs_params_verify(const struct ovl_fs_context
*ctx
,
820 struct ovl_config
*config
)
822 struct ovl_opt_set set
= ctx
->set
;
824 /* Workdir/index are useless in non-upper mount */
825 if (!config
->upperdir
) {
826 if (config
->workdir
) {
827 pr_info("option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
829 kfree(config
->workdir
);
830 config
->workdir
= NULL
;
832 if (config
->index
&& set
.index
) {
833 pr_info("option \"index=on\" is useless in a non-upper mount, ignore\n");
836 config
->index
= false;
839 if (!config
->upperdir
&& config
->ovl_volatile
) {
840 pr_info("option \"volatile\" is meaningless in a non-upper mount, ignoring it.\n");
841 config
->ovl_volatile
= false;
844 if (!config
->upperdir
&& config
->uuid
== OVL_UUID_ON
) {
845 pr_info("option \"uuid=on\" requires an upper fs, falling back to uuid=null.\n");
846 config
->uuid
= OVL_UUID_NULL
;
849 /* Resolve verity -> metacopy dependency */
850 if (config
->verity_mode
&& !config
->metacopy
) {
851 /* Don't allow explicit specified conflicting combinations */
853 pr_err("conflicting options: metacopy=off,verity=%s\n",
854 ovl_verity_mode(config
));
857 /* Otherwise automatically enable metacopy. */
858 config
->metacopy
= true;
862 * This is to make the logic below simpler. It doesn't make any other
863 * difference, since redirect_dir=on is only used for upper.
865 if (!config
->upperdir
&& config
->redirect_mode
== OVL_REDIRECT_FOLLOW
)
866 config
->redirect_mode
= OVL_REDIRECT_ON
;
868 /* Resolve verity -> metacopy -> redirect_dir dependency */
869 if (config
->metacopy
&& config
->redirect_mode
!= OVL_REDIRECT_ON
) {
870 if (set
.metacopy
&& set
.redirect
) {
871 pr_err("conflicting options: metacopy=on,redirect_dir=%s\n",
872 ovl_redirect_mode(config
));
875 if (config
->verity_mode
&& set
.redirect
) {
876 pr_err("conflicting options: verity=%s,redirect_dir=%s\n",
877 ovl_verity_mode(config
), ovl_redirect_mode(config
));
882 * There was an explicit redirect_dir=... that resulted
885 pr_info("disabling metacopy due to redirect_dir=%s\n",
886 ovl_redirect_mode(config
));
887 config
->metacopy
= false;
889 /* Automatically enable redirect otherwise. */
890 config
->redirect_mode
= OVL_REDIRECT_ON
;
894 /* Resolve nfs_export -> index dependency */
895 if (config
->nfs_export
&& !config
->index
) {
896 if (!config
->upperdir
&&
897 config
->redirect_mode
!= OVL_REDIRECT_NOFOLLOW
) {
898 pr_info("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n");
899 config
->nfs_export
= false;
900 } else if (set
.nfs_export
&& set
.index
) {
901 pr_err("conflicting options: nfs_export=on,index=off\n");
903 } else if (set
.index
) {
905 * There was an explicit index=off that resulted
908 pr_info("disabling nfs_export due to index=off\n");
909 config
->nfs_export
= false;
911 /* Automatically enable index otherwise. */
912 config
->index
= true;
916 /* Resolve nfs_export -> !metacopy && !verity dependency */
917 if (config
->nfs_export
&& config
->metacopy
) {
918 if (set
.nfs_export
&& set
.metacopy
) {
919 pr_err("conflicting options: nfs_export=on,metacopy=on\n");
924 * There was an explicit metacopy=on that resulted
927 pr_info("disabling nfs_export due to metacopy=on\n");
928 config
->nfs_export
= false;
929 } else if (config
->verity_mode
) {
931 * There was an explicit verity=.. that resulted
934 pr_info("disabling nfs_export due to verity=%s\n",
935 ovl_verity_mode(config
));
936 config
->nfs_export
= false;
939 * There was an explicit nfs_export=on that resulted
942 pr_info("disabling metacopy due to nfs_export=on\n");
943 config
->metacopy
= false;
948 /* Resolve userxattr -> !redirect && !metacopy && !verity dependency */
949 if (config
->userxattr
) {
951 config
->redirect_mode
!= OVL_REDIRECT_NOFOLLOW
) {
952 pr_err("conflicting options: userxattr,redirect_dir=%s\n",
953 ovl_redirect_mode(config
));
956 if (config
->metacopy
&& set
.metacopy
) {
957 pr_err("conflicting options: userxattr,metacopy=on\n");
960 if (config
->verity_mode
) {
961 pr_err("conflicting options: userxattr,verity=%s\n",
962 ovl_verity_mode(config
));
966 * Silently disable default setting of redirect and metacopy.
967 * This shall be the default in the future as well: these
968 * options must be explicitly enabled if used together with
971 config
->redirect_mode
= OVL_REDIRECT_NOFOLLOW
;
972 config
->metacopy
= false;
976 * Fail if we don't have trusted xattr capability and a feature was
977 * explicitly requested that requires them.
979 if (!config
->userxattr
&& !capable(CAP_SYS_ADMIN
)) {
981 config
->redirect_mode
!= OVL_REDIRECT_NOFOLLOW
) {
982 pr_err("redirect_dir requires permission to access trusted xattrs\n");
985 if (config
->metacopy
&& set
.metacopy
) {
986 pr_err("metacopy requires permission to access trusted xattrs\n");
989 if (config
->verity_mode
) {
990 pr_err("verity requires permission to access trusted xattrs\n");
993 if (ctx
->nr_data
> 0) {
994 pr_err("lower data-only dirs require permission to access trusted xattrs\n");
998 * Other xattr-dependent features should be disabled without
999 * great disturbance to the user in ovl_make_workdir().
1003 if (ctx
->nr_data
> 0 && !config
->metacopy
) {
1004 pr_err("lower data-only dirs require metacopy support.\n");
1013 * @m: the seq_file handle
1014 * @dentry: The dentry to query
1016 * Prints the mount options for a given superblock.
1017 * Returns zero; does not fail.
1019 int ovl_show_options(struct seq_file
*m
, struct dentry
*dentry
)
1021 struct super_block
*sb
= dentry
->d_sb
;
1022 struct ovl_fs
*ofs
= OVL_FS(sb
);
1023 size_t nr
, nr_merged_lower
, nr_lower
= 0;
1024 char **lowerdirs
= ofs
->config
.lowerdirs
;
1027 * lowerdirs[0] holds the colon separated list that user provided
1028 * with lowerdir mount option.
1029 * lowerdirs[1..numlayer] hold the lowerdir paths that were added
1030 * using the lowerdir+ and datadir+ mount options.
1031 * For now, we do not allow mixing the legacy lowerdir mount option
1032 * with the new lowerdir+ and datadir+ mount options.
1035 seq_show_option(m
, "lowerdir", lowerdirs
[0]);
1037 nr_lower
= ofs
->numlayer
;
1038 nr_merged_lower
= nr_lower
- ofs
->numdatalayer
;
1040 for (nr
= 1; nr
< nr_lower
; nr
++) {
1041 if (nr
< nr_merged_lower
)
1042 seq_show_option(m
, "lowerdir+", lowerdirs
[nr
]);
1044 seq_show_option(m
, "datadir+", lowerdirs
[nr
]);
1046 if (ofs
->config
.upperdir
) {
1047 seq_show_option(m
, "upperdir", ofs
->config
.upperdir
);
1048 seq_show_option(m
, "workdir", ofs
->config
.workdir
);
1050 if (ofs
->config
.default_permissions
)
1051 seq_puts(m
, ",default_permissions");
1052 if (ofs
->config
.redirect_mode
!= ovl_redirect_mode_def())
1053 seq_printf(m
, ",redirect_dir=%s",
1054 ovl_redirect_mode(&ofs
->config
));
1055 if (ofs
->config
.index
!= ovl_index_def
)
1056 seq_printf(m
, ",index=%s", ofs
->config
.index
? "on" : "off");
1057 if (ofs
->config
.uuid
!= ovl_uuid_def())
1058 seq_printf(m
, ",uuid=%s", ovl_uuid_mode(&ofs
->config
));
1059 if (ofs
->config
.nfs_export
!= ovl_nfs_export_def
)
1060 seq_printf(m
, ",nfs_export=%s", ofs
->config
.nfs_export
?
1062 if (ofs
->config
.xino
!= ovl_xino_def() && !ovl_same_fs(ofs
))
1063 seq_printf(m
, ",xino=%s", ovl_xino_mode(&ofs
->config
));
1064 if (ofs
->config
.metacopy
!= ovl_metacopy_def
)
1065 seq_printf(m
, ",metacopy=%s",
1066 ofs
->config
.metacopy
? "on" : "off");
1067 if (ofs
->config
.ovl_volatile
)
1068 seq_puts(m
, ",volatile");
1069 if (ofs
->config
.userxattr
)
1070 seq_puts(m
, ",userxattr");
1071 if (ofs
->config
.verity_mode
!= ovl_verity_mode_def())
1072 seq_printf(m
, ",verity=%s",
1073 ovl_verity_mode(&ofs
->config
));