@@ -418,6 +418,7 @@ enum {
418418 OPT_UUID_ON ,
419419 OPT_UUID_OFF ,
420420 OPT_NFS_EXPORT_ON ,
421+ OPT_USERXATTR ,
421422 OPT_NFS_EXPORT_OFF ,
422423 OPT_XINO_ON ,
423424 OPT_XINO_OFF ,
@@ -436,6 +437,7 @@ static const match_table_t ovl_tokens = {
436437 {OPT_REDIRECT_DIR , "redirect_dir=%s" },
437438 {OPT_INDEX_ON , "index=on" },
438439 {OPT_INDEX_OFF , "index=off" },
440+ {OPT_USERXATTR , "userxattr" },
439441 {OPT_UUID_ON , "uuid=on" },
440442 {OPT_UUID_OFF , "uuid=off" },
441443 {OPT_NFS_EXPORT_ON , "nfs_export=on" },
@@ -602,6 +604,10 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
602604 config -> ovl_volatile = true;
603605 break ;
604606
607+ case OPT_USERXATTR :
608+ config -> userxattr = true;
609+ break ;
610+
605611 default :
606612 pr_err ("unrecognized mount option \"%s\" or missing value\n" ,
607613 p );
@@ -705,6 +711,28 @@ static int ovl_parse_opt(char *opt, struct ovl_config *config)
705711 }
706712 }
707713
714+
715+ /* Resolve userxattr -> !redirect && !metacopy dependency */
716+ if (config -> userxattr ) {
717+ if (config -> redirect_follow && redirect_opt ) {
718+ pr_err ("conflicting options: userxattr,redirect_dir=%s\n" ,
719+ config -> redirect_mode );
720+ return - EINVAL ;
721+ }
722+ if (config -> metacopy && metacopy_opt ) {
723+ pr_err ("conflicting options: userxattr,metacopy=on\n" );
724+ return - EINVAL ;
725+ }
726+ /*
727+ * Silently disable default setting of redirect and metacopy.
728+ * This shall be the default in the future as well: these
729+ * options must be explicitly enabled if used together with
730+ * userxattr.
731+ */
732+ config -> redirect_dir = config -> redirect_follow = false;
733+ config -> metacopy = false;
734+ }
735+
708736 return 0 ;
709737}
710738
@@ -1054,8 +1082,14 @@ ovl_posix_acl_default_xattr_handler = {
10541082 .set = ovl_posix_acl_xattr_set ,
10551083};
10561084
1057- static const struct xattr_handler ovl_own_xattr_handler = {
1058- .prefix = OVL_XATTR_PREFIX ,
1085+ static const struct xattr_handler ovl_own_trusted_xattr_handler = {
1086+ .prefix = OVL_XATTR_TRUSTED_PREFIX ,
1087+ .get = ovl_own_xattr_get ,
1088+ .set = ovl_own_xattr_set ,
1089+ };
1090+
1091+ static const struct xattr_handler ovl_own_user_xattr_handler = {
1092+ .prefix = OVL_XATTR_USER_PREFIX ,
10591093 .get = ovl_own_xattr_get ,
10601094 .set = ovl_own_xattr_set ,
10611095};
@@ -1066,12 +1100,22 @@ static const struct xattr_handler ovl_other_xattr_handler = {
10661100 .set = ovl_other_xattr_set ,
10671101};
10681102
1069- static const struct xattr_handler * ovl_xattr_handlers [] = {
1103+ static const struct xattr_handler * ovl_trusted_xattr_handlers [] = {
1104+ #ifdef CONFIG_FS_POSIX_ACL
1105+ & ovl_posix_acl_access_xattr_handler ,
1106+ & ovl_posix_acl_default_xattr_handler ,
1107+ #endif
1108+ & ovl_own_trusted_xattr_handler ,
1109+ & ovl_other_xattr_handler ,
1110+ NULL
1111+ };
1112+
1113+ static const struct xattr_handler * ovl_user_xattr_handlers [] = {
10701114#ifdef CONFIG_FS_POSIX_ACL
10711115 & ovl_posix_acl_access_xattr_handler ,
10721116 & ovl_posix_acl_default_xattr_handler ,
10731117#endif
1074- & ovl_own_xattr_handler ,
1118+ & ovl_own_user_xattr_handler ,
10751119 & ovl_other_xattr_handler ,
10761120 NULL
10771121};
@@ -1334,7 +1378,7 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
13341378 pr_warn ("upper fs does not support RENAME_WHITEOUT.\n" );
13351379
13361380 /*
1337- * Check if upper/work fs supports trusted.overlay.* xattr
1381+ * Check if upper/work fs supports ( trusted|user) .overlay.* xattr
13381382 */
13391383 err = ovl_do_setxattr (ofs , ofs -> workdir , OVL_XATTR_OPAQUE , "0" , 1 );
13401384 if (err ) {
@@ -1473,10 +1517,10 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
14731517
14741518 /*
14751519 * Verify upper root is exclusively associated with index dir.
1476- * Older kernels stored upper fh in "trusted .overlay.origin"
1520+ * Older kernels stored upper fh in ".overlay.origin"
14771521 * xattr. If that xattr exists, verify that it is a match to
14781522 * upper dir file handle. In any case, verify or set xattr
1479- * "trusted .overlay.upper" to indicate that index may have
1523+ * ".overlay.upper" to indicate that index may have
14801524 * directory entries.
14811525 */
14821526 if (ovl_check_origin_xattr (ofs , ofs -> indexdir )) {
@@ -2014,7 +2058,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
20142058 cap_lower (cred -> cap_effective , CAP_SYS_RESOURCE );
20152059
20162060 sb -> s_magic = OVERLAYFS_SUPER_MAGIC ;
2017- sb -> s_xattr = ovl_xattr_handlers ;
2061+ sb -> s_xattr = ofs -> config .userxattr ? ovl_user_xattr_handlers :
2062+ ovl_trusted_xattr_handlers ;
20182063 sb -> s_fs_info = ofs ;
20192064 sb -> s_flags |= SB_POSIXACL ;
20202065 sb -> s_iflags |= SB_I_SKIP_SYNC ;
0 commit comments