Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardcoded tc command is not found on NixOS #6426

Closed
2 tasks done
Arcterus opened this issue Jul 31, 2024 · 5 comments · Fixed by #6431
Closed
2 tasks done

Hardcoded tc command is not found on NixOS #6426

Arcterus opened this issue Jul 31, 2024 · 5 comments · Fixed by #6431
Labels
enhancement New feature request networking Issues related to networking features (--net=, etc)

Comments

@Arcterus
Copy link

Arcterus commented Jul 31, 2024

Description

It seems that fshaper.sh hardcodes the path to tc, which causes setting bandwidth to fail on NixOS given that it has neither /sbin nor /usr/sbin. I think this could resolved fairly easily by just letting users set a variable with the path to tc or something like that. Alternatively, you could just allow configuring the path when building the project.

Steps to Reproduce

  1. Use NixOS.
  2. firejail --noprofile --name=blah --net=eth0
  3. firejail --bandwidth=blah set eth0 1 1

Expected behavior

The bandwidth to be set properly.

Actual behavior

An error saying that tc could not be found.

Behavior without a profile

No difference since this is an issue with the script's paths.

Additional context

This is basically the same issue as:

Environment

  • NixOS 24.05
  • Firejail version 0.9.72

Checklist

  • The issue is caused by firejail (i.e. running the program by path (e.g. /usr/bin/vlc) "fixes" it).
  • I have performed a short search for similar issues (to avoid opening a duplicate).

Log

Output of LC_ALL=C firejail --bandwidth=blah set enp5s0 1 1

Switching to pid 5297, the first child process inside the sandbox
Error: traffic control utility (tc) not found

Output of LC_ALL=C firejail --debug --bandwidth=blah set enp5s0 1 1

Switching to pid 5297, the first child process inside the sandbox
sbox exec: /bin/sh -c /nix/store/w2wdpq3m7qlhg13pwpwq0g80jlqcvwn7-firejail-0.9.72/lib/firejail/fshaper.sh --set eth0-5296 1 1 
Set caps filter 3000
Error: traffic control utility (tc) not found

@glitsj16
Copy link
Collaborator

glitsj16 commented Aug 1, 2024

Thanks for reporting this. Can you try the below patch and report back if that fixes traffic shaping on NixOS?

$ cat nixos-fshaper.patch
--- a/src/fshaper/fshaper.sh
+++ b/src/fshaper/fshaper.sh
@@ -3,13 +3,10 @@
 # Copyright (C) 2014-2024 Firejail Authors
 # License GPL v2
 
-TCFILE=""
-if [ -x "/usr/sbin/tc" ]; then
-	TCFILE="/usr/sbin/tc"
-elif [ -x "/sbin/tc" ]; then
-	TCFILE="/sbin/tc";
+if [ "$(command -v tc >/dev/null)" ]; then
+	TCFILE="$(command -v tc)"
 else
-	echo "Error: traffic control utility (tc) not found";
+	echo "Error: traffic control utility (tc) not found"
 	exit 1
 fi

@Arcterus
Copy link
Author

Arcterus commented Aug 1, 2024

No, it's still broken with that patch. I messed around with it a bit, and it looks like the PATH when that script executes is set to /no-such-path, so it can't find tc.

@glitsj16
Copy link
Collaborator

glitsj16 commented Aug 1, 2024

Thanks for testing!

Here's attempt 2:

$ cat nixos-fshaper.patch
--- a/src/fshaper/fshaper.sh
+++ b/src/fshaper/fshaper.sh
@@ -7,9 +7,13 @@
 if [ -x "/usr/sbin/tc" ]; then
 	TCFILE="/usr/sbin/tc"
 elif [ -x "/sbin/tc" ]; then
-	TCFILE="/sbin/tc";
+	TCFILE="/sbin/tc"
+elif [ -x "/run/current-system/sw/bin/tc" ]; then
+    TCFILE="/run/current-system/sw/bin/tc"
+elif [ -x "$(readlink -e $(which tc))" ]; then
+    TCFILE="$(readlink -e $(which tc))"
 else
-	echo "Error: traffic control utility (tc) not found";
+	echo "Error: traffic control utility (tc) not found"
 	exit 1
 fi

HTH

@rusty-snake
Copy link
Collaborator

Suggestion to use PATH=/usr/sbin:/sbin:/run/current-system/sw/bin command -v tc instead of this elif cascade.

@Arcterus
Copy link
Author

Arcterus commented Aug 2, 2024

I'll have to test it later today, but that should work given that it's basically what I did locally to get things functioning. However, I imagine the which command wouldn't be useful for anyone assuming PATH is set to /no-such-path on other distros too.

kmk3 pushed a commit to glitsj16/firejail that referenced this issue Aug 7, 2024
@kmk3 kmk3 added the enhancement New feature request label Aug 7, 2024
kmk3 added a commit that referenced this issue Aug 11, 2024
@kmk3 kmk3 added the networking Issues related to networking features (--net=, etc) label Sep 4, 2024
@kmk3 kmk3 changed the title Traffic shaping does not work with NixOS hardcoded tc paths do not work on NixOS Sep 5, 2024
@kmk3 kmk3 changed the title hardcoded tc paths do not work on NixOS Hardcoded tc command is not found on NixOS Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature request networking Issues related to networking features (--net=, etc)
Projects
Status: Done (on RELNOTES)
Development

Successfully merging a pull request may close this issue.

4 participants