Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > muc.lists.netbsd.tech.userlevel > #11516 > unrolled thread
| Started by | David Holland <dholland-tech@netbsd.org> |
|---|---|
| First post | 2025-01-09 13:52 +0000 |
| Last post | 2026-11-01 19:16 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to muc.lists.netbsd.tech.userlevel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Proposal: getexecpath(3) David Holland <dholland-tech@netbsd.org> - 2025-01-09 13:52 +0000
Re: Proposal: getexecpath(3) Robert Elz <kre@munnari.OZ.AU> - 2025-01-10 03:09 +0700
Re: Proposal: getexecpath(3) David Holland <dholland-tech@netbsd.org> - 2026-11-01 19:16 +0000
| From | David Holland <dholland-tech@netbsd.org> |
|---|---|
| Date | 2025-01-09 13:52 +0000 |
| Subject | Re: Proposal: getexecpath(3) |
| Message-ID | <Z3_UgWdVDwJu5cNf@netbsd.org> |
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 -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[toc] | [next] | [standalone]
| From | Robert Elz <kre@munnari.OZ.AU> |
|---|---|
| Date | 2025-01-10 03:09 +0700 |
| Message-ID | <11495.1736453342@jacaranda.noi.kre.to> |
| In reply to | #11516 |
Date: Thu, 9 Jan 2025 13:52:01 +0000
From: David Holland <dholland-tech@netbsd.org>
Message-ID: <Z3_UgWdVDwJu5cNf@netbsd.org>
| 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.
Sorry, but this is nonsense.
No application can know (without getppid() and either /proc or parsing
ps output) what application it was started from. And it is entirely
reasonable to make applications whose whole purpose is to run another
program with something different than the program name as argv[0] - I
used to do that all the time when testing login shells, actually logging
in every time is way too much effort, but a program that would exec
the test binary I was using, but make its argv[0] simply be "-sh" (whatever
the test shell version binary was called, or what the path to it was) was
about 20 seconds of code writing.
Further, if you're not using our /bin/sh then there's an even easier
way, many shells have a -a option to "exec" with the whole purpose of
allowing argv[0] to be set to any desired value)
Given /tmp/dummy.c containing:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int
main(int argc, char **argv)
{
printf("%s\n", *argv);
return 0;
}
(all 3 includes are probably not required, just my standard set
for simple test programs like this). Compile it to make /tmp/dummy
then running it as just "/tmp/dummy" will produce "/tmp/dummy" on
stdout. Running it as "(exec -a foobar /tmp/dummy)" from a shell
which supports that (bash mksh ksh93 yash bosh zsh .. maybe more)
and it will print "foobar".
| Furthermore, as I've already pointed out a couple times, a hostile
| caller can confuse any of these schemes.
They can, which is perhaps why this getexecpath() request was made.
| % mkdir /tmp/confusion /tmp/confusion/bin
[you probably omitted a cd here]
| % ln /usr/pkg/bin/qemu .
| % ./qemu
|
| Then the path to the executable _is_ /tmp/confusion/bin, and you're
| done.
Yes, and if something wanted to use argv[0] to find other data, or
other related binaries, then unless they're also installed (in the new
location), then things will fail - just as they would if qemu (in this
example) were left in its normal place, but the other data/binaries were
never installed (or later removed). Nothing exciting about that.
I suspect that what is wanted is for a properly installed qemu
to be able to run (without any of the above setup) as
(exec -a /tmp/confusion/bin/qemu /usr/pkg/bin/qemu [....])
and have it still work (though programs which use what is argv[0]
to determine what they should do, eg stat & readlink, amongst others,
will only work if at least the last element of the path in argv[0] is
something which will elicit the intended behaviour).
| You can't do it that way if /usr/pkg isn't on the same volume as /tmp,
You mean changing "ln" to "cp" is somehow difficult ? (or even ln -s)
I have no opinion on whether there's enough real need for a getexecpath()
interface to exist or not, but arguing that argv[0] already provides the
same information is simply wrong.
kre
ps: I know /tmp/dummy as above isn't perfect, it should test that *argv
is not NULL before blindly printing it ... there's no absolute guarantee
that it won't be.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[toc] | [prev] | [next] | [standalone]
| From | David Holland <dholland-tech@netbsd.org> |
|---|---|
| Date | 2026-11-01 19:16 +0000 |
| Message-ID | <aueQJ9KEEPhmDt_6@netbsd.org> |
| In reply to | #11517 |
Since this thread's come back to life: On Fri, Jan 10, 2025 at 03:09:02AM +0700, Robert Elz wrote: > | 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. > > Sorry, but this is nonsense. > > No application can know (without getppid() and either /proc or parsing > ps output) what application it was started from. And it is entirely > reasonable to make applications whose whole purpose is to run another > program with something different than the program name as argv[0] - I > used to do that all the time when testing login shells, actually logging > in every time is way too much effort, but a program that would exec > the test binary I was using, but make its argv[0] simply be "-sh" (whatever > the test shell version binary was called, or what the path to it was) was > about 20 seconds of code writing. Yeah, so you can lie to a program in argv[0] and maybe break it. You can also send it SIGSEGV, or attach with ptrace and overwrite its memory with deadbeef. What's your point? The idea is to let third-party applications find their installed resources without compiling in the install prefix, not to give setugid programs new lengths of rope to hang themselves with. Any getexecpath(3) should probably abort if issetugid(). -- David A. Holland dholland@netbsd.org -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[toc] | [prev] | [standalone]
Back to top | Article view | muc.lists.netbsd.tech.userlevel
csiph-web