tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Proposal: getexecpath(3)



On Mon, Jan 06, 2025 at 06:50:25PM +0100, Jean-Yves Migeon (NetBSD) wrote:
 > > For the sake of argument, I wrote the code, stuck it in /usr/local/bin,
 > > and ran it in various ways, first from sh:
 > 
 > This is not a shell matter.

It absolutely is. argv[0] is provided by the program that calls
execve, which for ordinary 3rd-party application software that wants
this feature is either the shell or a shell substitute (such as a
window manager, desktop start button, etc.)

There is no reason to care about what an "uncooperative" caller does.

Furthermore, as I've already pointed out a couple times, a hostile
caller can confuse any of these schemes. The simplest method (assuming
for the sake of argument we're trying to run /usr/pkg/bin/qemu and
convince it its $PREFIX is /tmp/confusion) is as follows:

   % mkdir /tmp/confusion /tmp/confusion/bin
   % ln /usr/pkg/bin/qemu .
   % ./qemu

Then the path to the executable _is_ /tmp/confusion/bin, and you're
done.

You can't do it that way if /usr/pkg isn't on the same volume as /tmp,
at which point things become more complicated, but configs where it is
are quite common.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index