All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nora Platiel <nplatiel@gmx.us>
To: Walter Harms <wharms@bfs.de>
Cc: mtk.manpages@gmail.com, alx.manpages@gmail.com,
	linux-man@vger.kernel.org
Subject: Re: AW: execve(2) man page: "absolute pathname" inconsistency
Date: Sun, 27 Jun 2021 01:09:34 +0200	[thread overview]
Message-ID: <trinity-606da93f-54ae-4472-ba63-e45b3f76d6b0-1624748974126@3c-app-mailcom-bs03> (raw)
In-Reply-To: <750acf642c3e4e79b782e72d5914c89d@bfs.de>

> I guess there is a mixup between interpreter and pathname.

Do you mean that `interpreter' is supposed to be absolute, instead of `pathname'?
The same example also disproves that, since argv[0] is relative:

|   interpreter [optional-arg] pathname arg...
|
| $ ./execve ./script
| argv[0]: ./myecho
| argv[1]: script-arg
| argv[2]: ./script
| argv[3]: hello
| argv[4]: world

> All this is only vaild if the
> flag is set to P (P - preserve-argv[0]) when you add a new
> setting in /proc/sys/fs/binfmt_misc/register

I'm not sure how binfmt_misc is related to this.
We are talking about the normal shebang mechanism (which doesn't preserve argv[0]), and the man page doesn't even mention binfmt_misc.
Do you agree that the man page is in error?

> (any way to get the current setting ?)

You can see the active flags for a registered FORMAT by reading /proc/sys/fs/binfmt_misc/FORMAT.
(Though I'm new to binfmt_misc, I usually keep it disabled.)

> the original wording from the kernel says:
>
> Legacy behavior of binfmt_misc is to overwrite the original argv[0] with
> the full path to the binary. When this flag is included, binfmt_misc will
> add an argument to the argument vector for this purpose, thus preserving
> the original argv[0]. e.g. If your interp is set to /bin/foo and you run
> blah (which is in /usr/local/bin), then the kernel will execute /bin/foo
> with argv[] set to ["/bin/foo", "/usr/local/bin/blah", "blah"]. The interp
> has to be aware of this so it can execute /usr/local/bin/blah with argv[]
> set to ["blah"].

According to my tests, no path is ever made absolute regardless of the P flag.
Apparently where it says "the full path to the binary" it doesn't mean an absolute path, just a path that resolves to the actual file (and doesn't need to be searched in $PATH as it may be the case with the original argv[0]).

# echo :myecho:M::1::./myecho: >/proc/sys/fs/binfmt_misc/register
# echo :myechop:M::2::./myecho:P >/proc/sys/fs/binfmt_misc/register
$ cat /proc/sys/fs/binfmt_misc/myecho
enabled
interpreter ./myecho
flags:
offset 0
magic 31
$ cat /proc/sys/fs/binfmt_misc/myechop
enabled
interpreter ./myecho
flags: P
offset 0
magic 32
$ echo 1 >script
$ echo 2 >scriptp
$ chmod a+x script scriptp
$ ./execve ./script
argv[0]: ./myecho
argv[1]: ./script
argv[2]: hello
argv[3]: world
$ ./execve ./scriptp
argv[0]: ./myecho
argv[1]: ./scriptp
argv[2]: ./scriptp
argv[3]: hello
argv[4]: world

As you can see, all the paths are relative regardless of the P flag.

  reply	other threads:[~2021-06-26 23:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24 20:42 execve(2) man page: "absolute pathname" inconsistency Nora Platiel
2021-06-25 10:33 ` AW: " Walter Harms
2021-06-26 23:09   ` Nora Platiel [this message]
2021-07-03 18:56 ` Alejandro Colomar (man-pages)
     [not found]   ` <1778431625342219@mail.yandex.com>
2021-07-15 16:09     ` Nora Platiel
2021-07-17 12:28       ` Alejandro Colomar (man-pages)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-606da93f-54ae-4472-ba63-e45b3f76d6b0-1624748974126@3c-app-mailcom-bs03 \
    --to=nplatiel@gmx.us \
    --cc=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=wharms@bfs.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.