-
-
Notifications
You must be signed in to change notification settings - Fork 698
Remove realpath/getcwd from loaders #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Noticed a bug in the process, pathlen is out of step with n
(Do not merge without GetProgramExecutableName change)
18e7c06
to
8711ed6
Compare
8711ed6
to
37db741
Compare
37db741
to
d35516f
Compare
840317b
to
4b68148
Compare
TryPath with com==1 tries both non-com and com, so the checks were redundant. With com==0, there is no reason to copy to the buffer if the initial access fails.
4b68148
to
9aafcb0
Compare
Merges branches 'm1-realpath', 'loader-realpath' and 'getprogramexecutablename-realpath' into no-realpath
9aafcb0
to
0734b9c
Compare
The loader implementing it was never minted, so it seems reasonable not to keep support for it indefinitely. But it seems impolite to break the prerelease loaders people may have been using between releases.
522a556
to
259e6fd
Compare
mrdomino
commented
Dec 17, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI Github does not render the three-way merge in 0734b9c correctly. That commit should show as empty; it only pulls in the commits before it and makes no changes itself.
If we got __program_executable_name, it means the /proc-esque methods are going to return the path of the loader rather than the path of the binary, so do not use them in this case. If the passed path is absolute, use it as-is. Otherwise, copy it into the buffer with getcwd prepended. The sys_faccessat call should be redundant; if TryPath fails, it probably failed because getcwd() was too long, so just use the relative path and accept that chdir will break things. On that note, TryPath now fails prior to the sys_faccessat if getcwd() is too long, and otherwise behaves the way the code used to. The version I wrote before this change would have always succeeded on a truncated path assuming the relative path could have been accessed. The original version would have succeeded on a truncated path if there happened to be a file at that path that could be accessed. This change also backs out the setugid loader check for /dev/fd path. For now, we fail open; if for some reason we are invoked set-id by the loader, we just assume that the user knows what they are doing and do not attempt to second-guess them, beyond politely declining to trust argv[0] or the environment.
jart
approved these changes
Dec 18, 2023
mrdomino
added a commit
to mrdomino/cosmopolitan
that referenced
this pull request
Dec 22, 2023
Returns to passing os as `%rcx`, stack pointer as `%rdx` as it was before jart#1024. exe is now passed as `%r8`, and is moved to `%rdx`. os is passed on aarch64, from both loader.c and ape-m1.c. It is currently unused.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements proposals 1 and 2a from this gist:
https://gist.github.com/mrdomino/2222cab61715fd527e82e036ba4156b1
The only reason to use realpath from the loader was to try to prevent a
TOCTOU between the loader and the binary. But this is only a real issue
in set-id contexts, and in those cases there is already a canonical way
to do it:
/dev/fd
, passed by the kernel to the loader, so all we haveto do is pass that along to the binary.
Aside from realpath, there is no reason to absolutize the path we supply
to the binary, since it can call
getcwd
as well as we can, and on non-M1 the binary is in a much better position to make that call.
Since we no longer absolutize the path, the binary does need to do this,
so we make its argv-parsing code generic and apply that to the different
possible places the path could come from. This means that
_
is finallyusable as a relative path, as a nice side benefit.
The M1 realpath code had a significant bug - it uses the wrong offset to
truncate the
.ape
in the$prog.ape
case.This PR also fixes a regression in
ape $progname
out of$PATH
on thetwo BSDs (Free and Net) that did not implement
RealPath
.