mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #3678] Error: too long environment variables, please use --rmenv #2314
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#2314
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 @simonfxr on GitHub (Oct 18, 2020).
Original GitHub issue: https://github.com/netblue30/firejail/issues/3678
I just ran into this error.
My LS_COLORS env var is rather big (~5kb), which lead to:
Error: too long environment variables, please use --rmenvI also can not work around the problem by passing
--rmenv=LS_COLORSsettingrmenv LS_COLORSin globals.local does also not work.The problem is that calling
unsetenv(*ptr)in main does not modify theenvppassed tomain(),extern char ** environ;should be used instead. Also I guess, that the profile is loaded after the check, so setting it in a profile won't work. Maybe this should be supported?Also I don't understand what this check is trying to accomplish, any explanation would be appreciated.
For now I can just increase the limit by patching and recompiling myself.
@ghost commented on GitHub (Oct 18, 2020):
There is more detailed info on protecting against
stack smashing attackin https://github.com/netblue30/firejail/pull/3325, including a few other things you might try.While patching and recompiling might 'fix' your issue, please be aware of the potential pitfalls of doing so in this context. The thread referenced above should provide a safer way out for your LS_COLORS issue.
@simonfxr commented on GitHub (Oct 18, 2020):
@glitsj16 Thx for the link, that makes sense. However that still does not address the problem with the
--rmenvflag logic, that patch in #3674 does not work, since the loop over the env variable uses theenvpargument, afaict the contents ofenvpare not modified byunsetenv()(see OP). Maybe it would be a better idea, to guard against the total environment size and not the size of single env entries.@topimiettinen commented on GitHub (Oct 18, 2020):
There's also some info on #3350. I think the proper fix to finalize #3322. Then the environment for Firejail itself is controlled and only a very small number of whitelisted, length checked variables are allowed inside the set-uid program. The variables are restored for the application itself and then the length checks could be relaxed. But even if #3322 was ready, I don't think it would be a good idea to push it just now when we're close to release.
Checking total environment size is a nice idea. Now we allow 256*(4096B+32B) = ~1MB of variables, when in reality maybe 64kB could be plenty while still allowing more or larger variables. Though this would be obsolete with #3322.
@rusty-snake commented on GitHub (Nov 9, 2020):
So #3322 fixes this, right?
@topimiettinen commented on GitHub (Nov 10, 2020):
I prefer #3322, because it protects Firejail fully but it also allows applications to get less restricted environment. To finalize it, I still have to check all paths where Firejail executes something to ensure that the set of env variables is correct for each case.
@ghost commented on GitHub (Apr 4, 2021):
I also ran into the same error message using the
gitcommand what is pretty strange since there is no profile for git in/etc/firejail/nor anywhere else in my home. Next thing isgit statusworks as usualbut
git pullreturnsso there must be firejail working in the background when I use
git pull. I rangit pullwith stracegit pull.strace
and
git statusgit status.strace
The main difference I've found so far is the last call before the error happens in the
git pull.stracefile: The file/usr/lib/git-core/gitis called which is a link to /usr/bin/git on my systemI don't know why this error happens, at all. Ok my PS1 and _OLD_VIRTUAL_PS1 variables are pretty long which produce a beautiful prompt I really want to keep. Running
works as expected. But this doesn't explain why firejail is involved in the plain
git pullcommand but not ingit status. I don't see why firejail is involved at all runninggit.firecfg --list | grep gitalso doesn't return anything.My setup
apparmor (3.0.1)
yes running
firejail --versionalso complains about theError: too long environment variables, please use --rmenvOS=Archlinux with kernel 5.10.27
git --versionworks fine@ghost commented on GitHub (Apr 5, 2021):
@MaelStor Odd indeed. Firejail has had a git.profile for a while now, and it definately is in the 0.9.64.4 package on Arch. Can you confirm there is no /etc/firejail/git.profile on your system? Also, what does
which -a gitshow? Try settingquiet-by-default yesin /etc/firejail/firejail.config temporarily to make output from a firejailed git stand out more prominently.@ghost commented on GitHub (Apr 5, 2021):
Sorry, yes indeed there is a profile for git
Seems I mixed things up with
firecfg --listwhat doesn't show git and there is no link in/usr/local/binas shown above, so it shouldn't be active or am I wrong?I tried running the same
gitcommands in bash instead of zsh with another prompt etc and added a variable quiet as long as my zsh PS1 (~7000 bytes) to the environment withexport SOMEVAR=$(python -c 'print("A"*7000)')with exactly the same result.Setting
quiet-by-defaulthad no effect:@rusty-snake commented on GitHub (Apr 5, 2021):
It's
sshwhich is called bygit pull.@ghost commented on GitHub (Apr 5, 2021):
@glitsj16 @rusty-snake Thanks. Now it makes sense. However putting rmenv into a local profile for ssh
didnt' help. I still cannot run git commands if ssh is involved because I cannot pass the
--rmenvflag tofirejail /usr/bin/ssh. I would love to keep ssh sandboxed but I don't see how to get rid of the error other than removing the/usr/local/bin/sshlink. What actually was the only option I've found that helped. Do you know any other possibilities?In addition I always have to run
firejailwithfirejail --rmenv=PS1 --rmenv=_OLD_VIRTUAL_PS1no matter which subcommand (--list,--treeetc.) follows. Is there a way to remove environment variables in the top level like the/etc/firejail/firejail.config? I'm currently doing it with an alias but an option would be great.IMHO It would help if I would be noticed about running ssh in a sandbox when I execute git, like it happens when running a program directly with firejail not in quiet mode. Also in the debug output of
firejail --debug /usr/bin/git pullthere is no indication that ssh profiles are loaded.@rusty-snake commented on GitHub (Apr 5, 2021):
Use firemon (e.g.
sudo firemon)There is no ssh.profile loaded if you firejail git.
@ghost commented on GitHub (Apr 5, 2021):
Using
firemonin my usual environment didn't work. I guess firejail fails because of too long environment variables at an early stage and therefore nothing is recorded. And it doesn't solve the problem to getsshworking when it is invoked bygitand I've got long environment variables.However if I switch to bash with a shorter PS1 I've got
firemonworking and it shows me thatsshis invoked. It's not so obvious like the firejail messages about loaded profiles when starting a program withfirejail $programbut I guess I get my stuff working withfiremon, which is great by the way.@rusty-snake commented on GitHub (Apr 5, 2021):
PS1and_OLD_VIRTUAL_PS1are the only envvar which are too long on your system. Why do you export them?@ghost commented on GitHub (Apr 5, 2021):
Yes these are the only ones. It's not me who's exporting them, at least in zsh. I've tried unsetting themwith
export PS1=in my .zshrc at the very end but they are still in my environment.EDIT: Got it working. I've overseen a command at the end of the file
UPDATE: Removing the PS1 from the environment works only as long as I'm not entering a git repository. After that the PS1 and _OLD_VIRTUAL_PS1 variables pop up again in my environment.
@haarp commented on GitHub (Apr 6, 2021):
It would be great if I could get rid of the
firejail='firejail --rmenv=LS_COLORS'alias on my system. alas,rmenvin the config doesn't work :(@ghost commented on GitHub (Apr 6, 2021):
@haarp Have you tried a bash alias yet as suggested in #3325?
@haarp commented on GitHub (Apr 6, 2021):
Any alias is just a workaround tho. A real fix would either allow rmenv in the config, or simply not choke on long env variables ;)
@ghost commented on GitHub (Apr 6, 2021):
We accept PR's. Feel free to provide one that offers at least the same level of protection against stack smashing attacks as currently implemented. You can always drop LS_COLORS if security > shiny setups.
@haarp commented on GitHub (Apr 6, 2021):
Wait, this is intentional? My impression was it was just a bug. Tho I admit it makes sense to bail out before config parsing begins.
In that case, the bail-out message could probably clarify that only
--rmenvworks, notrmenvin the config, so smartasses like me don't attempt it ;)btw, it's just not shiny. I have other long env variables for varaious reasons, that my alias needs to exclude.
@ghost commented on GitHub (Apr 6, 2021):
How about using an extra environment.global file in
/etc/firejailwhich blacklists environment varaibles, so I would have more control over the environment at an early stage. A simple list of environment variables one per line would be enough for me but perhaps you see better possibilities.