# \[PATCH v5 38/42\] ecryptfs: do not mount on top of idmapped mounts

- From: Christian Brauner \<hidden\>
- Date: 2021-01-12 22:15:53 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2021/01/197240
- Thread: https://ratatoskr.run/linux-fsdevel/2021/01/197218/t.md

```text
Prevent ecryptfs from being mounted on top of idmapped mounts until we
have ported it to handle this case and added proper testing for it.

Cc: Christoph Hellwig <hch@lst.de>
Cc: David Howells <dhowells@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: <redacted>
Signed-off-by: Christian Brauner <redacted>
---
/* v2 */
patch introduced

/* v3 */
- David Howells [ref]:
  - Adapt check after removing mnt_idmapped() helper.

/* v4 */
unchanged

/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837

- Christoph Hellwig [ref]:
  - Use new file_userns_helper().
---
 fs/ecryptfs/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index e63259fdef28..cdf40a54a35d 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -531,6 +531,12 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
 		goto out_free;
 	}
 
+	if (mnt_user_ns(path.mnt) != &init_user_ns) {
+		rc = -EINVAL;
+		printk(KERN_ERR "Mounting on idmapped mounts currently disallowed\n");
+		goto out_free;
+	}
+
 	if (check_ruid && !uid_eq(d_inode(path.dentry)->i_uid, current_uid())) {
 		rc = -EPERM;
 		printk(KERN_ERR "Mount of device (uid: %d) not owned by "
-- 
2.30.0

```
