How Torch broke ls and made me vulnerable
joshumax.github.io
joshumax.github.io
There are examples in various places:
https://enchildfone.wordpress.com/2010/03/23/a-description-o... http://man7.org/linux/man-pages/man8/ld.so.8.html http://longwei.github.io/rpath_origin/
LD_LIBRARY_PATH is really only for a developer's local use; it should never be used for installed software.
Disclaimer: may not apply in some scenarios, I haven't used Torch, so this is merely a general observation.
Also,
test:
echo "\$$ORIGIN"
outputs $ORIGIN. $$ translates to a literal dollar sign. \ escapes the dollar sign in the shell.export LD_LIBRARY_PATH=/opt/whatever/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Pull request sent to https://github.com/torch/distro/pull/228.
I still find it kinda baffling glibc would have this behavior for a trailing colon (:). Like, I know it's probably legacy/comparability, but it feels like a security nightmare. ./ should be explicit, not implicit.
Where is this documented? It's not indicated in ld.so's manpage:
http://man7.org/linux/man-pages/man8/ld.so.8.html
Sounds like a bug in GNU's ld.so more than anything.
http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#s...
The dynamic array tag DT_RUNPATH gives a string that holds a list of directories, separated by colons (:). For example, the string /home/dir/lib:/home/dir2/lib: tells the dynamic linker to search first the directory /home/dir/lib, then /home/dir2/lib, and then the current directory to find dependencies.
The following values would be equivalent to the previous example:
LD_LIBRARY_PATH=/home/dir/usr/lib:/home/dir2/usr/lib:
export FOOBAR=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FOOBAL
So yeah, fix the source of the problem in ld.so, don't blame it on Torch.It's neither unique to glibc (AIX, Solaris) nor to LD_LIBRARY_PATH (PATH), nor trailing colons (leading colons, adjacent colons).
This de facto standard becomes a little more obvious when one considers a likely implementation (iterating over "strchr(arg, ':')" or whatever). Any of these sequences then will give up an empty string:
PATH=:/foo
PATH=/foo:
PATH=/foo::/bar
And an empty string is equivalent to dot for chdir(2). zwp:/tmp$ cd ''
zwp:/tmp$ pwd
/tmp
zwp:/tmp$
(This is not the same as plain "cd" (ie with no args), which is a special case that takes you $HOME, of course).I agree it's surprising and potentially dangerous.
FWIW, the execp() functions hide a similar wtf. From the Linux man page:
The file is sought in the colon-separated list of
directory pathnames specified in the PATH envi‐
ronment variable. If this variable isn't defined,
the path list defaults to the current directory
followed by the list of directories returned by
confstr(_CS_PATH).
Security conscious programs that clear the environment and then call eg execlp() end up searching dot before the system path. Yay.What's wrong with something like, "Torch machine learning introduces vulnerability in loading of shared libraries." Whilst it doesn't tell the whole story it does at least give a flavour instead of just sowing confusion.
https://github.com/omnirom/android_bootable_recovery/commit/...
sounds like a pretty good thing to disable in ld.so...
However, most of the latest versions of the mainstream browsers now intentionally avoid writing out such files to the downloads folder unless the end user specifically OKs it (due to situations like this!)
If your script is obviously malicious then you're reducing your chances. Such a change could seem innocuous[0], then, cloning a repo containing a so file in the middle of a long list and cd'ing would trigger payload execution. Distributing the maliciousness by chaining innocuously looking actions is both effective at bypassing human logical analysis and plausibly deniable (up to a point).
It's a very unreliable attack vector, but what makes it completely pointless is in order to even set it up, you already need permission to edit the user's bash profile, and if you can do that, then you don't need LD_LIBRARY_PATH.
But you're right it should not occur.
Thanks for sharing!
Yes …? Well, I dunno; I don't know how Windows 10's PATH editor works. Nonetheless, the issue seems to be with magic interpretation of special configuration options, not with how those configuration options are entered. (Note also that the configuration was done programmatically, not by the user, so that there would have to be some kind of parse–deparse step anyway.)