mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #2267] Why does calling getpgrp(2) from a sandboxed process return 0? #1516
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#1516
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mqudsi on GitHub (Nov 21, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/2267
Hi there! I'm a member of the fish dev team, and we're trying to understand why fish won't run under firejail.
As a shell, the most important job fish has launching and managing child processes (job control). That includes creating process groups, marshalling the terminal between various processes and process groups, etc. Part of this requires fish to be aware of its own pgid, but calls to
getpgrpreturn0as the pgid instead of the actual pgroup when running under firejail.From the setpgid(2) man page:
As you can see, while
0may be a valid value to pass intosetpgid, it does not represent a valid pgrp in that case (instead it tellssetpgidto use the calling application's process id) and it is not a valid result of agetpgrp.While we can theoretically patch our entire codebase to try and handle cases where we call libc apis with
0as the pgid in question, I'm trying to understand why this is happening in the first place (I also disagree with some fellow devs and users who feel this is a bug in fish and not a issue with firejail, as I put the onus on the sandbox to create as realistic an environment as possible to maximize compatibility with sandboxed applications).Could you advise us on why this happens and what we are supposed to do with a 0 pgroup? Is there a way to prevent firejail from intercepting the call to getpgrp(2) for
fishin its firejail profile given its needs as a shell?cc @faho @santpent
@SkewedZeppelin commented on GitHub (Nov 21, 2018):
So firejail does no intercepting or shimming of syscalls, it can only restrict them via seccomp filters.
As for the original report (https://github.com/fish-shell/fish-shell/issues/5295), I can't actually reproduce it in anyway with fish 2.7.1 under Fedora 29. All of the following work just fine:
Maybe this is an AppArmor issue? @Vincent43
@mqudsi commented on GitHub (Nov 21, 2018):
@SkewedZeppelin thanks for the reply and for checking in. fish 2.7.1 contained code that would assign fish to its own pgroup on launch, so it didn't run into this issue. You'd have to build it from
masterto run into it.@SkewedZeppelin commented on GitHub (Nov 21, 2018):
@mqudsi ah, apologies I missed that part
built from git, I can indeed reproduce when using the --shell option.
@crass commented on GitHub (Nov 21, 2018):
As @SkewedZeppelin noted, firejail is not intervening here.
As can be seen from the first command, the first process in a new pid namespace has a process group of
0. The above commands show that bothbashanddashchange their process groups when job control is enabled (default), and that dash does not set the process group when job control is turned off.On reviewing the dash source,
setpgidis called when job control is turned on with thepgidbeing set to thepidof the main shell process.I don't think this is an issue for most programs either way, but we could do a
setpgid(0,1)right before spawning the jailed process. I suspect that would resolve these types of issues when a program wants to change a process group and then change it back to the previous process group id.@mqudsi commented on GitHub (Nov 22, 2018):
Thank you very much for the reply and the explanation.
fishperforms similar process group manipulations in interactive mode, but the apparent reuse of pgid 0 was running afoul of code that wasn't built with namespaces in mind.Personally, my *nix flavor of choice is FreeBSD and I was wholly unfamiliar with the underpinnings of Linux namespaces. I'm still surprised that 0 is a valid user mode pgroup in the new namespace, as it invalidates the presumption that 0 is the kernel and 1 is
init- a presumption hard baked intofish.Thanks for taking the time to explain this! Hopefully fish 3.0 should work under firejail out-of-the-box once we get this addressed.