Skip to content

Clear plaintext passwords in more error cases #1190

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 3 commits into from
Jan 21, 2025

Conversation

stoeckmann
Copy link
Contributor

Most code paths make sure that a plaintext password, if not read from stdin or a file, is properly cleared.

This is not true for all pw_encrypt error cases. If the salt itself is considered "unknown", then exit is called. Let pw_encrypt return an error code so the program logic can clear passwords properly before handling the error.

One such example is musl. If passwd compiled for musl tries to encrypt a password with SHA512 which is longer than 256 characters, it fails. But this can be easily the valid password on the system, because glibc has no such problem. So, just wipe it.

Example output with this patch (passwd linked with musl):

$ passwd
Changing password for user
Old password:
crypt method not supported by libcrypt? (SHA512)
passwd: failed to crypt password with previous salt: Invalid argument
The password for user is unchanged.

While at it, fixed missing clearing in gpasswd and adjusted a preprocessor definition usage.

@alejandro-colomar
Copy link
Collaborator

For all three commits:

Reviewed-by: Alejandro Colomar <[email protected]>

Thanks!

If crypt fails, pw_encrypt calls exit. This has the consequence that the
plaintext password is not cleared.

A valid password can fail if the underlying library does not support it.
One such example is SHA512, for which the password must not be longer
than 256 characters on musl. A password longer than this with glibc
works, so it is actually possible that a user, running passwd, tries to
enter the old password but the musl-based passwd binary simply exits.
Let passwd clear the password before exiting.

Reviewed-by: Alejandro Colomar <[email protected]>
Signed-off-by: Tobias Stoeckmann <[email protected]>
If encryption of password fails, clear the memory before exiting.

Reviewed-by: Alejandro Colomar <[email protected]>
Signed-off-by: Tobias Stoeckmann <[email protected]>
Use PASS_MAX + 1 instead of BUFSIZ to clarify where this size comes
from. Technically, PASS_MAX is BUFSIZ - 1 so this is a no-op change.

Just make sure that the size of pass stays in sync with agetpass.

Reviewed-by: Alejandro Colomar <[email protected]>
Signed-off-by: Tobias Stoeckmann <[email protected]>
@alejandro-colomar
Copy link
Collaborator

alejandro-colomar commented Jan 21, 2025

Since nobody commented, and it's quite simple, I'll merge already. Thanks!

@alejandro-colomar alejandro-colomar merged commit 12117b2 into shadow-maint:master Jan 21, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants