Skip to contentSkip to conversation

ovl: warn if trusted xattr creation fails

PATCH In review Alois Wohlschlager 3 participants 3 messages Feb 3, 2022 – Feb 26, 2022 Overlay filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovl: warn if trusted xattr creation fails

When mounting overlayfs in an unprivileged user namespace, trusted xattr creation will fail. This will lead to failures in some file operations, e.g. in the following situation:

mkdir lower upper work merged
mkdir lower/directory
mount -toverlay -olowerdir=lower,upperdir=upper,workdir=work none merged rmdir merged/directory
mkdir merged/directory

The last mkdir will fail:

mkdir: cannot create directory 'merged/directory': Input/output error

The cause for these failures is currently extremely non-obvious and hard to debug. Hence, warn the user and suggest using the userxattr mount option, if it is not already supplied and xattr creation fails during the self-check.

---
 fs/overlayfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/overlayfs/super.c +0 -0
index 7bb0a47cb615..11123fe967e0 100644
@@ -1427,6 +1427,8 @@ static int ovl_make_workdir(struct super_block *sb,

struct ovl_fs *ofs,
ofs->config.xino = OVL_XINO_OFF; pr_warn("upper fs does not support xattr,
falling back to xino=off.\n");
}
+ if (!ofs->config.userxattr)
+ pr_warn("trusted xattr creation not
supported, some file operations may fail. Try mounting with userxattr next time.\n");
err = 0;
} else {
ovl_do_removexattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE);
--
2.35.1

maintainer
#1 lore raw
Quoted 10 lines · Alois Wohlschlager

When mounting overlayfs in an unprivileged user namespace, trusted xattr creation will fail. This will lead to failures in some file operations, e.g. in the following situation:

mkdir lower upper work merged
mkdir lower/directory
mount -toverlay -olowerdir=lower,upperdir=upper,workdir=work none merged rmdir merged/directory
mkdir merged/directory

Quoted 8 lines

The last mkdir will fail:

mkdir: cannot create directory 'merged/directory': Input/output error

The cause for these failures is currently extremely non-obvious and hard to debug. Hence, warn the user and suggest using the userxattr mount option, if it is not already supplied and xattr creation fails during the self-check.

Thanks for the patch.

How about the following (untested) variant?

Thanks,
Miklos

fs/overlayfs/super.c +5 -2
index 7bb0a47cb615..955aeefc3b29 100644
@@ -1413,11 +1413,12 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
 	 */
 	err = ovl_do_setxattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE, "0", 1);
 	if (err) {
+		pr_warn("failed to set xattr on upper\n");
 		ofs->noxattr = true;
 		if (ofs->config.index || ofs->config.metacopy) {
 			ofs->config.index = false;
 			ofs->config.metacopy = false;
-			pr_warn("upper fs does not support xattr, falling back to index=off,metacopy=off.\n");
+			pr_warn("...falling back to index=off,metacopy=off.\n");
 		}
 		/*
 		 * xattr support is required for persistent st_ino.
@@ -1425,8 +1426,10 @@ static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs,
 		 */
 		if (ofs->config.xino == OVL_XINO_AUTO) {
 			ofs->config.xino = OVL_XINO_OFF;
-			pr_warn("upper fs does not support xattr, falling back to xino=off.\n");
+			pr_warn("...falling back to xino=off.\n");
 		}
+		if (err == -EPERM && !ofs->config.userxattr)
+			pr_info("try mounting with 'userxattr' option\n");
 		err = 0;
 	} else {
 		ovl_do_removexattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE);
#2 lore raw

Am Montag, 21. Februar 2022, 12:11:47 CET schrieb Miklos Szeredi:

Quoted 30 lines

Thanks for the patch.

How about the following (untested) variant?

Thanks,
Miklos

fs/overlayfs/super.c +0 -0
index 7bb0a47cb615..955aeefc3b29 100644
@@ -1413,11 +1413,12 @@ static int ovl_make_workdir(struct super_block *sb,

struct ovl_fs *ofs, */

fs/overlayfs/super.c +1 -1
 	err = ovl_do_setxattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE, "0", 1);
 	if (err) {
+		pr_warn("failed to set xattr on upper\n");
 		ofs->noxattr = true;
 		if (ofs->config.index || ofs->config.metacopy) {
 			ofs->config.index = false;
 			ofs->config.metacopy = false;
-			pr_warn("upper fs does not support xattr, falling back to

index=off,metacopy=off.\n"); + pr_warn("...falling back to
index=off,metacopy=off.\n");

fs/overlayfs/super.c +0 -0
 		}
 		/*
 		 * xattr support is required for persistent st_ino.
@@ -1425,8 +1426,10 @@ static int ovl_make_workdir(struct super_block *sb,

struct ovl_fs *ofs, */

fs/overlayfs/super.c static int ovl_make_workdir(struct super_block *sb, struct ovl_fs *ofs, · line 1435

Quoted 10 lines
fs/overlayfs/super.c +3 -1
 		if (ofs->config.xino == OVL_XINO_AUTO) {
 			ofs->config.xino = OVL_XINO_OFF;
-			pr_warn("upper fs does not support xattr, falling back to xino=off.\n");
+			pr_warn("...falling back to xino=off.\n");
 		}
+		if (err == -EPERM && !ofs->config.userxattr)
+			pr_info("try mounting with 'userxattr' option\n");
 		err = 0;
 	} else {
 		ovl_do_removexattr(ofs, ofs->workdir, OVL_XATTR_OPAQUE);

Seems sensible to me, since it doesn't duplicate information in case index, metacopy or xino are attempted to be used.

Alois