[GH-ISSUE #1927] firejail --list is empty, but firemon shows firejail processes #1288

Closed
opened 2026-05-05 07:48:07 -06:00 by gitea-mirror · 17 comments
Owner

Originally created by @chiraag-nataraj on GitHub (May 5, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1927

This is really weird, and is probably a product (in some way) of hidepid=2.

  1. Mount /proc with hidepid=2 (my exact mount options are nosuid,nodev,noexec,hidepid=2,gid=107)
  2. Launch something through firejail: firejail firefox
  3. Verify that firejail is in fact running: sudo pidof firejail
  4. Verify that firemon will show the relevant processes: sudo firemon
  5. firejail --list, sudo firejail --list, firejail --tree, and sudo firejail --tree all show nothing.

This seems to happen both with the current release version (0.9.52) and the current development version (0.9.53).

Originally created by @chiraag-nataraj on GitHub (May 5, 2018). Original GitHub issue: https://github.com/netblue30/firejail/issues/1927 This is really weird, and is probably a product (in some way) of `hidepid=2`. 1. Mount `/proc` with `hidepid=2` (my exact mount options are `nosuid,nodev,noexec,hidepid=2,gid=107`) 2. Launch something through `firejail`: `firejail firefox` 3. Verify that `firejail` is in fact running: `sudo pidof firejail` 4. Verify that `firemon` will show the relevant processes: `sudo firemon` 5. `firejail --list`, `sudo firejail --list`, `firejail --tree`, and `sudo firejail --tree` all show nothing. This seems to happen both with the current release version (0.9.52) and the current development version (0.9.53).
Author
Owner

@SkewedZeppelin commented on GitHub (May 5, 2018):

So firejail --list should output Error: /proc is mounted hidepid, you would need to be root to run this command, but isn't?

sudo firecfg --list should work, but isn't?

<!-- gh-comment-id:386833097 --> @SkewedZeppelin commented on GitHub (May 5, 2018): So `firejail --list` should output `Error: /proc is mounted hidepid, you would need to be root to run this command`, but isn't? `sudo firecfg --list` should work, but isn't?
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

So I expect firejail --list to be blank or give me an error, but I expect sudo firejail --list to give me the proper list. firemon works as expected (gives me the error as regular user and outputs the processes as root).

<!-- gh-comment-id:386833737 --> @chiraag-nataraj commented on GitHub (May 5, 2018): So I expect `firejail --list` to be blank or give me an error, but I expect `sudo firejail --list` to give me the proper list. `firemon` works as expected (gives me the error as regular user and outputs the processes as root).
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

Currently investigating. Running firejail --debug --list seems to list the proper command to call (/usr/local/bin/firemon --list), but I'm not getting output from that command.

<!-- gh-comment-id:386835619 --> @chiraag-nataraj commented on GitHub (May 5, 2018): Currently investigating. Running `firejail --debug --list` seems to list the proper command to call (`/usr/local/bin/firemon --list`), but I'm not getting output from _that_ command.
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

For some reason, firemon seems to act differently when called through firejail. Even if firemon doesn't have root permissions (which it needs with hidepid), it will try to enumerate everything when called through firejail, but not when called directly.

[edit]
I think I found an issue. When firemon is called through firejail, it thinks it has root privileges (i.e. getuid() returns 0) regardless of the calling user's UID. When firemon is invoked directly, getuid() returns the proper value. But I don't think this explains why sudo firejail --list doesn't work...going to continue digging. The issue seems to be with the pid_read() function, which seems to behave differently when called firemon is called through firejail (the PIDs which should have level 1 have level 0). Huh, the PID list itself seems to be different. This is really weird.

<!-- gh-comment-id:386841285 --> @chiraag-nataraj commented on GitHub (May 5, 2018): For some reason, `firemon` seems to act differently when called through `firejail`. Even if `firemon` doesn't have root permissions (which it needs with `hidepid`), it will try to enumerate everything when called through `firejail`, but not when called directly. [edit] I think I found an issue. When `firemon` is called through `firejail`, it thinks it has root privileges (i.e. `getuid()` returns 0) regardless of the calling user's UID. When `firemon` is invoked directly, `getuid()` returns the proper value. But I don't think this explains why `sudo firejail --list` doesn't work...going to continue digging. The issue seems to be with the `pid_read()` function, which seems to behave differently when called `firemon` is called through `firejail` (the PIDs which should have level 1 have level 0). Huh, the PID list itself seems to be different. This is really weird.
Author
Owner

@Vincent43 commented on GitHub (May 5, 2018):

Does executing firejail --list as root (without sudo) has same effect?

<!-- gh-comment-id:386841776 --> @Vincent43 commented on GitHub (May 5, 2018): Does executing `firejail --list` as root (without sudo) has same effect?
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

Yes. The PID list returned by pid_read is the same whether I run firejail --list as root or sudo firejail --list from my regular user. And it is definitely different from the actual PID list (which is return when I run firemon --list as root or through sudo). You can try it yourself by inserting printf("%i\n",pid) between pid_t pid = strtol(entry->d_name, &end, 10); and pid %= max_pids; in src/lib/pid.c.

<!-- gh-comment-id:386841849 --> @chiraag-nataraj commented on GitHub (May 5, 2018): Yes. The PID list returned by `pid_read` is the same whether I run `firejail --list` as root or `sudo firejail --list` from my regular user. And it is definitely different from the actual PID list (which is return when I run `firemon --list` as root or through sudo). You can try it yourself by inserting `printf("%i\n",pid)` between `pid_t pid = strtol(entry->d_name, &end, 10);` and `pid %= max_pids;` in `src/lib/pid.c`.
Author
Owner

@Vincent43 commented on GitHub (May 5, 2018):

I guess firejail is always dropping some privileges or manipulating something as it always run as root regardless of sudo or not. It doesn't have to be a bad thing actually.

<!-- gh-comment-id:386842057 --> @Vincent43 commented on GitHub (May 5, 2018): I guess firejail is always dropping some privileges or manipulating something as it always run as root regardless of sudo or not. It doesn't have to be a bad thing actually.
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

I suspect that is what is going on, since this seems to be a PID namespace of some sort. If so, we should deprecate firejail --list and just use firemon --list (probably same with --tree?).

<!-- gh-comment-id:386842114 --> @chiraag-nataraj commented on GitHub (May 5, 2018): I suspect that is what is going on, since this seems to be a PID namespace of some sort. If so, we should deprecate `firejail --list` and just use `firemon --list` (probably same with `--tree`?).
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

But it's also weird that this is only happening with hidepid enabled...

<!-- gh-comment-id:386842125 --> @chiraag-nataraj commented on GitHub (May 5, 2018): But it's also weird that this is _only_ happening with `hidepid` enabled...
Author
Owner

@Vincent43 commented on GitHub (May 5, 2018):

Without hidepid every user has the same view of processes (unless contained with firejail) so:
firemon, sudo firemon, firejail --tree have same effect.

<!-- gh-comment-id:386842230 --> @Vincent43 commented on GitHub (May 5, 2018): Without hidepid every user has the same view of processes (unless contained with firejail) so: `firemon`, `sudo firemon`, `firejail --tree` have same effect.
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

Found it. The culprit was dropping capabilities before calling firemon.

<!-- gh-comment-id:386842457 --> @chiraag-nataraj commented on GitHub (May 5, 2018): Found it. The culprit was dropping capabilities before calling `firemon`.
Author
Owner

@Vincent43 commented on GitHub (May 5, 2018):

I think the solution is to use firemon directly then.

<!-- gh-comment-id:386842623 --> @Vincent43 commented on GitHub (May 5, 2018): I think the solution is to use `firemon` directly then.
Author
Owner

@chiraag-nataraj commented on GitHub (May 5, 2018):

Cool 👍 Maybe we should provide a warning if hidepid is enabled and --list or --tree is used?

<!-- gh-comment-id:386842665 --> @chiraag-nataraj commented on GitHub (May 5, 2018): Cool :+1: Maybe we should provide a warning if `hidepid` is enabled and `--list` or `--tree` is used?
Author
Owner

@Vincent43 commented on GitHub (May 5, 2018):

It's interesting that when hidepid is enabled and user is in whitelisted group the behavior is quite the opposite:

$ firemon
Error: /proc is mounted hidepid, you would need to be root to run this command

$ firejail --list
1111:user::/usr/bin/firejail /usr/bin/firefox 
<!-- gh-comment-id:386842943 --> @Vincent43 commented on GitHub (May 5, 2018): It's interesting that when hidepid is enabled and user is in whitelisted group the behavior is quite the opposite: ``` $ firemon Error: /proc is mounted hidepid, you would need to be root to run this command $ firejail --list 1111:user::/usr/bin/firejail /usr/bin/firefox ```
Author
Owner

@chiraag-nataraj commented on GitHub (May 6, 2018):

Yeah, exactly. That's why I didn't see this bug/feature(?) until I removed my user from the whitelisted group.

<!-- gh-comment-id:386844788 --> @chiraag-nataraj commented on GitHub (May 6, 2018): Yeah, exactly. That's why I didn't see this bug/feature(?) until I removed my user from the whitelisted group.
Author
Owner

@Vincent43 commented on GitHub (May 6, 2018):

What I presented above is also incorrect as firemon should check if user is in trusted group. When running through firejail, firemon thinks it's root and ignores hidepid.

So, as for now if hidepid is used and user is in trusted group they should use firejail --list or sudo firemon --list (but using sudo misses the point of being in trusted group), and when user isn't in trusted group they should use sudo firemon --list.

Adding proper checks to firemon would be valuable.

<!-- gh-comment-id:386881635 --> @Vincent43 commented on GitHub (May 6, 2018): What I presented above is also incorrect as firemon should check if user is in trusted group. When running through firejail, firemon thinks it's root and ignores hidepid. So, as for now if hidepid is used and user is in trusted group they should use `firejail --list` or `sudo firemon --list` (but using `sudo` misses the point of being in trusted group), and when user isn't in trusted group they should use `sudo firemon --list`. Adding proper checks to firemon would be valuable.
Author
Owner

@netblue30 commented on GitHub (May 9, 2018):

Very cool bug!

Found it. The culprit was dropping capabilities before calling firemon.

I had to build a special capabilities filter for running under hidepid: 1576791f29

It's interesting that when hidepid is enabled and user is in whitelisted group the behavior is quite the opposite:
$ firemon
Error: /proc is mounted hidepid, you would need to be root to run this command

This is probably a second bug, thanks!

<!-- gh-comment-id:387776981 --> @netblue30 commented on GitHub (May 9, 2018): Very cool bug! > Found it. The culprit was dropping capabilities before calling firemon. I had to build a special capabilities filter for running under hidepid: https://github.com/netblue30/firejail/commit/1576791f29e8e9c83896fe1479e8bc099cca0d5a > It's interesting that when hidepid is enabled and user is in whitelisted group the behavior is quite the opposite: $ firemon Error: /proc is mounted hidepid, you would need to be root to run this command This is probably a second bug, thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#1288
No description provided.