Skip to content
Access control Write-up Advanced

[CVE-2026–123158] *sshole : How Two Unrelated ‘*’ Strings Broke OpenSSH on musl

A passwordless account whose shadow entry is a single asterisk could be logged into by sending a password longer than 256 bytes, because musl's crypt() returns the string "*" on failure and sshd compared it to the stored "*" with strcmp. An attacker who knows no password could authenticate as that account, which on Alpine cloud images has passwordless doas and is effectively root.

WhitGuidance Follow

Published on medium.com

Linux

WhitGuidance, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

Context

OpenSSH's sshd can verify passwords itself when PAM is not in use. On Alpine Linux, the default openssh-server package is built against musl libc and without PAM, so the password check runs through sys_auth_passwd() in auth-passwd.c and then through musl's crypt() implementation. The bug described here, tracked as CVE-2026-123158 and nicknamed sshole, lets an attacker who knows no password at all log in by sending a 257-byte string, provided the target account stores a single * in its shadow field.

Unix systems do not store passwords in plaintext. They store a hash and compare hashes at login time. A normal shadow entry looks like this:

Text
alice:$6$Qx7Lm2Pa$k3J9...(long hash)...:20000:0:99999:7:::

$6$ means SHA-512 crypt, and Qx7Lm2Pa is the salt, a random string mixed into the password so two users with the same password do not get the same hash.

Accounts that should only ever authenticate with an SSH key follow a decades-old Unix convention and store a single asterisk instead:

Text
keyonly:*:20000:0:99999:7:::

That convention only holds if no real password can ever hash down to the single character *. sshole is exactly the case where that assumption breaks. musl libc's crypt() refuses passwords longer than 256 bytes and signals the failure by returning the literal string "*". Under the right conditions, sshd can be tricked into generating exactly that "*" from an attacker-controlled password, and once it does, it matches the "*" stored for the passwordless account byte-for-byte.

From the original on medium.com

TL;DR

From the original on medium.com

An attacker who knows no password at all can log in just by sending a 257-byte string. The rest of this post walks through the sshd and musl source code to explain exactly how.

Setup

The analysis uses the pre-patch code as shipped in OpenSSH 9.3p2 on Alpine Linux 3.18. The relevant preconditions are:

  1. sshd is built against musl libc and without PAM (Alpine Linux's default openssh-server package).
  2. PasswordAuthentication yes (OpenSSH's default).
  3. The target account's shadow field is exactly * (accounts locked with ! are safe).
  4. The earliest $-hashed account in /etc/passwd order uses a vulnerable hash type.

For the hash type, $5$/$6$ (SHA-256/512) needs a 257 to 1024 byte password. bcrypt ($2a$/$2b$/$2y$) is different: pick_salt() miscalculates the $ delimiter position for bcrypt salts, so any 1 to 1024 byte password works regardless of length (fixed separately upstream in commit 84f8f466). If $1$ (MD5) or $y$ (yescrypt) comes first, neither path applies.

Root itself uses * on Alpine too, but the default PermitRootLogin prohibit-password blocks direct root logins this way. Alpine's official cloud images (3.18.11 to 3.24.3) ship an alpine user with passwordless doas, so bypassing login for that single account is effectively root.

Finding it

The core idea is that two unrelated * strings turn out to be equal. The first is the stored shadow value for a key-only account. The second is musl's error return from crypt(). The post reads the sshd password-check path and the musl crypt implementation to show where the two meet.

Step 1: How sshd checks a password without PAM

With PAM disabled, sshd verifies passwords itself in sys_auth_passwd(), in auth-passwd.c. This is the pre-patch code, as shipped in OpenSSH 9.3p2 on Alpine Linux 3.18:

C
char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd;...if (authctxt->valid && pw_password[0] && pw_password[1])    salt = pw_password;encrypted_password = xcrypt(password, salt);return encrypted_password != NULL &&    strcmp(encrypted_password, pw_password) == 0;

The logic is textbook: read the stored hash, use it as the salt to hash the password the user just typed, and strcmp() the two strings.

The interesting line is this one:

C
if (authctxt->valid && pw_password[0] && pw_password[1])    salt = pw_password;

Checking both pw_password[0] and pw_password[1] means the stored value needs at least two characters before sshd will use it as a salt. * is only one character, so it fails this check, and salt stays NULL. That forces the very next line, xcrypt(password, salt), to come up with a salt on its own.

Step 2: Borrowing a salt from another account

When salt is NULL, pick_salt() in openbsd-compat/xcrypt.c picks one:

C
if (salt[0] != '\0')    return salt;strlcpy(salt, "xx", sizeof(salt));setpwent();while ((pw = getpwent()) != NULL) {    if ((passwd = shadow_pw(pw)) == NULL)        continue;    if (passwd[0] == '$' && (p = strrchr(passwd+1, '$')) != NULL) {        typelen = p - passwd + 1;        strlcpy(salt, passwd, MINIMUM(typelen, sizeof(salt)));        explicit_bzero(passwd, strlen(passwd));        goto out;    }}out:endpwent();return salt;

It walks /etc/passwd front to back, looking for the first account whose hash starts with $ and has a second $ delimiter, a modern crypt format like $5$... or $6$.... It returns the hash-type-plus-salt prefix of that account, or falls back to the legacy DES placeholder "xx" if nothing matches.

This function exists because of CVE-2016-6210. In 2016, researchers showed that sshd's response time differed for nonexistent users versus real ones, a timing side-channel that let attackers enumerate valid usernames. The fix was to always borrow a real account's salt format when none was available, so the timing cost looked the same either way. The intent was to protect against usernames that do not exist. But because of the pw_password[1] check above, a real account with * falls into the exact same code path. So the passwordless keyonly account ends up borrowing, say, alice's $6$Qx7Lm2Pa salt for the comparison.

Step 3: musl crypt()'s 256-byte cap

Next, sshd hashes the attacker's password using that borrowed salt. musl's SHA-512 crypt implementation (src/crypt/crypt_sha512.c) caps the input length:

C
#define KEY_MAX 256...        for (i = 0; i <= KEY_MAX && key[i]; i++);    if (i > KEY_MAX)        return 0;

Anything over 256 bytes is refused outright, a sensible DoS protection. What matters is what the caller gets back on that failure:

C
p = sha512crypt(key, setting, output);q = sha512crypt(testkey, testsetting, testbuf);if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash))    return "*";return p;

Not NULL, but the string "*". POSIX says crypt() should return a null pointer and set errno on error, but musl deliberately returns a string instead, because (per its own commit message) "a large portion of programs which call crypt are not prepared for its failure and do not check that the return value is non-null." glibc's libxcrypt, by contrast, returns NULL on failure, which sshd already filters out with encrypted_password != NULL. This is exactly why glibc distros like Debian, Ubuntu and RHEL are not affected.

Worth noting: musl does guard against the obvious version of this bug. In crypt_des.c:

C
return (setting[0]=='*') ? "x" : "*";

If the salt itself starts with *, musl returns "x" instead, so crypt(password, "*") can never produce "*". That guard protects the classic pattern, where a program uses the stored field as its own salt. But sshd never does that here; it uses a borrowed $6$... salt from a different account. As far as musl is concerned, it is just doing an ordinary SHA-512 crypt with a valid salt that happens to fail because the input is too long, and the guard never triggers.

Step 4: Where the two * meet

Putting it together:

C
encrypted_password = xcrypt(password, salt);   return encrypted_password != NULL &&    strcmp(encrypted_password, pw_password) == 0;
  • pw_password: the stored value for keyonly, which is "*".
  • encrypted_password: musl's error string from trying to hash a 257-byte password with the borrowed salt, which is also "*".

strcmp("*", "*") returns 0, and sshd accepts the login.

In practice this usually takes two attempts in the same SSH connection. musl's getspnam() reuses an internal shared buffer, and pick_salt()'s lookup of another account overwrites and then wipes that buffer with explicit_bzero(). So on the first attempt, pw_password ends up pointing at corrupted memory and the comparison simply fails. From the second attempt onward in the same connection, the salt is cached and the comparison runs cleanly. Since sshd allows up to 6 password attempts per connection by default (MaxAuthTries), this extra attempt costs the attacker nothing.

Exploitation

Step 1: Confirm the target is vulnerable

Run these as root to check quickly:

Bash
ldd "$(command -v sshd)" | grep -i muslsshd -T 2>/dev/null | grep -i '^usepam'sshd -T 2>/dev/null | grep -i '^passwordauthentication'awk -F: '$2=="*"{print $1}' /etc/shadowawk -F: '$2 ~ /^\$[56]\$/{print $1}' /etc/shadow

If you see a musl match, usepam no, passwordauthentication yes, at least one * account, and at least one $5$/$6$ account, the host is vulnerable on any pre-patch version.

Step 2: Send the oversized password

Connect to sshd and authenticate as the * account with a password of 257 to 1024 bytes for $5$/$6$ salts. The first attempt fails because of the shared-buffer overwrite; the second attempt in the same connection succeeds because the salt is cached. The attacker does not need to know any password.

Step 3: The full attack flow

From the original on medium.com

Root cause

The mistake is the interaction between three pieces of code:

  1. sshd's pw_password[1] check treats a one-character stored value as "no salt", so it calls xcrypt(password, NULL).
  2. pick_salt() then borrows a real $6$... salt from another account, so musl sees a valid salt and does not trigger its setting[0]=='*' guard.
  3. musl's crypt() returns the literal string "*" on failure instead of NULL, and sshd's strcmp() compares that against the stored "*" and accepts.

The existing defences did not stop it because the musl guard only covers the case where the stored field is used directly as the salt, and sshd's encrypted_password != NULL check only filters NULL, not the string "*". The pick_salt() mechanism, added to fix a timing side-channel, is what makes the borrowed salt available in the first place.

Impact

An attacker who knows no password at all can log in to any account whose shadow field is exactly *, on a musl-based, non-PAM sshd with PasswordAuthentication yes, provided the earliest $-hashed account in /etc/passwd order uses a vulnerable hash type. On Alpine's official cloud images, the alpine user has passwordless doas, so bypassing login for that single account is effectively root. Direct root login is blocked by the default PermitRootLogin prohibit-password. Accounts locked with ! are safe, and glibc distros such as Debian, Ubuntu and RHEL are not affected because libxcrypt returns NULL on failure.

Fix

The fix is in OpenSSH 10.6p2. The patch to auth-passwd.c is just a few lines:

C
+#define MIN_PASSWORD_HASH_LEN    4 #define MAX_PASSWORD_LEN 1024...-    return encrypted_password != NULL &&+    ret = encrypted_password != NULL &&+        strlen(pw_password) >= MIN_PASSWORD_HASH_LEN &&         strcmp(encrypted_password, pw_password) == 0;+    freezero(pw_password, strlen(pw_password));+    return ret;

The key addition is strlen(pw_password) >= MIN_PASSWORD_HASH_LEN. The shortest valid hash (legacy DES) is 13 characters, so anything stored under 4 characters is excluded from the comparison entirely, whether it is *, !, or any error string musl might return. This single check closes every path described in this post, bcrypt salt-parsing bug included.

The patch also changes shadow_pw() to return an xstrdup()'d copy instead of a pointer into a shared buffer, and wipes it with freezero() after use, removing the root cause of the "needs two attempts" buffer-reuse behaviour described above.

Remediation steps

  1. Update and restart sshd. Updating the package alone does not help if the running process is not restarted.
Bash
apk upgrade -U   rc-service sshd restart
  1. If you cannot update right now, turn off password auth (make sure key-based login works first):
Bash
echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/00-no-passwords.conf   sshd -t && rc-service sshd restart   sshd -T | grep -i passwordauthentication

Alpine 3.16 to 3.18 do not read sshd_config.d by default, so add PasswordAuthentication no directly to /etc/ssh/sshd_config on those versions.

  1. Check for signs of abuse by looking for Accepted password for log lines naming an account that should never accept a password login:
Bash
grep -h 'Accepted password for' /var/log/messages /var/log/auth.log 2>/dev/null

Variants to test

  • bcrypt salt parsing. If the earliest $-hashed account uses $2a$, $2b$ or $2y$, try any password between 1 and 1024 bytes. This path was fixed separately upstream in commit 84f8f466.
  • Other musl-based, non-PAM sshd builds. Check ldd "$(command -v sshd)" | grep -i musl and sshd -T | grep -i '^usepam'.
  • Accounts with * in shadow. Run awk -F: '$2=="*"{print $1}' /etc/shadow.
  • Hash type ordering. Run awk -F: '$2 ~ /^\$[56]\$/{print $1}' /etc/shadow and check which $-hashed account appears first in /etc/passwd order.
  • Log review. Run grep -h 'Accepted password for' /var/log/messages /var/log/auth.log 2>/dev/null.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 22 min read.

What happened, in plain words

Imagine a building where some doors are meant to open only with a key card, never with a typed code. The building's rulebook says: for those doors, write a single star * on the door's record instead of a code, and everyone will understand that no typed code should ever open it. That works only as long as nobody can type something that the system turns into a single star.

This report describes exactly that situation for OpenSSH, the software that lets you log in to a Linux server remotely over the network. On a particular combination of software (Alpine Linux, which uses a small C library called musl), an attacker who knows no password at all can log in to an account that was supposed to be key-only, simply by sending a password of 257 bytes. The two stars that collide are unrelated: one is the stored marker for a key-only account, the other is an error message that musl's password-hashing function returns when the password is too long. The login check compares them, sees they are identical, and lets the attacker in.

The bug is tracked as CVE-2026-123158 and nicknamed sshole. The rest of this article walks through the source code step by step, in the same order as the technical write-up, and explains every concept from scratch.

From the original on medium.com

TL;DR

From the original on medium.com

An attacker who knows no password at all can log in just by sending a 257-byte string. The rest of this post walks through the sshd and musl source code to explain exactly how.

The basics you need first

Before the code, a few ideas that come up constantly below.

  • SSH is a way to open a text terminal on a remote computer over the internet, securely. When you connect, the remote side runs a program called sshd (the SSH daemon, meaning a background service) that decides whether to let you in.
  • Authentication is the process of proving who you are. SSH supports two common ways: a password you type, or a key, which is a very long secret file stored on your computer that mathematically proves your identity without sending anything guessable.
  • A hash is the output of a one-way scrambling function. You put a password in, you get a fixed-looking string out. You cannot reverse it to get the password back, but if you put the same password in again you get the same string out. That is how systems check passwords without storing them.
  • A salt is a random string mixed into the password before hashing, so that two users who picked the same password still end up with different hashes. It is stored alongside the hash, in plain sight, because it is not secret.
  • A C library (libc) is the bundle of standard functions every program on a Linux system relies on. musl is one such library, used by Alpine Linux. glibc is the more common one, used by Debian, Ubuntu and RHEL.
  • PAM (Pluggable Authentication Modules) is a separate framework that many Linux systems use to handle password checks. When PAM is in use, sshd hands the password to PAM. When it is not, sshd does the check itself, and that is the code path this bug lives in.
  • A byte is one character's worth of data in the simplest encoding. 257 bytes is a password of 257 characters.

Setup

The analysis uses the pre-patch code as shipped in OpenSSH 9.3p2 on Alpine Linux 3.18. The relevant preconditions are:

  1. sshd is built against musl libc and without PAM (Alpine Linux's default openssh-server package).
  2. PasswordAuthentication yes (OpenSSH's default).
  3. The target account's shadow field is exactly * (accounts locked with ! are safe).
  4. The earliest $-hashed account in /etc/passwd order uses a vulnerable hash type.

For the hash type, $5$/$6$ (SHA-256/512) needs a 257 to 1024 byte password. bcrypt ($2a$/$2b$/$2y$) is different: pick_salt() miscalculates the $ delimiter position for bcrypt salts, so any 1 to 1024 byte password works regardless of length (fixed separately upstream in commit 84f8f466). If $1$ (MD5) or $y$ (yescrypt) comes first, neither path applies.

Root itself uses * on Alpine too, but the default PermitRootLogin prohibit-password blocks direct root logins this way. Alpine's official cloud images (3.18.11 to 3.24.3) ship an alpine user with passwordless doas, so bypassing login for that single account is effectively root.

A few words on those conditions. /etc/passwd is a plain text file listing every account on the machine. /etc/shadow is its companion, readable only by the administrator, that holds the actual password hashes. The $5$ and $6$ prefixes tell you which hashing algorithm was used: $5$ is SHA-256, $6$ is SHA-512, $1$ is the old MD5, $y$ is yescrypt, and $2a$/$2b$/$2y$ are bcrypt. doas is a small program that lets a normal user run commands as the administrator, similar to sudo. If the alpine user can run anything as root without typing a password, then logging in as alpine is as good as logging in as root.

Finding it

The core idea is that two unrelated * strings turn out to be equal. The first is the stored shadow value for a key-only account. The second is musl's error return from crypt(). The post reads the sshd password-check path and the musl crypt implementation to show where the two meet.

Step 1: How sshd checks a password without PAM

With PAM disabled, sshd verifies passwords itself in sys_auth_passwd(), in auth-passwd.c. This is the pre-patch code, as shipped in OpenSSH 9.3p2 on Alpine Linux 3.18:

C
char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd;...if (authctxt->valid && pw_password[0] && pw_password[1])    salt = pw_password;encrypted_password = xcrypt(password, salt);return encrypted_password != NULL &&    strcmp(encrypted_password, pw_password) == 0;

Line by line, in plain words:

  • char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd; asks: is this a real account? If yes, fetch its stored hash from the shadow file. If no, use whatever the passwd file holds. Either way, pw_password now points at the stored value.
  • if (authctxt->valid && pw_password[0] && pw_password[1]) checks three things: the account is real, the stored value has at least one character, and it has at least a second character. In C, pw_password[0] is the first character and pw_password[1] is the second. If all three are true, the next line runs.
  • salt = pw_password; uses the stored hash as the salt. This is the normal case: the stored hash already contains the salt, so reusing it as the salt lets sshd recompute the same hash from the typed password.
  • encrypted_password = xcrypt(password, salt); hashes the password the user just typed, using that salt.
  • return encrypted_password != NULL && strcmp(encrypted_password, pw_password) == 0; returns true only if the hashing produced something (not NULL, meaning not a null pointer) and the result is byte-for-byte identical to the stored value. strcmp is the standard C function that compares two strings and returns 0 when they are equal.

The logic is textbook: read the stored hash, use it as the salt to hash the password the user just typed, and strcmp() the two strings.

The interesting line is this one:

C
if (authctxt->valid && pw_password[0] && pw_password[1])    salt = pw_password;

Checking both pw_password[0] and pw_password[1] means the stored value needs at least two characters before sshd will use it as a salt. * is only one character, so it fails this check, and salt stays NULL. That forces the very next line, xcrypt(password, salt), to come up with a salt on its own.

Why does that matter? Because the whole point of the * marker is that no password should ever match it. But here, sshd has decided the marker is too short to be a real hash, so it goes looking for a salt elsewhere. That detour is the first half of the bug.

Step 2: Borrowing a salt from another account

When salt is NULL, pick_salt() in openbsd-compat/xcrypt.c picks one:

C
if (salt[0] != '\0')    return salt;strlcpy(salt, "xx", sizeof(salt));setpwent();while ((pw = getpwent()) != NULL) {    if ((passwd = shadow_pw(pw)) == NULL)        continue;    if (passwd[0] == '$' && (p = strrchr(passwd+1, '$')) != NULL) {        typelen = p - passwd + 1;        strlcpy(salt, passwd, MINIMUM(typelen, sizeof(salt)));        explicit_bzero(passwd, strlen(passwd));        goto out;    }}out:endpwent();return salt;

Line by line:

  • if (salt[0] != '\0') return salt; means: if a salt was already supplied, just use it. '\0' is the C way of writing the null character, which marks the end of a string. An empty string starts with it.
  • strlcpy(salt, "xx", sizeof(salt)); puts the two-character placeholder "xx" into the salt buffer as a fallback. This is the old DES crypt format, which is ancient and weak, but it is only used if nothing better is found.
  • setpwent(); rewinds the system's list of accounts to the beginning, so the loop below starts from the first account in /etc/passwd.
  • while ((pw = getpwent()) != NULL) { walks through every account, one at a time, until the list runs out.
  • if ((passwd = shadow_pw(pw)) == NULL) continue; fetches that account's shadow entry. If there is none, skip to the next account.
  • if (passwd[0] == '$' && (p = strrchr(passwd+1, '$')) != NULL) { checks whether the stored hash starts with $ and contains a second $ later on. strrchr finds the last occurrence of a character in a string. A modern hash like $6$Qx7Lm2Pa$... has exactly that shape: a $, a type number, another $, then the salt.
  • typelen = p - passwd + 1; calculates how many characters make up the type-plus-salt prefix, up to and including the second $.
  • strlcpy(salt, passwd, MINIMUM(typelen, sizeof(salt))); copies that prefix into the salt buffer, taking care not to overflow it.
  • explicit_bzero(passwd, strlen(passwd)); wipes the shadow entry from memory. explicit_bzero is a function that zeroes memory in a way the compiler is not allowed to optimise away, so the secret really is gone.
  • goto out; jumps out of the loop, because the first match is enough.
  • out: endpwent(); return salt; closes the account list and hands back the salt.

It walks /etc/passwd front to back, looking for the first account whose hash starts with $ and has a second $ delimiter, a modern crypt format like $5$... or $6$.... It returns the hash-type-plus-salt prefix of that account, or falls back to the legacy DES placeholder "xx" if nothing matches.

This function exists because of CVE-2016-6210. In 2016, researchers showed that sshd's response time differed for nonexistent users versus real ones, a timing side-channel that let attackers enumerate valid usernames. The fix was to always borrow a real account's salt format when none was available, so the timing cost looked the same either way. The intent was to protect against usernames that do not exist. But because of the pw_password[1] check above, a real account with * falls into the exact same code path. So the passwordless keyonly account ends up borrowing, say, alice's $6$Qx7Lm2Pa salt for the comparison.

A timing side-channel is a subtle leak: even if a system says the same thing in both cases, the time it takes to say it can differ, and an attacker who measures that time can learn something. Here, the old behaviour was that a real username took longer to reject than a fake one, so an attacker could tell which usernames existed. The fix made both cases do the same amount of work by borrowing a real salt. That fix is what makes the borrowed salt available to the bug.

Step 3: musl crypt()'s 256-byte cap

Next, sshd hashes the attacker's password using that borrowed salt. musl's SHA-512 crypt implementation (src/crypt/crypt_sha512.c) caps the input length:

C
#define KEY_MAX 256...        for (i = 0; i <= KEY_MAX && key[i]; i++);    if (i > KEY_MAX)        return 0;

Line by line:

  • #define KEY_MAX 256 sets a constant: the maximum password length is 256 bytes.
  • for (i = 0; i <= KEY_MAX && key[i]; i++); counts characters in the password, stopping either when it reaches 256 or when it hits the end of the string. The semicolon at the end means the loop body is empty; it is only counting.
  • if (i > KEY_MAX) return 0; if the count went past 256, give up and return zero, which the caller treats as failure.

Anything over 256 bytes is refused outright, a sensible DoS protection. DoS means denial of service: an attacker trying to make the server do so much work that it stops serving real users. Capping the input length stops someone from feeding in a gigantic password to burn CPU.

What matters is what the caller gets back on that failure:

C
p = sha512crypt(key, setting, output);q = sha512crypt(testkey, testsetting, testbuf);if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash))    return "*";return p;

Line by line:

  • p = sha512crypt(key, setting, output); hashes the real password with the real salt, storing the result in output.
  • q = sha512crypt(testkey, testsetting, testbuf); hashes a known test password with a known test salt, storing the result in testbuf. This is a self-check: the library verifies its own implementation against a known-good answer.
  • if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) return "*"; if the first hash failed, or the self-check produced a different result, or the self-check result does not match the expected value, return the string "*". memcmp compares two blocks of memory byte by byte.
  • return p; otherwise, return the real hash.

Not NULL, but the string "*". POSIX says crypt() should return a null pointer and set errno on error, but musl deliberately returns a string instead, because (per its own commit message) "a large portion of programs which call crypt are not prepared for its failure and do not check that the return value is non-null." glibc's libxcrypt, by contrast, returns NULL on failure, which sshd already filters out with encrypted_password != NULL. This is exactly why glibc distros like Debian, Ubuntu and RHEL are not affected.

POSIX is a standard that defines how Unix-like systems should behave, so programs can be written once and work everywhere. errno is a global variable where C functions put an error code. The point is that musl chose to be forgiving: instead of handing back a null pointer that careless programs would crash on, it hands back a harmless-looking string. That choice is what makes the collision possible.

Worth noting: musl does guard against the obvious version of this bug. In crypt_des.c:

C
return (setting[0]=='*') ? "x" : "*";

Line by line:

  • return (setting[0]=='*') ? "x" : "*"; is a one-line if/else. If the salt (called setting here) starts with *, return "x". Otherwise return "*".

If the salt itself starts with *, musl returns "x" instead, so crypt(password, "*") can never produce "*". That guard protects the classic pattern, where a program uses the stored field as its own salt. But sshd never does that here; it uses a borrowed $6$... salt from a different account. As far as musl is concerned, it is just doing an ordinary SHA-512 crypt with a valid salt that happens to fail because the input is too long, and the guard never triggers.

Step 4: Where the two * meet

Putting it together:

C
encrypted_password = xcrypt(password, salt);   return encrypted_password != NULL &&    strcmp(encrypted_password, pw_password) == 0;

Line by line:

  • encrypted_password = xcrypt(password, salt); hashes the attacker's password with the borrowed salt. Because the password is 257 bytes, musl refuses and returns "*".

  • return encrypted_password != NULL && strcmp(encrypted_password, pw_password) == 0; checks that the result is not NULL (it is not, it is the string "*"), then compares it to the stored value. The stored value for keyonly is also "*". The comparison succeeds.

  • pw_password: the stored value for keyonly, which is "*".

  • encrypted_password: musl's error string from trying to hash a 257-byte password with the borrowed salt, which is also "*".

strcmp("*", "*") returns 0, and sshd accepts the login.

In practice this usually takes two attempts in the same SSH connection. musl's getspnam() reuses an internal shared buffer, and pick_salt()'s lookup of another account overwrites and then wipes that buffer with explicit_bzero(). So on the first attempt, pw_password ends up pointing at corrupted memory and the comparison simply fails. From the second attempt onward in the same connection, the salt is cached and the comparison runs cleanly. Since sshd allows up to 6 password attempts per connection by default (MaxAuthTries), this extra attempt costs the attacker nothing.

A buffer is a fixed-size chunk of memory used to hold data temporarily. getspnam() is the function that looks up a shadow entry. If it hands back a pointer into a shared buffer, and something else overwrites that buffer before the pointer is used, the pointer now points at the wrong data. That is why the first attempt fails and the second works: by then the salt has been cached, so the lookup does not happen again.

Exploitation

Step 1: Confirm the target is vulnerable

Run these as root to check quickly:

Bash
ldd "$(command -v sshd)" | grep -i muslsshd -T 2>/dev/null | grep -i '^usepam'sshd -T 2>/dev/null | grep -i '^passwordauthentication'awk -F: '$2=="*"{print $1}' /etc/shadowawk -F: '$2 ~ /^\$[56]\$/{print $1}' /etc/shadow

Line by line:

  • ldd "$(command -v sshd)" | grep -i musl asks the system which libraries the sshd program is linked against, then filters the output for the word musl. command -v sshd finds the full path of the sshd program. The pipe | sends the output of one command into the next.
  • sshd -T 2>/dev/null | grep -i '^usepam' asks sshd to print its effective configuration (-T), throws away any error messages (2>/dev/null), and looks for the line starting with usepam.
  • sshd -T 2>/dev/null | grep -i '^passwordauthentication' does the same for the password authentication setting.
  • awk -F: '$2=="*"{print $1}' /etc/shadow reads the shadow file, splits each line on colons (-F:), and prints the first field (the username) whenever the second field (the hash) is exactly *.
  • awk -F: '$2 ~ /^\$[56]\$/{print $1}' /etc/shadow does the same but prints usernames whose hash starts with $5$ or $6$.

If you see a musl match, usepam no, passwordauthentication yes, at least one * account, and at least one $5$/$6$ account, the host is vulnerable on any pre-patch version.

Step 2: Send the oversized password

Connect to sshd and authenticate as the * account with a password of 257 to 1024 bytes for $5$/$6$ salts. The first attempt fails because of the shared-buffer overwrite; the second attempt in the same connection succeeds because the salt is cached. The attacker does not need to know any password.

Step 3: The full attack flow

From the original on medium.com

Root cause

The mistake is the interaction between three pieces of code:

  1. sshd's pw_password[1] check treats a one-character stored value as "no salt", so it calls xcrypt(password, NULL).
  2. pick_salt() then borrows a real $6$... salt from another account, so musl sees a valid salt and does not trigger its setting[0]=='*' guard.
  3. musl's crypt() returns the literal string "*" on failure instead of NULL, and sshd's strcmp() compares that against the stored "*" and accepts.

The existing defences did not stop it because the musl guard only covers the case where the stored field is used directly as the salt, and sshd's encrypted_password != NULL check only filters NULL, not the string "*". The pick_salt() mechanism, added to fix a timing side-channel, is what makes the borrowed salt available in the first place.

Impact

An attacker who knows no password at all can log in to any account whose shadow field is exactly *, on a musl-based, non-PAM sshd with PasswordAuthentication yes, provided the earliest $-hashed account in /etc/passwd order uses a vulnerable hash type. On Alpine's official cloud images, the alpine user has passwordless doas, so bypassing login for that single account is effectively root. Direct root login is blocked by the default PermitRootLogin prohibit-password. Accounts locked with ! are safe, and glibc distros such as Debian, Ubuntu and RHEL are not affected because libxcrypt returns NULL on failure.

Fix

The fix is in OpenSSH 10.6p2. The patch to auth-passwd.c is just a few lines:

C
+#define MIN_PASSWORD_HASH_LEN    4 #define MAX_PASSWORD_LEN 1024...-    return encrypted_password != NULL &&+    ret = encrypted_password != NULL &&+        strlen(pw_password) >= MIN_PASSWORD_HASH_LEN &&         strcmp(encrypted_password, pw_password) == 0;+    freezero(pw_password, strlen(pw_password));+    return ret;

Line by line:

  • +#define MIN_PASSWORD_HASH_LEN 4 adds a new constant: the shortest stored hash sshd will accept is 4 characters. The + at the start of a line in a patch means the line is being added.
  • #define MAX_PASSWORD_LEN 1024 sets a maximum password length of 1024 bytes.
  • - return encrypted_password != NULL && removes the old single-line return. The - means the line is being deleted.
  • + ret = encrypted_password != NULL && starts building the new return value in a variable called ret.
  • + strlen(pw_password) >= MIN_PASSWORD_HASH_LEN && adds the crucial check: the stored value must be at least 4 characters long. strlen counts the characters in a string.
  • strcmp(encrypted_password, pw_password) == 0; is the unchanged comparison, now part of the same expression.
  • + freezero(pw_password, strlen(pw_password)); wipes the stored hash from memory after use. freezero both frees the memory and zeroes it first.
  • + return ret; returns the result.

The key addition is strlen(pw_password) >= MIN_PASSWORD_HASH_LEN. The shortest valid hash (legacy DES) is 13 characters, so anything stored under 4 characters is excluded from the comparison entirely, whether it is *, !, or any error string musl might return. This single check closes every path described in this post, bcrypt salt-parsing bug included.

The patch also changes shadow_pw() to return an xstrdup()'d copy instead of a pointer into a shared buffer, and wipes it with freezero() after use, removing the root cause of the "needs two attempts" buffer-reuse behaviour described above. xstrdup() makes a fresh copy of a string in newly allocated memory, so nothing else can overwrite it behind sshd's back.

Remediation steps

  1. Update and restart sshd. Updating the package alone does not help if the running process is not restarted.
Bash
apk upgrade -U   rc-service sshd restart

Line by line:

  • apk upgrade -U tells Alpine's package manager, apk, to upgrade installed packages to their newest versions. -U means update the package index first.
  • rc-service sshd restart restarts the sshd service, so the new binary is actually loaded into memory. Without this, the old, vulnerable process keeps running.
  1. If you cannot update right now, turn off password auth (make sure key-based login works first):
Bash
echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/00-no-passwords.conf   sshd -t && rc-service sshd restart   sshd -T | grep -i passwordauthentication

Line by line:

  • echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/00-no-passwords.conf writes a small configuration file that turns password logins off. The > redirects the output of echo into the file, creating or overwriting it.
  • sshd -t && rc-service sshd restart first tests the configuration (-t), and only if the test passes (&&) restarts the service. This avoids locking yourself out with a broken config.
  • sshd -T | grep -i passwordauthentication prints the effective configuration and shows the password authentication line, so you can confirm the change took effect.

Alpine 3.16 to 3.18 do not read sshd_config.d by default, so add PasswordAuthentication no directly to /etc/ssh/sshd_config on those versions.

  1. Check for signs of abuse by looking for Accepted password for log lines naming an account that should never accept a password login:
Bash
grep -h 'Accepted password for' /var/log/messages /var/log/auth.log 2>/dev/null

Line by line:

  • grep -h 'Accepted password for' /var/log/messages /var/log/auth.log 2>/dev/null searches both log files for the phrase sshd writes when a password login succeeds. -h hides the filename from the output, and 2>/dev/null discards errors about files that do not exist.

Variants to test

  • bcrypt salt parsing. If the earliest $-hashed account uses $2a$, $2b$ or $2y$, try any password between 1 and 1024 bytes. This path was fixed separately upstream in commit 84f8f466.
  • Other musl-based, non-PAM sshd builds. Check ldd "$(command -v sshd)" | grep -i musl and sshd -T | grep -i '^usepam'.
  • Accounts with * in shadow. Run awk -F: '$2=="*"{print $1}' /etc/shadow.
  • Hash type ordering. Run awk -F: '$2 ~ /^\$[56]\$/{print $1}' /etc/shadow and check which $-hashed account appears first in /etc/passwd order.
  • Log review. Run grep -h 'Accepted password for' /var/log/messages /var/log/auth.log 2>/dev/null.

Glossary

  • SSH: a protocol for opening a secure text session on a remote computer over a network.
  • sshd: the SSH daemon, the background program on the server that handles incoming SSH connections.
  • Authentication: the process of proving who you are to a system.
  • Hash: a one-way scrambled output of a password, used to check passwords without storing them.
  • Salt: a random string mixed into a password before hashing, so identical passwords produce different hashes.
  • libc: the standard C library that every program on a Linux system relies on.
  • musl: a small, lightweight libc used by Alpine Linux.
  • glibc: the more common libc, used by Debian, Ubuntu and RHEL.
  • PAM: Pluggable Authentication Modules, a framework many Linux systems use to handle password checks.
  • Byte: one unit of data, roughly one character in simple text.
  • CVE: a public identifier for a known security vulnerability.
  • /etc/passwd: a plain text file listing every account on a Linux machine.
  • /etc/shadow: the companion file holding actual password hashes, readable only by the administrator.
  • SHA-256 / SHA-512: two hashing algorithms, identified in shadow entries by $5$ and $6$.
  • bcrypt: another hashing algorithm, identified by $2a$, $2b$ or $2y$.
  • MD5: an old, weak hashing algorithm, identified by $1$.
  • yescrypt: a modern hashing algorithm, identified by $y$.
  • DES: a very old hashing algorithm whose hashes are 13 characters long.
  • doas: a small program that lets a normal user run commands as the administrator, similar to sudo.
  • root: the administrator account on a Linux system, which can do anything.
  • PermitRootLogin prohibit-password: an sshd setting that stops root from logging in with a password.
  • PasswordAuthentication: an sshd setting that controls whether password logins are allowed at all.
  • MaxAuthTries: an sshd setting for how many login attempts are allowed per connection.
  • Timing side-channel: a leak where the time a system takes to respond reveals information it did not intend to share.
  • DoS: denial of service, an attack that makes a service too busy to serve real users.
  • POSIX: a standard defining how Unix-like systems should behave.
  • errno: a global variable where C functions store an error code.
  • NULL: a special pointer value meaning "nothing", used in C to signal failure.
  • strcmp: the C function that compares two strings and returns 0 when they are equal.
  • strlen: the C function that counts the characters in a string.
  • strrchr: the C function that finds the last occurrence of a character in a string.
  • memcmp: the C function that compares two blocks of memory byte by byte.
  • explicit_bzero: a C function that zeroes memory in a way the compiler cannot optimise away.
  • freezero: a C function that frees memory and zeroes it first.
  • xstrdup: a C function that makes a fresh copy of a string in newly allocated memory.
  • Buffer: a fixed-size chunk of memory used to hold data temporarily.
  • getspnam: the C function that looks up a shadow entry.
  • pick_salt: the sshd function that chooses a salt when none was supplied.
  • crypt: the standard C function that hashes a password with a given salt.
  • xcrypt: sshd's wrapper around crypt.
  • sys_auth_passwd: the sshd function that checks a password when PAM is not in use.
  • shadow_pw: the sshd function that fetches an account's stored hash.
  • Patch: a set of changes to source code that fixes a bug.
  • Commit: a recorded change to a code repository, identified by a short hash.
  • apk: Alpine Linux's package manager.
  • rc-service: the command that starts, stops and restarts services on Alpine.
  • Pipe (|): a shell operator that sends the output of one command into the next.
  • grep: a command that searches text for a pattern.
  • awk: a command that processes text line by line, splitting fields on a chosen character.
  • ldd: a command that shows which libraries a program is linked against.
  • sshd -T: a command that prints sshd's effective configuration.
  • sshd -t: a command that tests the sshd configuration for errors without applying it.
  • 2>/dev/null: a shell redirection that throws away error messages.
  • &&: a shell operator that runs the next command only if the previous one succeeded.

More by WhitGuidance

View all

40 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.