Filesystem is root-only readable (user-owned mount namespace) #5318
Replies: 9 comments 14 replies
-
Oh, I see that the firejail/src/firejail/sandbox.c Line 671 in 9fed798 I think the big difference is that the |
Beta Was this translation helpful? Give feedback.
-
Huh, maybe using https://man.archlinux.org/man/setfsuid.2 would fix this? |
Beta Was this translation helpful? Give feedback.
-
The unsandboxed man command can read that dir fine on my arch linux box as regular, non-root user. So I'm wondering, how did you test this statement exactly?
|
Beta Was this translation helpful? Give feedback.
-
You're not running
|
Beta Was this translation helpful? Give feedback.
-
Unsandboxed processes cannot read this path for sandboxed processed. E.g.: I expect an unsandboxed |
Beta Was this translation helpful? Give feedback.
-
Answer: #5193 (comment) |
Beta Was this translation helpful? Give feedback.
-
You mentioned on the linked answer:
I want my current user to be able to access these paths. It seems that this could be fixed by changing firejail so that the user-ns is owned by my current user instead of root. Do you think this is a good idea too? It would possibly improve the situation with flatpak/xdg-desktop-portal#741. Currently |
Beta Was this translation helpful? Give feedback.
-
I gave this a quick try to see what breaks: diff --git a/src/firejail/main.c b/src/firejail/main.c
index c7da3c95c..929f3a6a6 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -2989,7 +2989,7 @@ int main(int argc, char **argv, char **envp) {
errExit("pipe");
// clone environment
- int flags = CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWUTS | SIGCHLD;
+ int flags = CLONE_NEWPID | CLONE_NEWUTS | SIGCHLD;
// in root mode also enable CLONE_NEWIPC
// in user mode CLONE_NEWIPC will break MIT Shared Memory Extension (MIT-SHM)
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index 9299268a3..f706ba47d 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -641,6 +641,16 @@ int sandbox(void* sandbox_arg) {
// Get rid of unused parameter warning
(void)sandbox_arg;
+ EUID_USER();
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNS) != 0)
+ errExit("creating user namespace");
+
+ printf("unshare ok\n");
+ EUID_ROOT();
+
pid_t child_pid = getpid();
if (arg_debug)
printf("Initializing child process\n"); This fails very quickly:
It seems that the firejail child process needs to hold Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Okay, so I've failed to implement this -- my C skills aren't good enough for such a task, and I'm also not familiar enough with the low level APIs involved here. I don't think I'll be able to implement this myself, so I'll summarize my thoughts in hopes that someone else can pick this up. I do still believe this change is very feasible. Basically, instead of creating a new filesystem namespace as root I think firejail should be able to create a new user namespace (as the non-root user calling firejail). The results is essentially a different filesystem namespace which belongs to the current user [on the host]. Because the current user would be able to access Additionally, this would be "one less thing" done by firejail as root. While firejail as a whole still needs to be run as root, it's one less bit of code that runs as root, paving the one to some day potentially not requiring setuid at all. |
Beta Was this translation helpful? Give feedback.
-
When running something like
man
via firejail, the path/proc/356611/root
is root-owned and only root-readable. My non-root user cannot read this directory at all, even from an unsandboxed process (e.g.: evenls
fails).As far as I understand,/
for firejail'd processes is also mounted using root-priviledges (please do correct me if I'm wrong on this item).Would it be possible to mount this using user namespaces alone? E.g.: Bubblewrap mounts theses filesystems in a way that the unsandboxed user can read from it.
I tried trying to figure out the inner workings of this on Firejail and Bubblewrap, but I'm clearly too unfamiliar with both codebases to figure out enough by myself.
This is remotely related to #5157
I'd also be curious how this would interoperate with flatpak/xdg-desktop-portal#741
Beta Was this translation helpful? Give feedback.
All reactions