Skip to contentSkip to conversation

overlayfs: add FS_ALLOW_IDMAP flag to enable idmapped mounts

PATCH In review Sohan Kunkerkar 3 participants 3 messages Aug 15, 2025 – Aug 19, 2025 Overlay filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 overlayfs: add FS_ALLOW_IDMAP flag to enable idmapped mounts

OverlayFS already has comprehensive support for idmapped mounts through its ovl_copyattr() function and proper mnt_idmap() handling throughout the codebase. The infrastructure correctly maps UIDs/GIDs from idmapped upper and lower layers.

However, the filesystem was missing the FS_ALLOW_IDMAP flag, which caused mount_setattr() calls with MOUNT_ATTR_IDMAP to fail with -EINVAL.

This change enables idmapped mount support by adding the FS_ALLOW_IDMAP flag to the overlayfs file_system_type, allowing containers and other applications to use idmapped mounts with overlay filesystems.

---
 fs/overlayfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/super.c +1 -1
index e19940d64..c628f9179 100644
@@ -1516,7 +1516,7 @@ struct file_system_type ovl_fs_type = {
 	.name			= "overlay",
 	.init_fs_context	= ovl_init_fs_context,
 	.parameters		= ovl_parameter_spec,
-	.fs_flags		= FS_USERNS_MOUNT,
+	.fs_flags		= FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
 	.kill_sb		= kill_anon_super,
 };
 MODULE_ALIAS_FS("overlay");
Signature · 1 line
2.50.1
maintainer
#1 lore raw
Quoted 32 lines · Sohan Kunkerkar

OverlayFS already has comprehensive support for idmapped mounts through its ovl_copyattr() function and proper mnt_idmap() handling throughout the codebase. The infrastructure correctly maps UIDs/GIDs from idmapped upper and lower layers.

However, the filesystem was missing the FS_ALLOW_IDMAP flag, which caused mount_setattr() calls with MOUNT_ATTR_IDMAP to fail with -EINVAL.

This change enables idmapped mount support by adding the FS_ALLOW_IDMAP flag to the overlayfs file_system_type, allowing containers and other applications to use idmapped mounts with overlay filesystems.

---
 fs/overlayfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/super.c +1 -2
index e19940d64..c628f9179 100644
@@ -1516,7 +1516,7 @@ struct file_system_type ovl_fs_type = {
        .name                   = "overlay",
        .init_fs_context        = ovl_init_fs_context,
        .parameters             = ovl_parameter_spec,
-       .fs_flags               = FS_USERNS_MOUNT,
+       .fs_flags               = FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
        .kill_sb                = kill_anon_super,
 };
 MODULE_ALIAS_FS("overlay");
--
Quoted 1 line

2.50.1

So Christian just forgot to do that?

Somehow I find that hard to believe.

I am guessing there were either some known issues or more code audits that needed to be done.

Christian? WDYT?

Thanks,
Amir.

#2 lore raw
Quoted 37 lines · Amir Goldstein
Quoted 32 lines · Sohan Kunkerkar

OverlayFS already has comprehensive support for idmapped mounts through its ovl_copyattr() function and proper mnt_idmap() handling throughout the codebase. The infrastructure correctly maps UIDs/GIDs from idmapped upper and lower layers.

However, the filesystem was missing the FS_ALLOW_IDMAP flag, which caused mount_setattr() calls with MOUNT_ATTR_IDMAP to fail with -EINVAL.

This change enables idmapped mount support by adding the FS_ALLOW_IDMAP flag to the overlayfs file_system_type, allowing containers and other applications to use idmapped mounts with overlay filesystems.

---
 fs/overlayfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/super.c +1 -2
index e19940d64..c628f9179 100644
@@ -1516,7 +1516,7 @@ struct file_system_type ovl_fs_type = {
        .name                   = "overlay",
        .init_fs_context        = ovl_init_fs_context,
        .parameters             = ovl_parameter_spec,
-       .fs_flags               = FS_USERNS_MOUNT,
+       .fs_flags               = FS_USERNS_MOUNT | FS_ALLOW_IDMAP,
        .kill_sb                = kill_anon_super,
 };
 MODULE_ALIAS_FS("overlay");
--
Quoted 1 line

2.50.1

So Christian just forgot to do that?

Quoted 6 lines

Somehow I find that hard to believe.

I am guessing there were either some known issues or more code audits that needed to be done.

Christian? WDYT?

This is very wrong.

For overlayfs supporting idmapped mounts can mean two distinct things:

(1) mounting overlayfs on top of idmapped layers
(2) idmapping overlayfs itself

So far only (1) is supported. In order to support (2) further changes are required. To support (2) it is necessary to also take idmappings into account on the overlayfs idmapping layer itself and overlayfs internally needs to be made aware that it needs to do a double translation. One for the overlayfs layer itself and then one for the lower and upper layers.

It is possible as I've written that code years ago but it introduces a lot more subtle behavior. So only if someone really needs this.