-
Notifications
You must be signed in to change notification settings - Fork 241
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
agetpass(): Allocate on the stack (alloca(3)) #1191
Open
alejandro-colomar
wants to merge
15
commits into
shadow-maint:master
Choose a base branch
from
alejandro-colomar:agetpass
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
agetpass(): Allocate on the stack (alloca(3)) #1191
alejandro-colomar
wants to merge
15
commits into
shadow-maint:master
from
alejandro-colomar:agetpass
Conversation
This file contains 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
alejandro-colomar
force-pushed
the
agetpass
branch
4 times, most recently
from
January 19, 2025 23:55
cafa934
to
1154d32
Compare
alejandro-colomar
force-pushed
the
agetpass
branch
4 times, most recently
from
January 20, 2025 00:24
f6aeb0a
to
b7c072b
Compare
alejandro-colomar
force-pushed
the
agetpass
branch
from
January 20, 2025 15:40
4545946
to
30b50b1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
alejandro-colomar
force-pushed
the
agetpass
branch
from
January 22, 2025 13:15
30b50b1
to
f024191
Compare
I've rewritten the patches from scratch as v4. |
alejandro-colomar
force-pushed
the
agetpass
branch
from
January 22, 2025 13:28
f024191
to
2f18365
Compare
alejandro-colomar
force-pushed
the
agetpass
branch
2 times, most recently
from
January 22, 2025 15:41
57b8ac5
to
c7ea351
Compare
alejandro-colomar
force-pushed
the
agetpass
branch
from
January 22, 2025 15:49
c7ea351
to
0a5c77e
Compare
alejandro-colomar
force-pushed
the
agetpass
branch
2 times, most recently
from
January 24, 2025 15:05
fb69c8d
to
d6ceb22
Compare
This simplifies the agetpass() call into a single line. Signed-off-by: Alejandro Colomar <[email protected]>
The lengthy documentation is rather obvious, and only clutters the source file. It will still be reachable in the git history for those interested. Instead, just say that this function is basically getpass(3) done right. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This moves the [[gnu::malloc()]] attribute to agetpass_internal() --which now must be extern--. This fixes a bug: the attribute was missing in agetpass_internal(). Fixes: 3fff9d7 (2024-01-31; "lib/agetpass.[ch]: add function ro read from pipe") Signed-off-by: Alejandro Colomar <[email protected]>
readpassphrase(3) is hard to use correctly. Wrap correct usage of readpassphrase in this API. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
…arate file Signed-off-by: Alejandro Colomar <[email protected]>
alejandro-colomar
force-pushed
the
agetpass
branch
2 times, most recently
from
January 24, 2025 23:11
9c49413
to
1d7a2ea
Compare
This macro will allow using alloca(3) memory in these APIs. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
alejandro-colomar
force-pushed
the
agetpass
branch
from
January 25, 2025 00:16
1d7a2ea
to
c649022
Compare
… APIs These APIs will minimize the visibility of passwords, by not using the heap. The stack should have enough space for PASS_MAX+2 allocations, so this should be safe. Signed-off-by: Alejandro Colomar <[email protected]>
And getpassa_stdin() instead of agetpass_stdin(). Now all passwords live in the stack, and are never copied into the heap. This introduces a subtle issue: while it's fine to call malloc(3) in a loop, it is dangerous to call alloca(3) in a loop (since there's no way to free that memory). The next commit will fix that. I've addressed it in a separate commit, for readability. Signed-off-by: Alejandro Colomar <[email protected]>
Calling passalloca() (which is a wrapper around alloca(3)) in a loop is dangerous, as it can trigger a stack overflow. Instead, allocate the buffer before the loop, and run getpass2() within the loop, which will reuse the buffer. Signed-off-by: Alejandro Colomar <[email protected]>
In the last commit, we replaced all of these calls by alloca(3)-based variants. Signed-off-by: Alejandro Colomar <[email protected]>
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.
Hi!
This is rather sensitive, and I'd like to have as many eyes as possible look at this code.
Cc: @hallyn , @ikerexxe , @stoeckmann , @thalman , @thesamesam , @ferivoz , @jubalh
Reasons for all this change:
See Clear plaintext passwords in more error cases #1190 (comment).
Revisions:
v2
v2b
v3
v3b
v4
[[gnu::malloc()]]
, due to https://inbox.sourceware.org/gcc/dese7p5pdgne5gtumus6mc6ydlfcnwneeovsujpbvwqibe52ax@sl3uip7dwxg6/T/.v5
<pass/limits.h>
. This breaks a circular include.v6
v6b
v6c
v7
This fixes an accidental bug I had introduced earlier. In src/sulogin.c, I was passing a NULL to passzero().
Code is also much simpler (and safer) when you can pass NULL to destructor APIs.
v7b
v7c
v8
v8b