-
Notifications
You must be signed in to change notification settings - Fork 246
agetpass(): Allocate on the stack (alloca(3)) #1191
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
Open
alejandro-colomar
wants to merge
5
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.
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
cafa934
to
1154d32
Compare
f6aeb0a
to
b7c072b
Compare
4545946
to
30b50b1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
30b50b1
to
f024191
Compare
I've rewritten the patches from scratch as v4. |
f024191
to
2f18365
Compare
57b8ac5
to
c7ea351
Compare
c7ea351
to
0a5c77e
Compare
c649022
to
80070c1
Compare
Thanks. I think I like it, but I haven't gone over all the uses yet. |
Thanks! Please let me know when you've finished reviewing. BTW, I'll be at FOSDEM. See you there? :-) |
I will do -- and yes! Let's make sure we find each other! :) |
81cff2a
to
e007e8f
Compare
This comment was marked as outdated.
This comment was marked as outdated.
2618db4
to
db7f1c0
Compare
db7f1c0
to
760007b
Compare
1736c50
to
e15c979
Compare
e15c979
to
322016b
Compare
322016b
to
ce9757b
Compare
ce9757b
to
b06872f
Compare
8e5377a
to
4cb46b4
Compare
af5befa
to
77e1e72
Compare
This simplifies the agetpass() call into a single line. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
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. PASS_MAX: Move definition to <pass.h> pass_t: Type to hold passwords. readpass(): readpassphrase(3) is hard to use correctly. Wrap correct usage of readpassphrase in this API. passzero(): Trivial memzero() wrapper that destroys passwords. passalloca(): This macro will allow using alloca(3) memory in these APIs. getpass2(), getpass2_stdin(): These macros are like getpass(3), but get the buffer as a parameter, avoiding the problems of getpass(3). The buffer size is fixed, and can't be overflowed. getpassa(), getpassa_stdin(): These are similar to the above, but the memory is allocated with alloca(3). Signed-off-by: Alejandro Colomar <[email protected]>
And getpassa_stdin() instead of agetpass_stdin(). Now our passwords live in the stack, and there are less copies in the heap. In a few programs, we still copy them into the heap, though. It's not easy to get rid of all of them. This alloca(3)-based API means we need to call passalloca() before a loop. 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. Also, to avoid deallocator mismatches, use `pass = passzero(pass)` in those cases, so that the compiler knows that 'pass' has changed, and we're not using the password after zeroing it; we're only re-using its storage, which is fine. 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]>
77e1e72
to
e1d1b96
Compare
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
v9
v10
v10b
restrict
.v11
v12
v13
v13b
Comparison against v12, as a sanity check:
v14
lib/pass.h
lib/pass.c
.v15
v15b
v16
pass_t
.v17
v17b
v17c
v17d
v17e
v17f
v17g
v17h
v17i
v17j
v17k
v17l
v7m
v7n
v7o
v17p
v17q
v17r
v17s
v18
v18b