Riadh Chelbi

DevOps Engineer

← All posts

Any password over 256 bytes: how four reasonable changes unlocked musl sshd

On OpenSSH over musl libc, an account locked with "*" accepted any password of 257 to 1024 bytes. A walk through the code, line by line, and the four changes that had to line up.

12 min read

SecurityOpenSSHLinuxmusl

Some bugs aren’t in any one line of code. Each program involved is doing something reasonable, and the bug sits in an assumption one of them makes about the other. *sshole, found by Ozgun Kultekin, is the clearest case of that I’ve read in a while.

The short version: on an OpenSSH server built against musl libc (Alpine, OpenWRT, Buildroot, Yocto, and a large share of container images), an account whose password is locked with * accepted any password between 257 and 1024 bytes long. It did not need a particular password. Any long one worked. On Alpine that account is root.

I wanted to know exactly why, so I read the code on both sides: OpenSSH’s password check and musl’s crypt(). Below I go through it in the order a login runs. The bug is public and already fixed. I’m writing it up for the mechanism, because nothing about it is specific to sshd.

What a locked account is

Unix does not store your password. It stores a one-way hash of it in /etc/shadow:

alice:$6$abc123$k2P9...:20000:0:99999:7:::

$6$ names the algorithm (SHA-512-crypt), abc123 is the salt, and the long tail is the hash. To check a login, the system hashes the typed password with the same $6$abc123$ prefix and compares the result to the stored string. If they are equal, you knew the password.

To lock an account, you put something in that field that is not a hash at all. The convention since 3BSD in 1980 is a single *:

root:*:20000:0:99999:7:::

Every hash crypt() produces starts with $6$, $5$, $2b$, or is a 13-character DES string. None of them is *, so the comparison can never succeed, whatever the password. Key logins still work, because they never look at this field. That is what “locked” means, and it has held for forty years.

A locked account working as intended. The password you type goes through crypt() and becomes a real hash such as $6$ and so on. The stored field is a single star, which is not a hash, so the real hash never equals it and the login is refused.a locked account, the way it's meant to workthe password you typecrypt( pw, salt )a real hash $6$…stored field: *not a hash — locked$6$… ≠ *→ refused
A locked account, working as intended: a typed password is always hashed into a real hash, which can never equal the stored *, so the login is refused.

One detail matters later: the result of crypt() and the stored field are compared as plain strings. The check does not know that * means “locked”. It only knows that two strings are or are not equal.

What sshd does with your password

When UsePAM is off, OpenSSH checks passwords in sys_auth_passwd() in auth-passwd.c. Here is the core, trimmed, as it stood before the fix (4353fdc4, the left-hand side of the diff):

/* Just use the supplied fake password if authctxt is invalid */
char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd;
// the stored field, e.g. "*"
/*
* Encrypt the candidate password using the proper salt, or pass a
* NULL and let xcrypt pick one.
*/
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;

Look at the if. sshd only uses the stored field as the salt when it is at least two characters long. A real hash always is. A * is not: pw_password[1] is the terminating \0, so salt stays NULL.

It was not always like this. Before July 2016, a short field got a hard-coded fallback:

/* Encrypt the candidate password using the proper salt. */
encrypted_password = xcrypt(password,
(pw_password[0] && pw_password[1]) ? pw_password : "xx");

"xx" selects traditional DES, which only reads the first 8 characters of a password and never fails on length. A locked account hashed this way could never match *, however long the password was.

That changed with the fix for CVE-2016-6210, in 9286875a. For usernames that did not exist, sshd hashed with a fake salt whose algorithm differed from the one real accounts used. The timing difference, which long passwords made easier to measure, leaked which usernames existed. The fix replaced the "xx" fallback with salt = NULL, which makes xcrypt() call a new pick_salt() that returns a realistic salt from the system itself. The first version only looked at root. A week later, dbf788b4 made it keep searching when root is locked:

/*
* Pick an appropriate password encryption type and salt for the running
* system by searching through accounts until we find one that has a valid
* salt. Usually this will be root unless the root account is locked out.
* If we don't find one we return a traditional DES-based salt.
*/

pick_salt() walks /etc/passwd, reads each account’s shadow entry, and takes the prefix of the first one that looks like $id$salt$. If it finds none, it falls back to "xx", an old DES salt.

Note the part about usually this will be root unless the root account is locked out. On Alpine, root is locked, so the walk moves on and borrows the salt from the first account that has a real password.

How sshd picks a salt for a locked account. Root's stored field is a single star, too short to be a salt, so salt is null and xcrypt calls pick_salt. pick_salt walks the accounts: root is locked and skipped, bin has no hash and is skipped, alice has a real $6$ hash, so her salt $6$abc123$ is used. That selects SHA-512 crypt. If no account had a real hash, the fallback would be the DES salt xx.login attempt for rootroot : *stored field, 1 charactertoo short to be a saltsalt = NULLpick_salt()walk the accountssalt = "$6$abc123$"→ SHA-512 cryptaccounts, in orderroot *locked: skipbin !no hash: skipalice $6$abc123$…use this saltfirst real $id$ hash winsnone? fall back to "xx" (DES)
For a one-character field like *, sshd has no salt of its own, so pick_salt() walks the accounts and borrows the first real $id$ salt it finds. On Alpine that is never root.

So when someone tries a password for root on an Alpine box, sshd does not hash it against *. It hashes it as SHA-512 with alice’s salt, then compares the result with *. Normally that is still safe: the result is a $6$... string, and $6$... is not *.

What musl does when hashing fails

crypt() comes from the C library. POSIX says that on failure it returns NULL. That’s easy to get wrong. Plenty of code passes the result straight to strcmp() and crashes on NULL. A crash is bad, but at least nobody gets logged in.

musl chose differently. Its crypt() never returns NULL. When hashing fails, it returns a short string that is not a valid hash, so careless callers do not crash. The SHA-512 implementation says so in its header, on error “*” is returned, and the wrapper does exactly that:

char *__crypt_sha512(const char *key, const char *setting, char *output)
{
...
p = sha512crypt(key, setting, output);
...
if (!p || ...)
return "*";
return p;
}

Now, when does sha512crypt() fail? SHA-512-crypt does more work the longer the password is, so a server that hashes whatever it receives can be made to burn CPU. musl added a cap to prevent that:

/* key limit is not part of the original design, added for DoS protection. */
#define KEY_MAX 256
/* reject large keys */
for (i = 0; i <= KEY_MAX && key[i]; i++);
if (i > KEY_MAX)
return 0;

A password of 257 bytes or more makes sha512crypt() return 0. The wrapper turns that into "*".

The original 2012 change, b3c4cc12, shows musl saw this collision coming. In the DES code it did not always return "*":

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

If the salt passed in was itself *, musl returned "x" instead, so a failed hash could never equal a stored *. That guard only works if the caller passes the stored field as the salt. sshd passes alice’s salt instead, so the guard never sees the *.

Both decisions make sense on their own. Returning "*" instead of NULL means nothing crashes, and "*" can never match a real hash. The 256-byte cap stops a denial-of-service. The trouble is that "*" isn’t a neutral value: to anything that reads /etc/shadow, it means locked.

Four changes, ten years apart

Here are the pieces in the order they landed. Different people made each one, in different projects, and each had a good reason.

  1. Aug 2012, musl (b3c4cc12): crypt() returns an unmatchable string on failure instead of NULL, so callers that skip the NULL check do not crash.
  2. Aug 2012, musl (88bf5a8a): the new SHA-256/512-crypt reject keys longer than 256 bytes to block a CPU denial-of-service, and return "*" when they do.
  3. Jul 2016, OpenSSH (9286875a, dbf788b4): for CVE-2016-6210, accounts with no usable hash borrow a real salt from another account instead of using DES "xx".
  4. Dec 2021, Alpine (fbe926af, released in 3.16): root is locked with * instead of !. Earlier, CVE-2019-5021 showed that Alpine images had shipped with an empty root password. ! fixed that but also broke key logins for root when PAM was not in use, so Alpine switched to the classic *.
Four separate changes over ten years, each reasonable on its own. In 2012 musl's crypt returns a star on failure instead of null. In 2012 musl caps the input at 256 bytes as a denial-of-service guard. In 2016 OpenSSH hashes unknown users too, to hide which usernames exist. In 2022 Alpine locks root with a star instead of an exclamation mark. Together they add up to a login that should not happen.2012 · musl libccrypt() returns "*" on failure, not NULL2012 · musl libccap input at 256 bytes (DoS guard)2016 · OpenSSHhash unknown users too (hide usernames)2022 · Alpinelock root with "*", not "!"fourreasonablechangeseach correct alone — together, a login
Four changes, each correct on its own: musl's crypt() returns * on failure (2012), musl caps input at 256 bytes (2012), OpenSSH hashes unknown users too (2016), Alpine locks root with * (2022).

I don’t think a reviewer could have caught any of these. The bug only exists when all four end up on the same machine.

Putting it together

Now trace a login as root on an Alpine box running sshd without PAM, with a 300-byte password:

  1. sshd reads root’s stored field: *.
  2. * is one character, so salt = NULL and xcrypt() calls pick_salt().
  3. pick_salt() skips locked root and returns alice’s prefix, $6$abc123$.
  4. musl sees $6$ and runs sha512crypt(). The key is 300 bytes, which is over KEY_MAX, so it returns 0.
  5. The wrapper turns that failure into "*".
  6. sshd runs strcmp("*", "*"). They are equal.
  7. The login is accepted. You are root.

Now repeat it with a 20-byte password. Steps 1 to 3 are identical. At step 4, sha512crypt() succeeds and returns a real $6$abc123$... hash, which does not equal *, and the login is refused. The only thing that changed is the length.

The collision, side by side. On the left a 20-byte password is hashed normally into $6$ and so on, which is not equal to the stored star, so the login is refused. On the right a 300-byte password exceeds musl's 256-byte cap, so crypt fails and returns a star, the star equals the stored star, and the login is granted.≤ 256 bytes> 256 bytesa 20-byte passwordsha512crypt, alice's saltreturns $6$abc123$…strcmp( result, "*" )$6$… ≠ *login refuseda 300-byte passwordsha512crypt, alice's saltkey > 256: returns *strcmp( result, "*" )* == *login granted
The collision: a password under 256 bytes hashes normally and is refused; a password over 256 bytes overflows musl's cap, so crypt() returns *, which equals the stored * and is read as success.

There is also a ceiling. Before any of this, sshd’s auth_password() rejects passwords longer than MAX_PASSWORD_LEN, which is 1024 bytes. So the window is 257 to 1024 bytes: long enough to trip musl’s cap, short enough to get past sshd’s.

So it comes down to one character meaning two things. In musl, * means hashing failed. In /etc/shadow, it means this account is locked. sshd compared the two without knowing about either meaning.

Why each condition matters

Each condition on the affected list comes from a specific line above, and removing any one of them breaks the chain:

You are affected only when all five conditions hold at the same time: sshd is running on musl, PAM is not in use, password authentication is on, some account's field is a star, and another account has a real password. When all are true, any password of 257 bytes or more is accepted.affected only when every box is truesshd built on muslPAM not in usepassword auth enabledan account's field is "*"another account has a real passwordANDany password ≥ 257 bytes is accepted
You are affected only when all five hold at once: sshd on musl, no PAM, password auth on, an account locked with *, and another account with a real password. Then any password of 257+ bytes is accepted.
Condition Why it is needed
sshd built on musl On glibc or libxcrypt, a long key either hashes normally or fails with NULL or *0. sshd checks for NULL, and *0 is not *. Only a library that returns exactly * lines up.
PAM off With PAM, the password is checked by pam_unix, not by sys_auth_passwd(). Alpine’s openssh-server does not use PAM by default.
Password auth on Without it, sshd never calls sys_auth_passwd(). On is the default.
A target account stores * A one-character field is what sends sshd to pick_salt(), and * is what the failure value has to match.
Another account has a real $id$ hash Without one, pick_salt() falls back to "xx", which selects traditional DES. DES only uses the first 8 characters, so a long password still produces a real 13-character hash, and the login is refused.

That last row is the surprising one. A fresh Alpine box where nobody has set a password has nothing to borrow from, so it is safe. The box only becomes vulnerable once someone adds a normal user with a password, which is exactly what happens on real servers.

glibc distributions, anything using PAM, Dropbear, and OpenBSD are not affected. One case is much worse: on Alpine’s official AWS and Azure images, the default alpine user has passwordless doas, so getting into that account means getting root.

Why it took ten years to notice

All the ingredients existed by 2016. Root as * on Alpine arrived in 2022. Even then, no one noticed for four years:

  • Nobody tests this combination. OpenSSH is developed and tested on OpenBSD and glibc. musl does not run sshd in its tests. Each project’s CI passed, and the bug lives only where they meet.
  • Most of Linux uses PAM. pam_unix checks locked accounts on its own and never reaches this code.
  • Nobody types a 300-byte password by accident. Ordinary failed logins, even millions of them from brute-force bots, use short passwords and get refused correctly.
  • The warning signs pointed elsewhere. A 2013 Debian discussion covered crypt() returning NULL. A 2024 musl mailing-list thread covered busybox passwd failing on 257-character passwords. Both were about failure, and neither asked what the failure value would be compared against.

Kultekin found it the slow, careful way: building sshd against glibc and musl, with and without PAM, with and without shadow, and sending each build about 17,600 unusual logins. Every build agreed except one, musl without PAM, which accepted logins it should have refused. That’s what I like about differential testing. You don’t need to guess where the bug is.

The fix, and what to do

Damien Miller fixed it in 4353fdc4 on November 4, 2026, with one more condition in the final comparison:

#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;

The commit message says plainly where the OpenSSH team thinks the bug is: “We do not consider the root cause to be within OpenSSH.”

A stored field too short to be a real hash can no longer match anything, whatever crypt() returns. That closes the hole in sshd, whichever C library is underneath. I think sshd is the right place for it anyway, because the caller is the one that knows a one-character field can’t be a hash.

Update OpenSSH. According to Kultekin’s write-up, the fix is in OpenSSH 10.6p2. On Alpine:

Terminal window
apk upgrade openssh

If you can’t update yet, turn off password logins. On anything facing the internet you probably want this anyway:

Terminal window
echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/00-no-passwords.conf
rc-service sshd restart

With no password authentication, sshd never calls sys_auth_passwd(), so the whole chain is gone.

Check whether it was used against you. In your auth logs, look for an Accepted password line for an account whose shadow field is *. That should never happen, so treat any match as a compromise. Kultekin published a checker at github.com/oz9un/sshole.

What I’m taking from it

I’d have approved every change in this chain. Returning a sentinel instead of NULL, capping key length, hiding which usernames exist, locking root: they’re all defensive moves, and together they let anyone in with a long enough password.

What went wrong is a sentinel value crossing a boundary. Inside musl, "*" is a safe failure value because it is not a hash. musl cannot know that the caller will compare it with a field where "*" means something else. Inside sshd, comparing two strings for equality looks like the most obvious check there is, and nothing in the code says that one side might be an error code.

Now when I write a magic value in my own code (-1, "", 0, "*"), I try to ask who else will end up holding it, and whether it already means something to them.

References

  1. O. Kultekin, “*sshole,” Nov. 2026.
  2. O. Kultekin, sshole: detection tooling, GitHub repository, 2026.
  3. D. Miller, “avoid password authn bypass,” OpenSSH Portable, commit 4353fdc4, Nov. 4, 2026.
  4. D. Tucker, “Determine appropriate salt for invalid users,” OpenSSH Portable, commit 9286875a, Jul. 15, 2016.
  5. D. Tucker, “Search users for one with a valid salt,” OpenSSH Portable, commit dbf788b4, Jul. 21, 2016.
  6. R. Felker, “make crypt return an unmatchable hash rather than NULL on failure,” musl libc, commit b3c4cc12, Aug. 9, 2012.
  7. R. Felker, “add sha256/sha512 crypt,” musl libc, commit 88bf5a8a, Aug. 29, 2012.
  8. A. Xu, “scripts/genrootfs.sh: locked -> invalid password,” Alpine aports, commit fbe926af, Dec. 10, 2021.
  9. OpenSSH Portable, auth-passwd.c and openbsd-compat/xcrypt.c, source at commit 4353fdc4.
  10. musl libc, src/crypt/crypt_r.c and src/crypt/crypt_sha512.c, source at commit 7813e911.
  11. MITRE, “CVE-2016-6210,” CVE record, 2016.
  12. MITRE, “CVE-2019-5021,” CVE record, 2019.