Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 407195 - net-misc/openvpn: path to network tools get hardcoded at build time
Summary: net-misc/openvpn: path to network tools get hardcoded at build time
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal with 5 votes (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
: 410781 431604 434482 444444 444768 444842 451320 454258 466908 (view as bug list)
Depends on:
Blocks: 392757
  Show dependency tree
 
Reported: 2012-03-06 23:03 UTC by SpanKY
Modified: 2018-04-15 10:18 UTC (History)
25 users (show)

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


Attachments
use execvpe if available (openvpn-execvpe.patch,3.36 KB, patch)
2012-11-26 10:01 UTC, SpanKY
Details | Diff
Dynamic iproute support and detection (dynamic-iproute-detection.patch,5.33 KB, patch)
2013-04-17 22:56 UTC, Josh Cepek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description SpanKY gentoo-dev 2012-03-06 23:03:18 UTC
looks like when i emerge openvpn, it records the full path to networking utils:

checking for ifconfig... /bin/ifconfig
checking for ip... /sbin/ip
checking for route... /bin/route
checking for netstat... /bin/netstat

it then uses those at runtime:
Mar 06 18:00:10 [openvpn] /bin/ifconfig tun0 10.8.8.2 pointopoint 10.8.8.3 mtu 1500
Mar 06 18:00:10 [openvpn] /bin/route add -net 10.8.8.0 netmask 255.255.255.0 gw 10.8.8.3

that's obviously no good if the tools change location, which they are.  consider a previous run that was failing:
Mar 06 17:52:35 [openvpn] /sbin/ifconfig tun0 10.8.8.2 pointopoint 10.8.8.3 mtu 1500
Mar 06 17:52:35 [openvpn] Linux ifconfig failed: could not execute external program
Mar 06 17:52:35 [openvpn] Exiting

openvpn needs to discover these things at runtime via $PATH
Comment 1 Richard Grenville 2012-03-08 01:15:41 UTC
openvpn records 4 paths in its configure: IFCONFIG_PATH, IPROUTE_PATH, ROUTE_PATH, NETSTAT_PATH. It provides a runtime parameter '--iproute' to specify the path to "ip", overriding the hardwired IPROUTE_PATH, if openvpn is built with 'iproute2' USE flag. And actually openvpn[iproute2] does not use the other 3 hardwired paths at all. So for openvpn[iproute2] it's possible to completely solve the problem by letting openvpn's initscript discover the path to "ip" dynamically, and pass it to openvpn with --iproute, just a few extra lines in /etc/init.d/openvpn. (Note, though, openvpn[-iproute2] probably exits when it catches '--iproute' as an "unrecognized option".)

For openvpn[-iproute2] things look tricky and a patch is definitely required. Another issue is openvpn always uses hardwired paths on non-Linux systems like Gentoo/FreeBSD.
Comment 2 Bernard Cafarelli gentoo-dev 2012-03-13 15:55:24 UTC
With net-tools-1.60_p20120127084908 (which moves ifconfig location), this also means openvpn recompilation is needed after update at the moment
Comment 3 Alon Bar-Lev 2012-05-05 19:37:21 UTC
Reason: security product cannot search tools in path.

Recommendation:
USE="iproute2"

And then you have a configuration option of iproute to specify which tool to use.
Comment 4 SpanKY gentoo-dev 2012-05-05 23:24:41 UTC
that's crap.  if you can run openvpn as your user, you can sure as well manipulate its memory at runtime and tell it to do whatever you want.

if you're launching it as root, you certainly can control the initial env.
Comment 5 Dirkjan Ochtman (RETIRED) gentoo-dev 2012-05-14 07:55:50 UTC
*** Bug 410781 has been marked as a duplicate of this bug. ***
Comment 6 SpanKY gentoo-dev 2012-08-16 17:44:58 UTC
*** Bug 431604 has been marked as a duplicate of this bug. ***
Comment 7 SpanKY gentoo-dev 2012-09-10 05:09:05 UTC
*** Bug 434482 has been marked as a duplicate of this bug. ***
Comment 8 SpanKY gentoo-dev 2012-11-26 08:14:58 UTC
*** Bug 444768 has been marked as a duplicate of this bug. ***
Comment 9 Dirkjan Ochtman (RETIRED) gentoo-dev 2012-11-26 08:17:10 UTC
Perhaps bug 444444 is also a duplicate?
Comment 10 SpanKY gentoo-dev 2012-11-26 08:18:01 UTC
*** Bug 444444 has been marked as a duplicate of this bug. ***
Comment 11 Permjacov E. A. 2012-11-26 08:49:59 UTC
Tell me that, if it was confirmed more then half year ago, why it is not fixed yet ?
Comment 12 Dirkjan Ochtman (RETIRED) gentoo-dev 2012-11-26 08:57:17 UTC
So far, upstream has not wanted to do anything about it.
Comment 13 SpanKY gentoo-dev 2012-11-26 09:59:59 UTC
my reading of the code indicates they use execve() because they want to pass down the argv/envp arrays.  that last part is important -- while there is an execvpe(), it is not portable.

then again, openvpn is already enabling AC_GNU_SOURCE when it's available, so that isn't a big deal.

otherwise, the logic would have to use execvp and manually sync the environ after the fork() ...
Comment 14 SpanKY gentoo-dev 2012-11-26 10:01:44 UTC
Created attachment 330600 [details, diff]
use execvpe if available

i've only done a compile-time test.  don't have local access to my main system atm to do a runtime test.
Comment 15 Dirkjan Ochtman (RETIRED) gentoo-dev 2012-11-26 10:11:18 UTC
In the mean time, rebuilding openvpn would work for users who run into this. I just talked to upstream, and they're working on solving this for 2.4 using netlink sockets.
Comment 16 Markos Chandras (RETIRED) gentoo-dev 2012-11-26 20:18:52 UTC
*** Bug 444842 has been marked as a duplicate of this bug. ***
Comment 17 Anton Bolshakov 2012-11-30 06:32:02 UTC
Why wouldn't you push openvpn-r1 for now, so users would be forced to rebuild it?
I hit that bug too and it cased me unnecessary downtime.
Comment 18 Markos Chandras (RETIRED) gentoo-dev 2012-11-30 09:18:36 UTC
Yes a revbump with adjusted dependencies it a good workaround at the moment
Comment 19 Alex Efros 2012-11-30 13:17:37 UTC
(In reply to comment #3)
> Reason: security product cannot search tools in path.
> 
> Recommendation:
> USE="iproute2"
> 
> And then you have a configuration option of iproute to specify which tool to
> use.

Sorry for off-topic, but where I can find documentation/more info about this?
I mean, what's the difference for end-user between using net-tools or iproute2 internally by openvpn? And what is iproute options you're talking about?
Comment 20 kfm 2012-11-30 13:26:19 UTC
(In reply to comment #19)
> (In reply to comment #3)
> > Reason: security product cannot search tools in path.
> > 
> > Recommendation:
> > USE="iproute2"
> > 
> > And then you have a configuration option of iproute to specify which tool to
> > use.
> 
> Sorry for off-topic, but where I can find documentation/more info about this?
> I mean, what's the difference for end-user between using net-tools or
> iproute2 internally by openvpn? And what is iproute options you're talking
> about?

The difference is in whether openvpn uses "ip" instead of "route" from net-tools to add a route. Some of us prefer to use iproute2 exclusively. See http://inai.de/2008/02/19 for the reasons.

This bug concerns the issue whereby openvpn fails because the the location of the ip binary has changed as of a recent iproute2 package update.
Comment 21 kfm 2012-12-01 00:35:43 UTC
(In reply to comment #14)
> Created attachment 330600 [details, diff] [details, diff]
> use execvpe if available
> 
> i've only done a compile-time test.  don't have local access to my main
> system atm to do a runtime test.

I just tested this based on the upgrade scenario that was my undoing. I built openvpn with this patch and, after restarting, it invoked /bin/ip correctly. Then I downgraded iproute2 from 3.6.0 to 3.3.0, which installs to /sbin/ip. I restarted openvpn and it was still able to invoke ip. Excellent.
Comment 22 Dirkjan Ochtman (RETIRED) gentoo-dev 2013-01-11 08:22:06 UTC
*** Bug 451320 has been marked as a duplicate of this bug. ***
Comment 23 wuodan 2013-01-11 20:45:31 UTC
Was about to add symlinks to get openvpn to work.
The patch smoothly solved it - thanks.
I'd vote for making an openvpn-2.2.2-r1.ebuild with the patch until upstream reacts.
Comment 24 Sergei Trofimovich (RETIRED) gentoo-dev 2013-01-11 22:01:46 UTC
How about just pass non-paths to ./configure?

https://bugs.gentoo.org/show_bug.cgi?id=451320#c0
Comment 25 SpanKY gentoo-dev 2013-01-11 22:35:18 UTC
(In reply to comment #24)

have you actually tested that beyond a configure+compile ?  i'm guessing not.  as the documentation for execve() states, the first argument is *not* searched via $PATH, it's executed directly.  thus if you don't give it a full path, it'll implicitly run $PWD/filename.

a simple test shows that:
$ echo 'main(){execve("true",0,0);}' | gcc -x c -o a.out -
$ strace -eexecve ~/a.out 
execve("./a.out", ["./a.out"], [/* 73 vars */]) = 0
execve("true", [0], [/* 0 vars */]) = -1 ENOENT (No such file or directory)
$ cd /bin
$ strace -eexecve ~/a.out 
execve("/home/vapier/a.out", ["/home/vapier/a."...], [/* 74 vars */]) = 0
execve("true", [0], [/* 0 vars */]) = 0
Comment 26 Sergei Trofimovich (RETIRED) gentoo-dev 2013-01-11 23:39:50 UTC
(In reply to comment #25)

Eh, right, my bad. Sorry for the noise.

Sat Jan 12 02:37:30 2013 ifconfig tun0 172.16.0.4 pointopoint 172.16.0.1 mtu 1500                                              
Sat Jan 12 02:37:30 2013 Linux ifconfig failed: could not execute external program
Comment 27 Ben Kohler gentoo-dev 2013-01-27 16:15:25 UTC
*** Bug 454258 has been marked as a duplicate of this bug. ***
Comment 28 Josh Cepek 2013-04-17 20:49:04 UTC
All of the net-tools package, including ifconfig, is a pile of unmaintained defunct crap (just look at the recent commit history upstream - it's all small stop-gap patches to prevent it from breaking for systems that still need it.)

If it's causing problems, let's just require iproute2 as a dep and be done with it. ifconfig uses the old 2.2 and earlier kernel ioctl interface and upstream (the net-tools maintainers) have no interest in changing that. The `ip` utility and all others provided by iproute2, are the "new standard" and use the kernel interface introduced in 2.4. Unless someone actually is running a 2.2 kernel, such a dep won't cause an undue burden.

I'm very much in favor of requiring iproute2 verses applying needless patches to upstream code for the sole purpose of playing nice with effectively deprecated tools. At the very least, don't patch upstream code when --enable-iproute2 is passed to ./configure since it's not required.
Comment 29 SpanKY gentoo-dev 2013-04-17 21:08:16 UTC
(In reply to comment #28)

err, net-tools is maintained just fine.  we aren't generally adding extended interfaces when iproute2 already supports it, but for most people, net-tools gets the job done fine.

but your bile is misdirected.  requiring iproute won't affect this bug at all.  openvpn hardcodes absolute paths to net-tools and iproute2 equally.
Comment 30 Josh Cepek 2013-04-17 21:29:03 UTC
(In reply to comment #29)

Replying to the important bit first,

> but your bile is misdirected.  requiring iproute won't affect this bug at
> all.  openvpn hardcodes absolute paths to net-tools and iproute2 equally.

Not quite since iproute2 didn't go through a binary re-location. You're right that it would suffer the same problem if it was installed to $PREFIX/usr/sbin/ instead of $PREFIX/sbin/ though. Since that hasn't happened, forcing iproute2 as a USE flag would indeed fix the issue people have reported here.


> err, net-tools is maintained just fine.  we aren't generally adding extended
> interfaces when iproute2 already supports it, but for most people, net-tools
> gets the job done fine.

Interesting. Upstream recently "deprecated" (their words, not mine) netstat. So much for "maintained just fine" it would seem. We're past the 2.4 kernel stage now, and it's time to use tools that reflect that. The replacement for netstat you ask? Upstream (net-tools) maintainers tell you to use iproute2 (ip and ss.) Go figure.

Citation: http://net-tools.git.sourceforge.net/git/gitweb.cgi?p=net-tools/net-tools;a=commit;h=77d0c1b2a55c1af31cce4df68da7bf93c8155111
Comment 31 SpanKY gentoo-dev 2013-04-17 21:51:08 UTC
(In reply to comment #30)

yes, it did.  i know it did because i made the commit.

<iproute-3.5.1: /sbin/ip
>=iproute-3.5.1: /bin/ip

i'm aware of net-tools upstream status.  if you read the git history, you'll see i've personally made plenty of commits to it.
Comment 32 Josh Cepek 2013-04-17 22:56:00 UTC
Created attachment 345840 [details, diff]
Dynamic iproute support and detection

Sorry, you're quite right about the path change to iproute2's ip binary as well.

So, moving forward, Comment #3 shows that --iproute exists as a runtime solution to this problem.

I've attached a patch (dynamic-iproute-detection.patch) that uses iproute2 as a dep and dynamically picks up the location to pass to the --iproute argument to openvpn. This feature is only enabled under Linux, and controllable through the /etc/conf.d/openvpn config file.

This way, changes to the path of 'ip' will not break by default as a user would have to explicitly disable the preference of this automatic detection.
Comment 33 SpanKY gentoo-dev 2013-04-18 01:47:55 UTC
(In reply to comment #32)

i think the patch i already posted to use execvpe is a lot less invasive
Comment 34 kfm 2013-04-19 19:45:43 UTC
(In reply to comment #33)
> (In reply to comment #32)
> 
> i think the patch i already posted to use execvpe is a lot less invasive

It certainly is. Did either yourself or Dirkjan propose it upstream? Assuming they're not interested, is there any chance of your patch being incorporated in Gentoo anyway?
Comment 35 SpanKY gentoo-dev 2013-04-19 20:13:28 UTC
(In reply to comment #34)

i've only tested+posted it here.  i'm not familiar with openvpn upstream, so i haven't bothered posting it.  feel free to run with it :).
Comment 36 Dirkjan Ochtman (RETIRED) gentoo-dev 2013-04-20 20:31:42 UTC
See comment 15 on what upstream's ideas are.
Comment 37 Josh Cepek 2013-04-20 20:51:30 UTC
Gentoo has always been a distribution about choice. The source changes proposed to the upstream openvpn codebase remove an important security feature to prevent overloading the environment's path. While this may not be a concern for some people, the proposed change makes it so for everyone building from the ebuild, including users who care about such security changes.

And the proposed benefit? Why are we considering a patch that removes a by-design security feature all so some users don't need to rebuild if the path of the ip or ifconfig binary changes? At the very least, provide an interface for users who do not wish to reduce the security of their system by not strictly controlling the environment, as the code is designed to do.

OpenVPN goes out of its way to act as a security product; please don't undermine that goal for the convenience of avoiding a recompile of a single package. The patch I've proposed is less "invasive" in the sense that it does not force users to trade security for minor convenience. In fact, I'd recommend the default be changed to "no" in my patch; then users may decide to make the security tradeoff themselves if this is a big enough concern for their use-case. And if upstream does use netlink sockets for 2.4, this all goes away anyway.
Comment 38 Gordon Pettey 2013-04-20 20:59:06 UTC
I have to agree with Josh. Arguing that changing the code base is somehow less invasive than altering some configuration files is utterly illogical.
Comment 39 SpanKY gentoo-dev 2013-04-21 03:06:05 UTC
(In reply to comment #37)

waving your hands and saying "it's for security!" is crap.  openvpn isn't set*id which means the person executing the openvpn programs have full control over the environment, the runtime memory, and just about everything else.  hardcoding paths to programs in a futile attempt to "protect" against the $PATH env var being set to malicious locations is entirely pointless and adds 0 security.
Comment 40 SpanKY gentoo-dev 2013-04-23 18:46:25 UTC
*** Bug 466908 has been marked as a duplicate of this bug. ***
Comment 41 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2013-09-12 07:54:40 UTC
bug 444444 was is a dupe of this bug, so it's a loop and won't cross itself off.

what's the next step here?
Comment 42 SpanKY gentoo-dev 2013-09-12 17:39:45 UTC
(In reply to Matthew Thode ( prometheanfire ) from comment #41)

we're waiting for the openvpn maintainers to merge the patch i posted to use execvpe.  or to give the go ahead for someone else to merge it.
Comment 43 Gert Doering 2013-11-17 16:21:41 UTC
Upstream has not seen any compelling arguments why we would want to add that change.  ifconfig, route, ip are system parameters and on a normal distribution, they just don't move around "just so", so this would really only for the benefit of gentoo - and you can fix it locally by just re-emerging when (once every 10 years) one of the network binaries moves around
Comment 44 SpanKY gentoo-dev 2013-11-26 19:11:15 UTC
(In reply to Gert Doering from comment #43)

the moving of tools in $PATH is happening in all distros (the net-tool changes were merged upstream and not just in Gentoo), so all distros will need to handle this.  i meant to get the iproute2 change pushed up too, but i haven't gotten around it.

conversely, there's no real compelling arguments why the paths need to be hardcoded at build time.
Comment 45 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2014-02-18 03:28:57 UTC
any update on this?
Comment 46 SpanKY gentoo-dev 2014-02-18 23:05:11 UTC
it's up to djc@, but i can merge this for 2.3.x in the mean time if he doesn't mind.  fixing things in 2.4 to use netlink sockets sounds great, but doesn't help us with 2.3 now ...
Comment 47 SpanKY gentoo-dev 2014-03-22 05:57:47 UTC
give it another month or two, and i'll probably just merge it
Comment 48 Gert Doering 2014-03-22 12:21:01 UTC
In reply to #44: on other distributions, such a change (moving of system binaries elsewhere) would normally happen as part of a version upgrade - and part of that upgrade would be "recompile everything that relies on the binaries that have moved".

So Gentoo is a bit special here as there are no fixed "releases" and "upgrades" between them - but I still fail to see what's wrong with just bumping the version number of the openvpn ebuild if such a move happens, get it recompiled, issue solved?  This is a one-time issue, unless you're not planning to move around ifconfig/route on a more frequent basis in the future (which I strongly hope you're not going to do).
Comment 49 Dirkjan Ochtman (RETIRED) gentoo-dev 2014-03-22 13:51:26 UTC
I'd prefer not to take your fix and instead bump the package as needed.
Comment 50 SpanKY gentoo-dev 2014-04-29 22:05:45 UTC
(In reply to Dirkjan Ochtman from comment #49)

bump to what ?  unless i'm missing something, upstream won't have a sane version for quite a long time (it's been years already).
Comment 51 Dirkjan Ochtman (RETIRED) gentoo-dev 2014-04-30 06:50:32 UTC
Yes, but a revbump will rebuild it for everyone with the new paths.
Comment 52 Gert Doering 2014-04-30 07:05:47 UTC
(In reply to SpanKY from comment #50)
> (In reply to Dirkjan Ochtman from comment #49)
> 
> bump to what ?  unless i'm missing something, upstream won't have a sane
> version for quite a long time (it's been years already).

Uh, what?  Just add a subrevision to the ebuild.

Besides that, I'm not sure what you mean by "upstream won't have a sane version for quite a long time" - we just released 2.3.3 two weeks ago, and will release 2.3.4 this week, both of which are "from the stable train".  2.3.2 was released 11 months ago, which I wouldn't call "years already" either.

Could you elaborate what is "not sane" about this?
Comment 53 Dirkjan Ochtman (RETIRED) gentoo-dev 2014-04-30 07:15:48 UTC
I think by "sane version" I think he means nothing that does netlink sockets, or otherwise not relying on build-time paths.

It doesn't seem like Mike and upstream/Gert can reach agreement on what is "sane" related to the build-time paths, but I'd rather not take this execvpe patch.
Comment 54 Gert Doering 2014-04-30 07:19:18 UTC
(In reply to Dirkjan Ochtman from comment #53)
> I think by "sane version" I think he means nothing that does netlink
> sockets, or otherwise not relying on build-time paths.

OK, if that's the definition of "sanity", we will only provide insane releases for quite a while to come - what we have now isn't pretty and smells a bit musty after the decades, but is very well tested on all supported platforms.

2.4 will bring nice stuff, possibly even "sanity", but right now, there's still stuff that is just kaput if you choose the right combination of platform and build flags...
Comment 55 SpanKY gentoo-dev 2014-04-30 18:07:05 UTC
(In reply to Dirkjan Ochtman from comment #51)

yes, if we put a blocker on older versions of net-tools/iproute2 and add a revbump, we can continue to bury our heads in the sand and most users won't notice an issue.
Comment 56 Manuel Rüger (RETIRED) gentoo-dev 2016-09-01 12:43:00 UTC
This bug has gotten really old, can you please retry with openvpn-2.3.12 and see if the issue still exists?
Comment 57 Petr Pisar 2016-09-02 16:44:15 UTC
net-misc/openvpn-2.3.12 suffers from the same issue. After merging it, I moved /bin/ip to /usr/bin/ip and started the daemon. The daemon failed because it was no able to execute /bin/ip:

Sep  2 18:37:14 album openvpn[18116]: TUN/TAP device foo0 opened
Sep  2 18:37:14 album openvpn[18116]: do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Sep  2 18:37:14 album openvpn[18116]: /bin/ip link set dev foo0 up mtu 1360
Sep  2 18:37:14 album openvpn[18116]: Linux ip link set failed: could not execute external program
Sep  2 18:37:14 album openvpn[18116]: Exiting due to fatal error
Comment 58 Gert Doering 2016-09-02 19:02:21 UTC
(In reply to Petr Pisar from comment #57)
> net-misc/openvpn-2.3.12 suffers from the same issue.

And it will continue to do so, see my comments #43, #48 and others - OpenVPN upstream does not consider arbitrary moving of system binaries to be something we need or want to support.

See said comments for the reasoning behind: in distributions with a regular release schedule, this just does not happen - if system binaries move, it's a distribution upgrade, and all dependent packages get upgraded/recompiled accordingly.  Gentoo can work around this (if this should ever be needed again) by bumping the ebuild version on openvpn, so it gets recompiled - but just how often do you plan to move around "ifconfig", "route" or "ip"?