Skip to contentSkip to conversation

cachefiles: Allow the cache to be non-root

PATCH Applied David Howells 4 participants 4 messages May 19, 2023 – Jun 5, 2023

Subsystems (2)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

PATCH 1/1 cachefiles: Allow the cache to be non-root

Set mode 0600 on files in the cache so that cachefilesd can run as an unprivileged user rather than leaving the files all with 0. Directories are already set to 0700.

Userspace then needs to set the uid and gid before issuing the "bind" command and the cache must've been chown'd to those IDs.

---
 fs/cachefiles/namei.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cachefiles/namei.c +2 -1
index 82219a8f6084..66482c193e86 100644
@@ -451,7 +451,8 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
 
 	ret = cachefiles_inject_write_error();
 	if (ret == 0) {
-		file = vfs_tmpfile_open(&nop_mnt_idmap, &parentpath, S_IFREG,
+		file = vfs_tmpfile_open(&nop_mnt_idmap, &parentpath,
+					S_IFREG | 0600,
 					O_RDWR | O_LARGEFILE | O_DIRECT,
 					cache->cache_cred);
 		ret = PTR_ERR_OR_ZERO(file);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · David Howells

Set mode 0600 on files in the cache so that cachefilesd can run as an unprivileged user rather than leaving the files all with 0. Directories are already set to 0700.

Userspace then needs to set the uid and gid before issuing the "bind" command and the cache must've been chown'd to those IDs.

---
 fs/cachefiles/namei.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cachefiles/namei.c +0 -0
index 82219a8f6084..66482c193e86 100644

fs/cachefiles/namei.c struct file *cachefiles_create_tmpfile(struct cachefiles_object *object) · line 458

Quoted 9 lines
fs/cachefiles/namei.c +2 -1
@@ -451,7 +451,8 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
 
 	ret = cachefiles_inject_write_error();
 	if (ret == 0) {
-		file = vfs_tmpfile_open(&nop_mnt_idmap, &parentpath, S_IFREG,
+		file = vfs_tmpfile_open(&nop_mnt_idmap, &parentpath,
+					S_IFREG | 0600,
 					O_RDWR | O_LARGEFILE | O_DIRECT,
 					cache->cache_cred);
 		ret = PTR_ERR_OR_ZERO(file);

Seems safe enough, and if it helps allow this to run unprivileged then:

Reviewed-by on v1 1/1
#2 lore raw
In reply to David Howells
Quoted 8 lines · David Howells

Set mode 0600 on files in the cache so that cachefilesd can run as an unprivileged user rather than leaving the files all with 0. Directories are already set to 0700.

Userspace then needs to set the uid and gid before issuing the "bind" command and the cache must've been chown'd to those IDs.

Quoted 6 lines

It seems useful on our side as well and safe:

Thanks,
Gao Xiang

maintainer Applied
#3 lore raw
In reply to David Howells
Quoted 9 lines · David Howells

Set mode 0600 on files in the cache so that cachefilesd can run as an unprivileged user rather than leaving the files all with 0. Directories are already set to 0700.

Userspace then needs to set the uid and gid before issuing the "bind" command and the cache must've been chown'd to those IDs.

[...]

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] cachefiles: Allow the cache to be non-root

      https://git.kernel.org/vfs/vfs/c/a64498ff493f