Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 523304 - net-misc/tor - set capabilities to use ports <1000
Summary: net-misc/tor - set capabilities to use ports <1000
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Anthony Basile
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-20 14:27 UTC by Toralf Förster
Modified: 2015-03-07 18:54 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
torrc (torrc,726 bytes, text/plain)
2014-10-05 13:53 UTC, Toralf Förster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toralf Förster gentoo-dev 2014-09-20 14:27:21 UTC
the Tor project advises in:
https://www.torproject.org/docs/tor-relay-debian.html.en#after
to run a tor server with ORPort and DirPort at 443 and 80 respectively. This however means, that tor as a non-root user needs rights to access ports < 1024. An easy way to do this is (tested, works):

setcap 'cap_net_bind_service=+ep' /usr/bin/tor"

another approach is (not tested):

sysctl net.inet.ip.portrange.reservedhigh=0

/me wonders if an elog info should remind the user after upgrading its tor package related to these things ?
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2014-09-20 16:37:43 UTC
Why inform admins when you can actually provide with changes to the ebuild + run-time configuration?
Comment 2 Toralf Förster gentoo-dev 2014-09-20 16:44:04 UTC
The change is just necessary if tor is configured not in the default way (where ports 9001 and 9030 are used).

Well, OTOH I'm wondering if somebody should just run its own post-emerge script automatically after emerging tor ?
Comment 3 Anthony Basile gentoo-dev 2014-09-20 18:53:53 UTC
I don't understand the concern here.  tor can bind to ports < 1024.  It starts as root, binds and then drops privileges.  See below:

neworder ~ # cat /etc/tor/torrc
User tor
PIDFile /var/run/tor/tor.pid
Log notice syslog
DataDirectory /var/lib/tor/data

ORPort 443
DirPort 81

neworder ~ # /etc/init.d/tor restart
 * Stopping Tor ...                
 * Starting Tor ...
                                                                       
neworder ~ # netstat -ntlp | grep tor
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      11141/tor           
tcp        0      0 127.0.0.1:9050          0.0.0.0:*               LISTEN      11141/tor           
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      11141/tor           

neworder ~ # ps aux | grep tor
tor      11141  6.9  0.2 1321876 76020 ?       Sl   14:52   0:03 /usr/bin/tor -f /etc/tor/torrc --runasdaemon 1 --PidFile /var/run/tor/tor.pid
Comment 4 Toralf Förster gentoo-dev 2014-09-20 18:59:45 UTC
I set up a tor server a week ago (amd64), where exactly this did not work. That was the reason why I realized that. I got :

Sep 20 16:10:35.000 [notice] Read configuration file "/etc/tor/torrc".
Sep 20 16:10:35.000 [notice] Opening Directory listener on 0.0.0.0:80
Sep 20 16:10:35.000 [warn] Could not bind to 0.0.0.0:80: Permission denied
Sep 20 16:10:35.000 [notice] Opening OR listener on 0.0.0.0:443
Sep 20 16:10:35.000 [warn] Could not bind to 0.0.0.0:443: Permission denied
Sep 20 16:10:35.000 [notice] Closing no-longer-configured Directory listener on 0.0.0.0:9030
Sep 20 16:10:35.000 [notice] Closing no-longer-configured OR listener on 0.0.0.0:9001
Sep 20 16:10:35.000 [warn] Failed to parse/validate config: Failed to bind one of the listener ports.
Sep 20 16:10:35.000 [err] Reading config failed--see warnings above. For usage, try -h.
Sep 20 16:10:35.000 [warn] Restart failed (config error?). Exiting.

So I used setcap and it worked.

kernel : vanilla kernel 3.16.3.
Comment 5 Anthony Basile gentoo-dev 2014-09-20 19:17:27 UTC
(In reply to Toralf Förster from comment #4)
> I set up a tor server a week ago (amd64), where exactly this did not work.
> That was the reason why I realized that. I got :
> 
> Sep 20 16:10:35.000 [notice] Read configuration file "/etc/tor/torrc".
> Sep 20 16:10:35.000 [notice] Opening Directory listener on 0.0.0.0:80
> Sep 20 16:10:35.000 [warn] Could not bind to 0.0.0.0:80: Permission denied
> Sep 20 16:10:35.000 [notice] Opening OR listener on 0.0.0.0:443
> Sep 20 16:10:35.000 [warn] Could not bind to 0.0.0.0:443: Permission denied
> Sep 20 16:10:35.000 [notice] Closing no-longer-configured Directory listener
> on 0.0.0.0:9030
> Sep 20 16:10:35.000 [notice] Closing no-longer-configured OR listener on
> 0.0.0.0:9001
> Sep 20 16:10:35.000 [warn] Failed to parse/validate config: Failed to bind
> one of the listener ports.
> Sep 20 16:10:35.000 [err] Reading config failed--see warnings above. For
> usage, try -h.
> Sep 20 16:10:35.000 [warn] Restart failed (config error?). Exiting.
> 
> So I used setcap and it worked.
> 
> kernel : vanilla kernel 3.16.3.

Were those ports in use?  Notice in my example I have `DirPort 81` and not `DirPort 80`.  The reason is that i have apache on 80.  If I use 80, I get a permission denied in the logs.
Comment 6 Toralf Förster gentoo-dev 2014-09-20 19:33:21 UTC
It is a dedicated Tor server, nothing else (except BOINC to keep the CPU happy), so all ports are free.

I guess, that "/etc/init-d/tor reload" might be the culprit for the issue I had b/c at this point tor already gave away its capability, or ?

Probably an "/etc/init.d/tor restart" would worked too but I tried to avoid a downtime.
Comment 7 Anthony Basile gentoo-dev 2014-10-04 11:45:58 UTC
(In reply to Toralf Förster from comment #6)
> It is a dedicated Tor server, nothing else (except BOINC to keep the CPU
> happy), so all ports are free.
> 
> I guess, that "/etc/init-d/tor reload" might be the culprit for the issue I
> had b/c at this point tor already gave away its capability, or ?
> 
> Probably an "/etc/init.d/tor restart" would worked too but I tried to avoid
> a downtime.

So I'm not sure what to do with this bug right now because I can't confirm it.  Can I see your config file.  Remove any potentially private information.
Comment 8 Toralf Förster gentoo-dev 2014-10-05 13:53:24 UTC
Created attachment 386080 [details]
torrc

well, there are no secrets in it
Comment 9 Jeremy Olexa (darkside) (RETIRED) archtester gentoo-dev Security 2014-11-27 04:07:04 UTC
This bug is more useful if you consider a hibernating relay that can't "rebind" to a reserved port. However, I don't think setting caps in an ebuild is the right way.
Comment 10 Anthony Basile gentoo-dev 2015-03-07 18:54:45 UTC
Okay I thought about this for a while and I'm not going to do anything.  1) I really want to avoid setting caps in an ebuild.  I know we're doing that right now with things like ping and we are starting to push out stage3's with caps set, but the difference here is that it is not essential to tor's operation, and in fact sometimes undesireable, whereas it is essential for say ping with no setuid.  2) There's a lot of options for tor.  Its a complex beast and I'm not going to complicate matters with a bunch of pkg_postinst() messages.  People using tor as a server will have to read the upstream documentation.