Skip to contentSkip to conversation

cachefiles: do not yet allow on idmapped mounts

PATCH In review Christian Brauner 1 participant 2 messages Mar 19, 2021 – Mar 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 cachefiles: do not yet allow on idmapped mounts

Based on discussions (e.g. in [1]) my understanding of cachefiles and the cachefiles userspace daemon is that it creates a cache on a local filesystem (e.g. ext4, xfs etc.) for a network filesystem. The way this is done is by writing "bind" to /dev/cachefiles and pointing it to the directory to use as the cache.
Currently this directory can technically also be an idmapped mount but cachefiles aren't yet fully aware of such mounts and thus don't take the idmapping into account when creating cache entries. This could leave users confused as the ownership of the files wouldn't match to what they expressed in the idmapping. Block cache files on idmapped mounts until the fscache rework is done and we have ported it to support idmapped mounts.

[1]: https://lore.kernel.org/lkml/20210303161528.n3jzg66ou2wa43qb@wittgenstein

---
/* v2 */
- Christian Brauner <[email protected]>:
- Ensure that "root" is initialized when cleaning up.

/* v3 */
- David Howells <[email protected]>:
- Reformulate commit message to avoid paragraphs with duplicated content.
- Add a pr_warn() when cachefiles are supposed to be created on idmapped mounts.

---
 fs/cachefiles/bind.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cachefiles/bind.c +6 -0
index dfb14dbddf51..38bb7764b454 100644
@@ -118,6 +118,12 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
 	cache->mnt = path.mnt;
 	root = path.dentry;
 
+	ret = -EINVAL;
+	if (mnt_user_ns(path.mnt) != &init_user_ns) {
+		pr_warn("File cache on idmapped mounts not supported");
+		goto error_unsupported;
+	}
+
 	/* check parameters */
 	ret = -EOPNOTSUPP;
 	if (d_is_negative(root) ||

base-commit: 1e28eed17697bcf343c6743f0028cc3b5dd88bf0

Signature · 1 line
2.27.0
#1 lore raw
Quoted 13 lines · Christian Brauner

Based on discussions (e.g. in [1]) my understanding of cachefiles and the cachefiles userspace daemon is that it creates a cache on a local filesystem (e.g. ext4, xfs etc.) for a network filesystem. The way this is done is by writing "bind" to /dev/cachefiles and pointing it to the directory to use as the cache.
Currently this directory can technically also be an idmapped mount but cachefiles aren't yet fully aware of such mounts and thus don't take the idmapping into account when creating cache entries. This could leave users confused as the ownership of the files wouldn't match to what they expressed in the idmapping. Block cache files on idmapped mounts until the fscache rework is done and we have ported it to support idmapped mounts.

Quoted 5 lines

[1]: https://lore.kernel.org/lkml/20210303161528.n3jzg66ou2wa43qb@wittgenstein

---

Hey David,

Are you happy with this now, and could I possibly get your Ack on this, please? And also, are you routing this to Linus (preferably before v5.12 is out) or do you want me to take it?

Christian

Quoted 36 lines

/* v2 */
- Christian Brauner <[email protected]>:
- Ensure that "root" is initialized when cleaning up.

/* v3 */
- David Howells <[email protected]>:
- Reformulate commit message to avoid paragraphs with duplicated content.
- Add a pr_warn() when cachefiles are supposed to be created on idmapped mounts.

---
 fs/cachefiles/bind.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cachefiles/bind.c +6 -0
index dfb14dbddf51..38bb7764b454 100644
@@ -118,6 +118,12 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)
 	cache->mnt = path.mnt;
 	root = path.dentry;
 
+	ret = -EINVAL;
+	if (mnt_user_ns(path.mnt) != &init_user_ns) {
+		pr_warn("File cache on idmapped mounts not supported");
+		goto error_unsupported;
+	}
+
 	/* check parameters */
 	ret = -EOPNOTSUPP;
 	if (d_is_negative(root) ||

base-commit: 1e28eed17697bcf343c6743f0028cc3b5dd88bf0

Signature · 1 line
2.27.0