News for hackers. Stuff that matters.
Re:Sshole by mpyne on Thursday November 05, 2026 @09:17AM (#50379342)
OK, I think I see what’s going on with this, in this configuration.

The goal from an attacker’s perspective is to get this to be true: `$ret = crypt($pw, $hash); $ret == $hash` when called by OpenSSH’s sshd. This is how sshd validates that the user logging in knew the account password.

The `$hash` is the “settings” to the crypt call and will normally look like “$6$--gibberish” for users with passwords set, but could look like “*” or “!” for users not intended to be able to login.

The bug is from the intersection of all of these things:

1. musl can return “*” for errors, rather than leave the return value NULL. Other libc have adopted something like this too, but seem to use a different result “*0”.

2. musl can also return “+” for errors, but only does so if $hash starts with “*”. This is intended to eliminate the possibility of an error causing `$ret == $hash` to be true, however it assumes that applications calling `crypt()` will set $pw and $hash to values corresponding to the `$ret == $hash` comparison to be made immediately afterwards.

3. OpenSSH can be convinced to pass the hash of a different user if the hash is “*” or “!” to avoid timing attacks that can enumerate the user list, so it will set $pw and $hash to correspond to different users. $hash will be a real “$6$--gibberish” style hash in this case, and OpenSSH expects `crypt()` to either return NULL or return a hash string. But now there’s two hashes OpenSSH uses. It does: `$ret = crypt($pw, $hash2); $ret == $hash1`;

4. This should normally not be a problem because OpenSSH will pass in valid $pw and $hash2 that should not lead to errors in hashing, so the $ret that musl generates should be a real hash that cannot match the “*” or “!” $hash1 for the login-disabled user. However as a DDoS mitigation, musl will return error if the password is too long when using SHA-2-based hashes (the default, it seems).

5. This error will result in a non-NULL result of “*” or “+”. Since OpenSSH passed in a real hash ($hash2), musl will return “*”, which compares equal to the actual user hash $hash1 for the disabled-login user.

The OpenSSL adjustment ensures a minimum hash length for the user before logging them in, even if crypt() succeeds somehow.

Re:Sshole by idlewords on Thursday November 05, 2026 @09:30AM (#50379516)
This is a vastly clearer explanation than the linked page. Thank you!
Re:Sshole by alexgoodhart on Thursday November 05, 2026 @09:40AM (#50379656)
Because Claude wrote the linked page. Claude is impressively bad at communicating these days. with gpt-5.6+ approaching Claude level like 30% of time and Gemini much clearer but also the most annoying 7 year old ever, it’s a pretty lame environment especially for people who r new to everything
Re:Sshole by endymi0n on Thursday November 05, 2026 @10:20AM (#50380217)
Until Opus 5.0 I'd have agreed with you, but Opus 5.5 is honestly one of the best I've ever sparred with, vastly better than the rest, including Astra imho. Especially so when prompting for clear top-down, first-principles communication.
Re:Sshole by yearolinuxdsktp on Thursday November 05, 2026 @10:38AM (#50380474)
Opus 5.5 is much better, but IME I always have to force it to review its writing (Opus 5.5) to get it to put the most important facts first (and not bury the lede). It loves to park the main point far away after intermediate clauses. It always writes “premise, so consequence.” It takes a prompt asking to review against rules in context for it to fix it.

The ‘concise’ output style setting is bad with Opus 5.5, as it will often spit out a cryptic (is this really English?!), allergic-to-commas concise response, which takes more time to parse.

Re:Sshole by xnorswap on Thursday November 05, 2026 @11:04AM (#50380856)
Oh it loves to bury a lede.

    < mundane detail>
    < If you don't run this command your computer will explode>
    < exposition > 
    < mundane reminder to follow up something else >
Then 3 back and forths later, your computer explodes, and claude has the cheek to point out when questioned that it did warn you.
Re:Sshole by ericbarrett on Thursday November 05, 2026 @10:56AM (#50380740)
Disagree, I review a lot of Opus 5.5 code and its comments and docs are still pretty inane and Claudish. Is it better than the 4.x and 5.0 era, sure. But it's still nouning the verbs, using colons everywhere, a-not-b, "a foos the b" etc. A lot of lingual knots that need a human hand to untie.
Re:Sshole by brabel on Thursday November 05, 2026 @11:40AM (#50381279)
I was using opus5.5 for everything but since I tried google Argon4 that has been my favorite for writing. It’s clear and to the point.
Re:Sshole by pizzafeelsright on Thursday November 05, 2026 @11:42AM (#50381296)
I wondered about this myself as the explanations and documents I have been maintaining are becoming increasingly 'slop', but a different kind of slop.

In the past I could get an explanation, where I was able to track the line of thought. Now when I read through the explanation it is like someone has taken two or three explanations and merged them into each other, like there is a combining of iterations without clarity.

example:

The tree is blue.

The tall tree has the color of blue.

the tree, while tall, is blue.

That finally gets squished into: the blue tall tree has height and is evident of blue.

Is this double speak or injected double effort of words?

Re:Sshole by phyzome on Thursday November 05, 2026 @02:33PM (#50383351)
Some of the page is also just wrong.

Except it turns out that at least one of those things is because I didn't enable JS, and the static text is wrong!

(Turning on JS did not actually help, because then the page is filled with horrible, cheesy animations and I can't actually read any of it.)

Re:Sshole by markasoftware on Thursday November 05, 2026 @11:50AM (#50381387)
Yep, the linked page doesn't /feel/ AI written (maybe it's using a grok or muse model whose tone I don't quite recognize yet?) but it kinda just states a lot of facts that make sense on their own but don't cohere into a whole vulnerability like the comment above does.
Re:Sshole by numeri on Thursday November 05, 2026 @01:25PM (#50382540)
I think it's just Claude prompted to write in a casual, conversational, no caps style.

The surface-level hints are gone, but the attempt to make every sentence pithy, the decisions on what information to present and what to assume the audience knows, and the over-emotionalization are all still there.

Re:Sshole by lukax on Thursday November 05, 2026 @02:50PM (#50383568)
Of course it is. "one debian box, one alpine box" is an obvious Claudeism.
Re:Sshole by ghostly_s on Thursday November 05, 2026 @03:44PM (#50384238)
and what same human would embed two linux systems (??) in a blog post just for a demo that prints "pass"/"fail" that hardly anyone will bother to interact with?
Re:Sshole by larsonian on Friday November 06, 2026 @04:36AM (#50390202)
The demo is obviously vibe-coded, but that doesn't necessarily have to mean the prose comes from Claude too (although in this case it clearly does).
Re:Sshole by pigpop on Friday November 06, 2026 @09:41AM (#50392889)
It feels very AI written, it's just not the blatantly AI default style. Pretty much any prompt with a "write X in this style: [example text]" will produce writing like this.
Re:Sshole by chuckadams on Thursday November 05, 2026 @10:20AM (#50380216)
I think the conclusion that can be drawn from this is that the behavior of crypt() is howling-at-the-moon insane, and it should no longer be considered for any system built in this century, at least not without extensive wrappers that correct and normalize all these edge cases.
Re:Sshole by markasoftware on Thursday November 05, 2026 @11:48AM (#50381371)
Conclusion is type safety is important
Re:Sshole by zbentley on Thursday November 05, 2026 @12:26PM (#50381800)
Specifically, that the lack of tagged unions (or really, structured return types in general; you can pretend those are a tagged union if you believe hard enough) in C library interop conventions is a terrible foundation on which to build widely-used APIs.

And that just ends up indicting the C language itself. Can't send errors down a separate channel; folks might not inspect errno. Can't return NULL on error, folks might compare it blindly to another result. No tagged unions, so can't return one. Can't crash on error because there's no scoped error handling. Can't return a struct for checking .error/.result separately, because alignment and equality (and tearing and accidental clobbering and more) make that brittle as hell for widely-used APIs.

C is not a good language for library APIs. Like, really not. It has its uses/strengths, sure, but without even getting into the typical gripes people have about C, libraries--one of the things that it is used for the most--are one of the things for which it is the least well-suited.

"But it has a stable ABI!" So does a land mine. Until you touch it.

Re:Sshole by cozzyd on Thursday November 05, 2026 @03:22PM (#50383973)
you can return a struct just fine... most API's don't though.
Re:Sshole by cowlevel on Friday November 06, 2026 @12:09AM (#50388453)
Historically it didn't work well between different compilers. Maybe it still doesn't.
Re:Sshole by chuckadams on Friday November 06, 2026 @09:35AM (#50392793)
Passing and returning structs by value has been part of C since C89. Most compilers pass small structs in individual registers, and nowadays with LTO they'll even elide the copy of bigger ones if they can. What's definitely the case though is that by-value structs weren't a common thing when most of the Unix API was written.
Re:Sshole by kps on Friday November 06, 2026 @10:49AM (#50393843)
Structure assignment, passing, and returning were added in UNIX V7 C.
Re:Sshole by citrin_ru on Thursday November 05, 2026 @12:40PM (#50381958)
My conclusion is that an old tradition of not returning NULL in crypt as a workaround for buggy code which doesn't handle errors was a bad idea.
Re:Sshole by jeremyjh on Thursday November 05, 2026 @01:04PM (#50382226)
This is still a consequence of a poor type system.
Re:Sshole by creata on Thursday November 05, 2026 @01:59PM (#50382952)
I don't think so. Even in a language with a good type system like Rust, somebody could have made this API:

    /// Hash the phrase with the given setting.
    fn crypt(phrase: &[u8], setting: &[u8]) -> [u8; CRYPT_OUTPUT_SIZE];
Then, in a later version, `crypt` needs to become fallible, so they'd need to signal errors somehow. But because they really want to preserve backward compatibility, they can't replace the output with a Result type. And so they end up doing the same thing that was done in libcrypt - they output some error value and hackily make sure it's not equal to the `setting` string, under the mistaken assumption that the output of `crypt` would only ever be compared to the `setting` string. And then the same problem happens.

Maybe I'm wrong, but it looks to me like the exact same incentives and ways to screw things up exist in C and in Rust for this particular bug.

Re:Sshole by gf000 on Thursday November 05, 2026 @02:20PM (#50383209)
You are looking at it from the wrong direction.

The problem is not that you can write bad stuff in rust, the problem is that this particular usage pattern can't be sanely coded in C. This is a public API that should inform users and enforce certain properties. A Results type does exactly that, you would have to go way out of your way to force invalid stuff through that type alone.

Re:Sshole by creata on Thursday November 05, 2026 @02:35PM (#50383391)
I don't think so. In both Rust and C, the solution is the same - make the function explicitly fallible, instead of trying to preserve backward compatibility. In C, the function would probably just look like this, returning zero on success and negative on failure:

    int crypt2(const char *phrase, const char *setting, char *out);
You can call such a signature "insane" if you want, and that's fine, but it would have averted the bug that is the topic of discussion.
Re:Sshole by markasoftware on Thursday November 05, 2026 @03:41PM (#50384209)
what you are suggesting is a form of type safety. There are still degrees of type safety even in C, and this bug resulted from deciding that backwards compatibility is more important than type safety, which I think we agree on.
Re:Sshole by lokar on Thursday November 05, 2026 @04:12PM (#50384515)
And C has effectively deprecated bad APIs over the years. Just not this one.
Re:Sshole by quotemstr on Thursday November 05, 2026 @04:45PM (#50384891)
It's a perfectly sane signature, especially coupled with an API surface that uses the return channel for errors generally.
Re:Sshole by kazinator on Friday November 06, 2026 @06:57PM (#50400175)
[delayed]
Re:Sshole by cowlevel on Friday November 06, 2026 @12:07AM (#50388446)
This isn't good either. Crypt is a pure computation that can't fail for arbitrary reasons. The former implementation could fail if the salt was invalid, which is something you could guarantee. Now it also fails if the password is invalid. That's new behaviour and no matter which way you wrap it up it has the potential to be incompatible. They should have added the maximum length recommendation to the man page, and let DoS attacks continue until the calling software was updated, not the crypt library.
Re:Sshole by markasoftware on Thursday November 05, 2026 @02:35PM (#50383383)
IMO type safety requires both language features and a mindset where you take efforts to keep things type safe. Your example has only the former.

For example, in a Rust web app, you can choose to use String for encoded URLs, unencoded URL fragments, escaped html, unescaped HTML, usernames, etc. Or you can choose to use newtypes and carefully design all APIs to only take and return the correct newtypes.

Re:Sshole by eru on Thursday November 05, 2026 @09:56PM (#50387599)
Yes, even in Lean you can just refuse to prove any properties.

But if you have a stronger and more expressive type system, you are more inclined to use it, instead of looking for silly workaround like in C.

Re:Sshole by skew-aberration on Thursday November 05, 2026 @10:28PM (#50387803)
You wouldn't be concerned about breaking backward compatibility with rust though, would you? A recompile would be needed anyway and the change would be detected and enforced. The rationale for the bad API here (two types in one variable) was that users were ignoring NULL - that's the part which wouldn't happen in rust.
Re:Sshole by justmedep on Thursday November 05, 2026 @10:56PM (#50387972)
Maybe he meant binary compatibility.
Re:Sshole by cowlevel on Friday November 06, 2026 @12:02AM (#50388430)
They would have to make it crypt2.
Re:Sshole by speedstyle on Friday November 06, 2026 @07:41AM (#50391650)
OP suggests it was always fallible, they switched to a sentinel to mitigate callers dereferencing null, which they wouldn't have with Option/Result. https://git.musl-libc.org/cgit/musl/commit/?id=b3c4cc12

But in your version, you can't preserve backwards compatibility, making an infallible function fallible is a breaking change. For something comparable to libc you might want to (eg Rust std still has mem::uninitialized), but even with security issues, I feel like people would be more inclined to deprecate for a new function (or panic, which does have its own problems).

A good type system also means things are written with better forwards compatibility, and can be safely changed later. The Rust equivalent to `crypt` likely wouldn't exist: a low-level library would just provide hash functions, leaving callers to mitigate DOS etc; a broader library might return some opaque handle with equality/serialization, which you couldn't try to compare to a passwordless user; a high-level library would parse the account store itself. None of these really need to change in incompatible ways, they have all the information to add features and fixes at their own level of abstraction.

Re:Sshole by shess on Thursday November 05, 2026 @11:51PM (#50388372)
The idea of trying to provide a workaround for buggy code calling crypt() is terrifying. For sure, trying to grease the skids for buggy code calling printf(), go for it. But it is hard to imagine cases where slightly-incorrect usage of crypt() is a good idea.
Re:Sshole by rjbwork on Thursday November 05, 2026 @01:13PM (#50382342)
My thoughts exactly.

"Make invalid states unrepresentable" is such a useful adage when designing even basic systems, much less the gates to control your server.

Re:Sshole by GuB-42 on Thursday November 05, 2026 @03:37PM (#50384157)
In this particular case, it is type safe. NULL, by the C standard does not refer to an object. It means that every pointer in C is effectively an option type, which mean that a function that returns a pointer can return NULL for "no result", which, in the case of crypt() is perfectly adequate.

It is the opposite that is unsafe, that is, when the returned value can't be NULL, but it stills returns a pointer. C++ has references in an attempt to fix this problem.

Because C tends to prioritize performance over safety, a NULL pointer dereference is considered undefined behavior and the compiler can invoke nasal demons if it makes the code go faster, but with the right options, you can have it checked and invoke what in other languages would call a panic handler, but on UNIX is the SIGSEGV signal. You can then attach a debugger or read the core file and see what went wrong.

Note: I am not talking about "char *" for strings, that one is unsafe, but NULL is not. It is just a special case of an option type, or a result type, or an error union. Modern languages just extended this idea to objects other than pointers, and with more than one type of error.

Re:Sshole by poly2it on Thursday November 05, 2026 @04:02PM (#50384422)
You might consider it type safe according to C's rules, but it is not type safe according to contemporary opinion because the success type and error type are the same.
Re:Sshole by quotemstr on Thursday November 05, 2026 @04:40PM (#50384831)
Contemporary opinion among who? Words mean things, and "type safe" simply does not mean "agrees with my preferred style of error reporting"
Re:Sshole by poly2it on Thursday November 05, 2026 @05:05PM (#50385153)
Papers on type soundness from the last 30 years usually explore the domain further than C semantics.
Re:Sshole by quotemstr on Thursday November 05, 2026 @05:17PM (#50385277)
That's not the same as asserting that soundness requires adherence to the current fashion, sum types over results and errors. TIMTOWTDI.

You don't have to think C is sound or good to distinguish a disfavored API style from mathematical unsoundness. There are infinitely many type safe APIs and languages that are, despite their soundness, ugly and hard to use.

Re:Sshole by ciefa on Thursday November 05, 2026 @05:17PM (#50385278)
Can you link some?
Re:Sshole by pron on Thursday November 05, 2026 @06:12PM (#50385893)
This is not about soundness. Soundness means that the program behaves in accordance with what its types express. What you're saying is that papers on types show how you can use types to express more constraints.
Re:Sshole by ranger_danger on Thursday November 05, 2026 @08:45PM (#50387111)
There can be other valid perspectives and definitions of that word than yours.

I think almost all (tech) arguments stem from simple disagreements and/or different assumptions made on the definition of a (subjective) term.

Re:Sshole by pron on Thursday November 05, 2026 @09:55PM (#50387597)
You may be right in general, but soundness comes from formal logic, where they're pretty fastidious with their definitions. Soundness certainly doesn't mean the expressivity of the types (i.e. what constraints they can represent); it's about the relationship between the runtime behaviour of a program and the types in the code.
Re:Sshole by ranger_danger on Friday November 06, 2026 @02:58AM (#50389437)
Again I think you're trying to push a specific definition as more correct than OP's somehow. Why not just ask them what they meant to understand their intent/context instead of saying they are wrong?
Re:Sshole by pron on Friday November 06, 2026 @07:09AM (#50391425)
I think I understand their point and even said, "What you're saying is that papers on types show how you can use types to express more constraints," and that's correct. I merely pointed out that that's not soundness, which is something I think they'd like to know. There may be some leeway in the definition of soundness and how it's similar to or different from type safety, but either way, type expressivity is something different altogether (and C certainly has issues with both expressivity and type safety or soundness, but they're different issues). So the point isn't to win - the argument was right and I'm not claiming that C's type system is expressive - but to explain the different terms and their meaning in programming languages and formal semantics.
Re:Sshole by majorchord on Thursday November 05, 2026 @08:38PM (#50387072)
Opinion among people who know better than to try to explain subjective words with dogma, because that just makes them look silly.
Re:Sshole by eru on Thursday November 05, 2026 @09:37PM (#50387465)
> [...] because the success type and error type are the same.

That's a bit weird? In Rust, if you have an thing that returns Result<String, String> that's still type safe, even though success and error types are the same.

I think I know what you want to express..

You might say it's in-band vs out-of-band error signalling?

Re:Sshole by itishappy on Thursday November 05, 2026 @10:13PM (#50387717)
> In Rust, if you have an thing that returns Result<String, String> that's still type safe, even though success and error types are the same.

These types are not the same:

    Ok<String>
    Err<String>
Re:Sshole by markasoftware on Friday November 06, 2026 @12:57AM (#50388711)
Those are not types at all. Ok and Err are type constructors for the Result<A, B> type that take arguments of type A and B respectively.
Re:Sshole by SkiFire13 on Friday November 06, 2026 @02:00AM (#50389078)
> type constructors

Nit: the type constructor is `Result`: given two types `A` and `B` (not instances of those types, but actual types) it gives you a new type `Result<A, B>`.

`Ok` and `Err` are called "variants" and can be used to construct a new _instance_ of `Result<A, B>`.

Re:Sshole by markasoftware on Friday November 06, 2026 @04:41PM (#50398887)
Ah, thanks! I'd remembered the term "data constructor" from Haskell and called it a type constructor instead.
Re:Sshole by kazinator on Friday November 06, 2026 @06:52PM (#50400123)
[delayed]
Re:Sshole by kazinator on Friday November 06, 2026 @06:48PM (#50400090)
[delayed]
Re:Sshole by eru on Friday November 06, 2026 @09:35PM (#50401089)
Basically, you need the whole 'success and error types are different' in a language like Python if you make the return type something like "int | string", where 'string' stands for your error message.

Of course that breaks down, when the success type is also an error message, eg when you are looking up something in a catalogue of error messages.

Rust has no trouble with this, for exactly the reasons you line out.

Re:Sshole by LordDragonfang on Thursday November 05, 2026 @06:39PM (#50386163)
> the compiler can invoke nasal demons if it makes the code go faster

I had never heard that phrase, and was delighted at the answer when I googled it its origin, thank you:

http://www.catb.org/jargon/html/N/nasal-demons.html

> “When the compiler encounters [a given undefined construct] it is legal for it to make demons fly out of your nose” (the implication is that the compiler may choose any arbitrarily bizarre way to interpret the code without violating the ANSI C standard)

Re:Sshole by cowlevel on Friday November 06, 2026 @12:01AM (#50388422)
However this is limited by the compiler's actual abilities and code. The C standard doesn't forbid nasal demons, but the compiler isn't programmed to invoke nasal demons and isn't running on hardware with that capability, so it won't happen.

I've heard nasal demons invoked as a literal possibility. No they are not a literal possibility.

Re:Sshole by Xirdus on Friday November 06, 2026 @01:33AM (#50388918)
Maybe your compiler isn't, but GCC is designed to summon every nasal demon it can. It especially loves to elide null pointer checks. There was a PR that almost made it to Linux mainline that did some weird stuff in kernel space where memory mapped to address 0 is valid and contains important stuff. It got a pointer, read data from it, then checked if pointer is null before giving root permissions for some operation. Reading the code, everything seems alright. Even stepping through it with debugger shows that it works. But when compiled with -O2 or higher, GCC removed the null check and now everybody got root permissions unconditionally - because reading from null pointer is UB regardless of circumstances, and GCC treats UB as dead code even if it is reachable.
Re:Sshole by cowlevel on Friday November 06, 2026 @02:22AM (#50389227)
> GCC is designed to summon every nasal demon it can.

Which is zero, to be clear. There's not even a standard USB device class for a nasal demon releaser

A null check elision is not a demon up my nose - it's a null check elision.

Re:Sshole by neomantra on Friday November 06, 2026 @05:37AM (#50390654)
Having made devices for other human holes, you can just use the standardized HID class. It can be adapted for nasal demons incoming and outgoing.
Re:Sshole by Xirdus on Friday November 06, 2026 @09:07AM (#50392458)
Sure, and char[] is no string because you can't tie anything with it. And don't get me started on the insects that allegedly live inside digital source files - that's an absurd concept, no self respecting computer specialist should be talking like that.
Re:Sshole by miki123211 on Friday November 06, 2026 @05:47AM (#50390721)
Wait, so if you're running on embedded, you're not allowed to store anything at address 0, requiring you to waste that little bit of RAM?

That's... a bizarre choice, considering how religious C is about not making any assumptions about what a machine can and cannot do, even going to the trouble of working with non-IEEE floats and int types that are not a multiple of 8 bits.

Re:Sshole by Xirdus on Friday November 06, 2026 @08:44AM (#50392212)
Unfortunately yes. ISO/IEC 9899:1999 footnote 83: "Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer (...)."
Re:Sshole by jasomill on Monday November 09, 2026 @08:37AM (#50425422)
No. IIRC, you’re just not allowed to use a constant expression evaluating to 0 as a pointer to construct a non-null pointer to address zero.

There’s no requirement that the in-memory representation of a null pointer be all-zeroes, only that 0 in source code represents whatever it is.

Regardless, I agree that it’s a bizarre choice.

Re:Sshole by itishappy on Thursday November 05, 2026 @09:52PM (#50387565)
> It is the opposite that is unsafe, that is, when the returned value can't be NULL, but it stills returns a pointer.

Without the ability to express a non-nullable type, C cannot be unsafe in this way!

Would this mean all pointers in C are type safe?

Re:Sshole by itishappy on Thursday November 05, 2026 @10:18PM (#50387751)
> It is just a special case of an option type, or a result type, or an error union. Modern languages just extended this idea to objects other than pointers, and with more than one type of error.

These are not the same, and your second sentence suggests why. Option has but a single error type, but result types and error unions allow arbitrary types of error.

Re:Sshole by SkiFire13 on Friday November 06, 2026 @02:03AM (#50389091)
> In this particular case, it is type safe

That depends on how you interpret the pointer type, but in any case there are multiple interpretation and just the fact that these exist will create confusion and type unsafety.

Re:Sshole by miki123211 on Friday November 06, 2026 @05:43AM (#50390700)
In theory, having newtons and pounds force be represented as `float` is type safe. In practice, it destroyed a multi-million-dollar NASA spacecraft because of human error.

If NASA were to use the equivalent of `pub struct Newtons(f32); pub struct PoundsForce(f32);`, where the types Newton and PoundsForce were not interchangeable, this would never have happened[1].

[1] I'm aware that that story is a bit more complicated than that, that CSV files were involved (which are, again, not type safe), and that, in that particular scenario, more would have to be done to preserve type safety across formats, vendors and codebases, but my point still stands.

Re:Sshole by gugagore on Friday November 06, 2026 @07:20AM (#50391504)
I think related to your caveat is:

https://lexi-lambda.github.io/blog/2020/11/01/names-are-not-...

> The newtype is opaque, so the only way to observe it is to convert it back to a [f32].

Re:Sshole by annex-winged-cr on Friday November 06, 2026 @06:00AM (#50390812)
The implicitness is exactly the problem. The workaround that caused this vulnerability was done because people assumed that crypt() would never return null.

You don't even need a fancy result type. A simple Option<String> would've forced downstream users to consider the failure case, avoiding this situation in the first place.

Re:Sshole by f33d5173 on Friday November 06, 2026 @12:21PM (#50395327)
.unwrap()

Now what?

Re:Sshole by shakow on Friday November 06, 2026 @12:44PM (#50395636)
First you shouldn't have unwraps in prod code, and you can verify that in your CI/build process/whatever. Second, now you have a crash of the SSH server, which is arguably much better than some random logging in as root.
Re:Sshole by f33d5173 on Friday November 06, 2026 @04:38PM (#50398870)
This isn't about "you", it's about whether any consumer of your code is using unwrap on the result, which currently is perfectly safe to do. The equivalent in C is returning NULL, which would also have caused a crash. They decided not crashing was preferable, which is how we ended up here.
Re:Sshole by kazinator on Friday November 06, 2026 @06:15PM (#50399812)
[delayed]
Re:Sshole by shakow on Friday November 06, 2026 @09:01PM (#50400932)
I don't really care about the form of the argument when the concrete results are that (i) “no unwrap in prod” is trivial to ensure through the toolchain, (ii) even though, its consequences are “damn it crashed” instead of “welp I guess this guy is root now”.
Re:Sshole by kazinator on Sunday November 08, 2026 @01:57AM (#50411035)
[delayed]
Re:Sshole by shakow on Sunday November 08, 2026 @05:31AM (#50412000)
> And that analogous situation can happen in the safer language where crypt returns an Optional(String) which some bad programs assume is always present.

Once again, no, because these unknown programs would just crash on the `.unwrap()`; not get in a silently corrupted state. Same causes, different effects.

Re:Sshole by kazinator on Sunday November 08, 2026 @11:38AM (#50414753)
[delayed]
Re:Sshole by dadoum on Saturday November 07, 2026 @06:46AM (#50403712)
Absolutely not. Unwrap is a language rule, so everyone knows unwrap is not a safe thing to do and writing it even once is an explicit dismissal (and you should document it). On the other side, knowing that crypt does not necessarily return a hash is easily overlooked and forgotten, there is no code smell that can hint you that you are doing things wrong.
Re:Sshole by kazinator on Saturday November 07, 2026 @10:34AM (#50405412)
[delayed]
Re:Sshole by ahepp on Friday November 06, 2026 @06:00PM (#50399658)
I think the argument would be that in C people will look at a char* and think "string" rather than "string or null". Thus consumers of the library not checking the result and the maintainer trying to be helpful by putting a "safe" value in there for the error case.

Whereas if the library returns something that is unambiguously an option type, consumers unambiguously call unwrap at their own risk.

Of course you do have a point (assuming I'm picking up what you're suggesting correctly) that all pointers in C are option types. But I think there's a cognitive ergonomics aspect to this where an option type more clearly relays the library authors' intent.

Re:Sshole by eviks on Saturday November 07, 2026 @12:26PM (#50406288)
Now you have an easy way to discover the bug
Re:Sshole by kazinator on Friday November 06, 2026 @06:10PM (#50399773)
[delayed]
Re:Sshole by alerighi on Friday November 06, 2026 @06:11AM (#50390913)
Exactly, whoever program in C knows that every function that returns a pointer may return NULL (even if not documented) and thus every pointer must be checked.

However a better API (to me) that I would have written was:

    crypt_error_t crypt(...args, char *result, size_t resultLength) 
That way btw the function doesn't need to allocate memory inside, which is (being a mostly embedded programmer) something I don't like at all. Plus returning an error enum makes it clear instead of having to look at errno.

But POSIX API is not something well designed, it dates back to the '80 so... probably today would be written completely differently

Re:Sshole by kazinator on Friday November 06, 2026 @06:20PM (#50399863)
[delayed]
Re:Sshole by eru on Thursday November 05, 2026 @09:36PM (#50387454)
That and in-band signalling is error-prone.

Another example that C programmers love: using 0 to mean infinity. Eg when you have a timeout setting, and 10 means ten seconds, but 0 means infinity seconds instead of zero seconds.

Re:Sshole by justmedep on Thursday November 05, 2026 @11:00PM (#50388003)
That’s just a very bad API. You could do the same in Rust? There are nice C APIs that would use a nice struct that describes the timeout you want… eg GCD.
Re:Sshole by eru on Friday November 06, 2026 @04:34AM (#50390187)
I'm not sure a struct is the right thing here in general. You often want an algebraic datatype.

What Rust calls an enum, but an enum with payloads. In C terms it would be a discriminated union.

Re:Sshole by cowlevel on Friday November 06, 2026 @12:10AM (#50388467)
In general it's a problem of sentinel values. Some languages let you abstract this - I think in Rust and C++ you can define an "intrusive optional" which is like optional but uses an invalid value pattern to store the not-present state. In memory it's the same as a sentinel value but the compiler forces you to unwrap it like an optional.
Re:Sshole by eru on Friday November 06, 2026 @04:33AM (#50390180)
I'm not sure how well the 'forcing' works for Rust and C++. You can definitely do this kind of thing in dependently typed languages.
Re:Sshole by cowlevel on Friday November 06, 2026 @08:05AM (#50391862)
The type is akin to optional<int>. You can't add 5 to it, you have to dereference it first which crashes if it was null (0 or another chosen value).
Re:Sshole by eru on Friday November 06, 2026 @09:36PM (#50401092)
Well, in Rust you would use pattern matching, which can't even crash.

In Haskell, the closest thing to adding 5 to an optional value would be something like:

    fmap (5+) my_optional_value
This one leaves 'Nothing' alone, but adds 5 in case the value is present.
Re:Sshole by Joker_vD on Friday November 06, 2026 @05:05AM (#50390419)
Amusingly, Win API of all places generally evades this pattern: 0 timeout means "no waiting", and to wait indefinitely, you use timeout of INFINITE which is actually UINT_MAX or, equivalently, -1 (in Win API, timeouts are unsigned, not time_t).
Re:Sshole by sgerenser on Thursday November 05, 2026 @04:33PM (#50384753)
But, but 'always "succeeding" but giving an unmatchable hash is reportedly a better behavior than failing on error.'!!
Re:Sshole by l33tman on Thursday November 05, 2026 @05:03PM (#50385118)
Is really the solution to a bug where a function had a wrapper that tried to solve its documented issue of returning *, to make yet another wrapper to try to solve the documented issue of returning true?
Re:Sshole by selfmodruntime on Friday November 06, 2026 @12:52PM (#50395757)
The conclusion is, again!, that C is an outdated tool for secrure software.
Re:Sshole by kazinator on Friday November 06, 2026 @06:04PM (#50399696)
[delayed]
Re:Sshole by mpyne on Saturday November 07, 2026 @11:11AM (#50405707)
musl does implement it this way.

However OpenSSH passes a different hash to musl’s crypt() than what it later uses to compare, so musl doesn’t switch to the alternate return output because from its perspective, it’s already guaranteed not to accidentally compare the same as the input hash.

Re:Sshole by byronsharman on Thursday November 05, 2026 @10:49AM (#50380616)
Thank you for explaining it with proper capitalization. I understood your explanation much better than the author's.
Re:Sshole by dboreham on Thursday November 05, 2026 @10:53AM (#50380688)
> musl can return “*” for errors

wtaf ?

Re:Sshole by za_creature on Thursday November 05, 2026 @11:38AM (#50381252)
There is no doubt in my mind that this was intentional.
Re:Sshole by zbentley on Thursday November 05, 2026 @12:32PM (#50381868)
Well, it was intentional, but not in the way I think you mean.

musl switched to returning `*` so folks stopped accidentally using NULL results, which was causing crashes and risked false-positives comparing NULL to itself.

That was a misfeature and should never have been implemented. But I bet it was an easy band-aid change to make!

Re:Sshole by za_creature on Thursday November 05, 2026 @01:03PM (#50382208)
As opposed to the false positives returned by comparing '*' to itself.

Why * specifically? Why not some random guid generated before committing, if it's so important to not let buggy software crash?

Re:Sshole by zbentley on Thursday November 05, 2026 @01:07PM (#50382263)
I'm agreeing with you, to be clear.

But buggy software might not crash; it might compare NULL == NULL and misbehave, instead.

So there's really no good option here, which is why C is a rancid choice of language for publicly-usable APIs. But we're stuck with it. So it goes.

Re:Sshole by dboreham on Thursday November 05, 2026 @01:24PM (#50382517)
I've been programming in C since 1978 and never until now heard of a function returning "*" on error.
Re:Sshole by zbentley on Thursday November 05, 2026 @01:31PM (#50382624)
This specific manifestation of "C is terrible for shared code APIs" is rare.

But issues caused by folks forgetting to check errno, miscomparing NULL to NULL when calling multiple APIs, dereferencing external-API-returned NULL due to missed error checking, mishandling inherited errno after successful action, or--the most common--mishandling negative integer return sentinels meant to indicate errors? Those are incredibly common.

Re:Sshole by za_creature on Thursday November 05, 2026 @02:19PM (#50383205)
This specific library call is quite poorly designed.

Standard C api calls return an integer, which is 0 on success or nonzero on error. Ignoring it is an intentional choice. `errno` is the hack that shouldn't really exist because it's trivially easy to forget to check that and also has issues with threading (patched by making it a thread local) and more recently, coroutines (which admit no general purpose patch because they're a userspace construct).

Another reason why this is terrible is that it's unclear what the returned pointer's lifetime is. Is it until the next call to crypt? If so, is it thread-local like errno? If it's passed on to the user, is it safe to call free() on it, or is there a crypt_free function that should be called instead?

But all of this, and I mean all of it pales in comparison to returning '*' on error.

Re:Sshole by zbentley on Thursday November 05, 2026 @03:00PM (#50383708)
> But all of this, and I mean all of it pales in comparison to returning '*' on error.

100% agree. This is an egregious failure. But C's error-handling story would be bad even without this, and the badness of C's error handling is what motivated the (bad) decision to return *.

It'd be great if we wrote systems software in a language that supported advanced features like...

checks notes

...returning multiple values.

Hell, even in VBA you had to at least spend the keystrokes to type "on error resume next".

Re:Sshole by gpvos on Thursday November 05, 2026 @05:39PM (#50385517)
It's just that every other string than "*" would have been a better choice, including even the empty string (which would have been the next terrible choice).
Re:Sshole by tredre3 on Thursday November 05, 2026 @02:12PM (#50383115)
It's not a C thing, it's a Linux thing. The asterisk is relevant to how crypt() is used for /etc/shadow.

           If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not
           be able to use a unix password to log in (but the user may log in the system by other means).
Re:Sshole by zbentley on Thursday November 05, 2026 @03:05PM (#50383757)
No, it's a C thing. They previously returned NULL for invalid passwd lookups, but because there's no way in C to force API users to decide what to do if an error occurred, that was causing program crashes due to NULL dereferences.

So they made the (very bad, but motivated by C's broken design/conventions) decision to return a magic string instead.

Re:Sshole by za_creature on Thursday November 05, 2026 @03:23PM (#50383989)
Oh, it was magic alright.
Re:Sshole by patmorgan23 on Thursday November 05, 2026 @03:56PM (#50384361)
This sounds like a program problem not a library problem. Why did the library try to solve it?
Re:Sshole by nuxi on Thursday November 05, 2026 @04:29PM (#50384706)
Now imagine every other C API that can potentially return NULL did the same thing. Is that in any way sensible?

You can argue that C has broken design/conventions, but the musl decision was really really awkward.

Re:Sshole by ruslan on Thursday November 05, 2026 @05:11PM (#50385203)
> but because there's no way in C to force API users to decide what to do if an error occurrs,

0. There are tons of libc functions that return NULL on failure, it is conventional way in C to indicate failure.

1. There's no much to decide, just fail to login if crypt() fails with NULL.

2. errno is standard way in C to check error code of a failing function, but in case of login you hardly need this, just fail!

I totally agree that fixing this issue in musl was a pretty dubious solution. Don't fix what's not broken, fix broken application instead. Publish a CVE if you cannot fix it.

I looked through FreeBSD source code for how they use crypt(), it's checked for NULL everywhere!

Re:Sshole by __david__ on Friday November 06, 2026 @04:15AM (#50390011)
Nothing you said is incorrect, but I believe they meant that there’s no way to force a C program to check the NULL correctly—the compiler will happily compile code that gets a pointer back from a function but doesn’t check for NULL before dereferencing it. In something like Rust the type system won’t let you touch the value until you’ve done something to deal with the error. Even if you just want to ignore it, you are forced to acknowledge that the function is fallible by the type system—it’s a compile error if you don’t.
Re:Sshole by gpvos on Thursday November 05, 2026 @05:44PM (#50385577)
Returning NULL on error is actually an excellent choice because most programs will crash if they try to use it without checking. Of course, modern programming languages have better constructs, but this was rare to nonexistent when C was started and if you think C is going away anytime soon you're delirious. musl's decision to change that to "*" is ununderstandable.
Re:Sshole by zbentley on Thursday November 05, 2026 @07:59PM (#50386831)
> musl's decision to change the return value to "*" is ununderstandable and likely intentionally evil.

Dude, they documented their rationale. It was dumb and wrong but totally relatable. Irresponsible users were getting crashes, and I’m sorry to tell you that for a lot of library maintainers

> Returning NULL on error is actually an excellent choice because most programs will crash if they try to use it without checking.

…is not something they want to write in responses to bug reports, even though it is quite true. It’s human nature to want to prevent your stuff causing problems for others, even if the problems are fully their fault. Most people cannot and will not be Steve “so don’t hold it like that” Jobs, for fear that their decision will be just as short-sighted as his was.

In this case, that was obviously the dead wrong call. But I’ve been in that seat, and “closed: user error” for the 100th time feels bad to write. Add to that a touch of misplaced cleverness, and you get “hey…what if we just returned an impossible string instead of an error?”

Evil requires motive or malice, and I’m having trouble coming up with those in this case. These patches weren’t concealed or miscategorized a la xz, the behavior was discussed in the open. They were just, in hindsight, really poor decisions made for ordinary reasons. Hanlon’s Razor and all that.

Re:Sshole by za_creature on Friday November 06, 2026 @04:41AM (#50390250)
> “closed: user error” for the 100th time feels bad to write.

That's the job of a OSS library author.

Re:Sshole by __david__ on Friday November 06, 2026 @04:52AM (#50390331)
> That’s why I’ve been harping on C being trash for shared-code API…

Agreed, but I can’t think of any other widespread ABIs that are better. Rust’s is not stable both C++ and Rust have concepts that don’t map into other languages well, so using them wholesale is a no go. So it would probably need to be a subset of those. Honestly just tagged unions would probably be enough. Maybe the solution is to get native tagged unions into C…

Re:Sshole by gpvos on Saturday November 07, 2026 @03:13AM (#50402661)
Fine, I can follow your reasoning.

There is the concept of "defense in depth": having each layer of code and configuration be sane and secure. Even if you program in Rust, you should be vigilant in that sense. This kind of code amounts to removing one or two layers.

Re:Sshole by cowlevel on Thursday November 05, 2026 @10:04PM (#50387643)
C programs wouldn't accidentally compare NULL to NULL. They'd either check for null explicitly, or they'd pass the null to strcmp and crash.
Re:Sshole by bch on Thursday November 05, 2026 @01:06PM (#50382251)
> musl switched to returning `*` so folks stopped accidentally using NULL results, which was causing crashes and risked false-positives comparing NULL to itself.

Of all the things to mitigate...

1) crashing should be an option - it noisily indicates "there's a problem" and if it faults and dumps core, you've got a guided tour of your problem.

2) Is testing NULL as a passable option likely? I'd guess a more likely idiom is:

  if(NULL==(str=somefunc(arg1, arg2))){
    return err;
  }
Re:Sshole by PokestarFan on Thursday November 05, 2026 @01:17PM (#50382395)
I think the issue is that a lot of callers were not aware that crypt() could error at all and all the issues are downstream of that. If OpenSSH knew that crypt() could error they would have handled it (possibly by inspecting errno).
Re:Sshole by creata on Thursday November 05, 2026 @01:26PM (#50382560)
I don't think that's the problem. The man page for crypt clearly says that erroring is a possibility and that it's not standardized how it errors:

> The behavior of crypt on errors isn't well standardized. Some implementations simply can't fail (except by crashing the program), others return a null pointer or a fixed string. Most implementations don't set errno, but some do. POSIX specifies returning a null pointer and setting errno, but it defines only one possible error, ENOSYS, in the case where crypt is not supported at all.

In my opinion the problem is that the behavior of crypt is underspecified - it isn't even specified how it signals failure, which is shocking.

You can't check errno to see if there was a failure because, as the man page says, the value of errno is unspecified when crypt succeeds.

Re:Sshole by throwaway2037 on Friday November 06, 2026 @12:51AM (#50388678)

    > You can't check errno to see if there was a failure because, as the man page says, the value of errno is unspecified when crypt succeeds.
You can set errno to zero before the call. If the value is non-zero after the call, that is a good heuristic for failure.
Re:Sshole by zbentley on Friday November 06, 2026 @02:44AM (#50389350)
...unless crypt() is one of the many, many functions which themselves internally call functions that set errno. In which case you can't be sure.
Re:Sshole by xp84 on Thursday November 05, 2026 @06:58PM (#50386324)
> crashing should be an option

Wise words. I think early in my career I tended towards coding as defensively as possible in a very specific way of "don't crash", as I definitely was not working in codebases I felt I had a full picture of. "I don't know who calls this method, and I don't want to get a call in the middle of the night that I broke prod" so I would say, return an empty string when asked to format a datetime except I'm passed a string or an int. (Yes, I was working in dynamic, untyped languages, too).

Later on, even in untyped languages, I came around more to "Throw loud and specific exceptions when asked to do things that are nonsensical" - it requires more overall cojones though because it may cause "your code" to crash. But the realization I came to was that it's better to crash (a MaliciouslyLongPasswordError was uncaught) because "AuthManager asked PasswordService to check a password that was 2MB long" than to paper that over until something like this comes out. Or, the more common situation, you're passed garbage, you return something that won't choke the caller at the time, but what it saves to the database in that scenario ends up being corrupt data. 6 months later someone notices, and has to sort out a data mess that may or may not be recoverable.

Re:Sshole by zbentley on Thursday November 05, 2026 @07:50PM (#50386752)
“A good offense (SIGABRT) is the best defense(ive code).”

I dig it.

Re:Sshole by oasisaimlessly on Friday November 06, 2026 @06:16AM (#50390946)
FYI, your learned approach is also known as "fail fast" methodology[1][2].

[1]: https://www.martinfowler.com/ieeeSoftware/failFast.pdf

[2]: https://en.wikipedia.org/wiki/Fail-fast_system

Re:Sshole by ghostly_s on Thursday November 05, 2026 @03:48PM (#50384289)
But choosing "*" as the character to return is an insane choice for anyone who knows the basics of linux sysadmin, or hell anyone who's ever used a search field in any context and thus knows it is ubiquitously used as a wildcard operator.
Re:Sshole by cloudfudge on Thursday November 05, 2026 @05:39PM (#50385520)
It's almost sensible if you only think of one side. It's like if /etc/passwd put "NO_PASSWORD" in the field for disabled logins and someone was like, oh, I'll be clever and say crypt() returns "NO_PASSWORD" on error because that's obviously invalid and won't match. But that's exactly what *does* make it match.
Re:Sshole by bryan_w on Thursday November 05, 2026 @11:39PM (#50388286)
But this also needs the "ddos" patch that was submitted later as well.

That seems orchestrated.

Re:Sshole by bryan_w on Thursday November 05, 2026 @11:43PM (#50388314)
Re:Sshole by pdw on Thursday November 05, 2026 @07:11PM (#50386439)
But it fits the common Linux implementation of the function... e.g. the Debian manpage says:

> Upon error, crypt_r, crypt_rn, and crypt_ra write an invalid hash to the _output_ field of their _data_ argument, and crypt writes an invalid hash to its static storage area. This string will be shorter than 13 characters, will begin with a ‘*’, and will not compare equal to _setting_.

Re:Sshole by crunchatized on Saturday November 07, 2026 @04:56PM (#50408412)
That's in Debian 11 and later. That man page said something entirely different in Debian 10 and earlier, when they shipped glibc's libcrypt. Now they ship libxcrypt instead.

Fedora asked libxcrypt to give them back glibc's behavior, returning NULL, and they obliged by adding ./configure --disable-failure-tokens. But it's an option that Debian never enabled.

https://github.com/besser82/libxcrypt/issues/25

https://salsa.debian.org/md/libxcrypt/-/blob/master/debian/r...

Re:Sshole by dboreham on Thursday November 05, 2026 @01:22PM (#50382486)
Of all the possible strings this seems like the absolute worst choice. If I were typing that string I'd pause to think "wait, what if the caller uses this with a regex?"
Re:Sshole by mmoll on Thursday November 05, 2026 @01:56PM (#50382916)
I agree. The “excuse” for implementing those behaviors is just providing plausible deniability. The commit that lets crypt return “*”, followed closely by a change that lets you easily trigger that behavior sounds just like how somebody would sneakily introduce a back-door into tons of linux systems while making it look as innocent as possible.
Re:Sshole by nextaccountic on Friday November 06, 2026 @07:45AM (#50391693)
Yep. See: underhanded c code contest

https://www.underhanded-c.org/

Re:Sshole by odo1242 on Thursday November 05, 2026 @12:34PM (#50381895)
Returning a string on error honestly is defensible, the question is why the string was “*” instead of like “crypt ERROR: input password cannot be longer than 256 characters” lol
Re:Sshole by dboreham on Thursday November 05, 2026 @01:21PM (#50382464)
Precisely.
Re:Sshole by mmoll on Thursday November 05, 2026 @01:49PM (#50382834)
No. Musl claims (claimed?) to be strictly POSIX compliant, and POSIX requires crypt to return NULL on errors.
Re:Sshole by tredre3 on Thursday November 05, 2026 @02:06PM (#50383029)
"*" is what's been historically used to represent an invalid/no value in passwd/shadow, so it makes some sense.

Of course given the chance that one might do a direct string comparison between crypt's return and the passwd/shadow file's hash field it was still a not well thought out choice.

Re:Sshole by gf000 on Thursday November 05, 2026 @02:21PM (#50383222)
No, it's absolutely not defensible.
Re:Sshole by JdeBP on Thursday November 05, 2026 @03:17PM (#50383920)
One has to remember the context here. The only error possible according to the SUS is ENOSYS, literally that crypt() is not actually implemented in the library. The traditional AT&T Unix crypt() was always implemented, and its encryption did not have failure modes, so there was never any error return to handle. This is why programs were written to never check the result of crypt(). It was only ever NULL on systems where one couldn't use the mechanism at all in the first place.

So the knock-on effect is that libraries that do have errors other than ENOSYS to accommodate, have to return magic 'impossible' values instead of setting errno and returning NULL, because of the weight of existing applications that expect nothing but the standard, traditional AT&T Unix (and indeed old BSD), behaviour.

Check the GNU libc crypt() doco. It defines a whole family of 'impossible' values that signal errors, by dint of listing a load of magic characters that should never be in the encrypted string. Including asterisk.

Also check FreeBSD's OpenPAM for a case in point. Even today, it does not check for a NULL return from crypt() and leaps straight to strcmp().

* https://cgit.freebsd.org/src/tree/lib/libpam/modules/pam_uni...

If you want to see real history here, check out the 1992 comment by Eric Andrew Young, that is still in the source for OpenBSD today (in des/des_fcrypt.c), on how SSLeay's crypt() had to be adjusted so that any single character password field, including "*", did not end up successfully matching itself.

* https://cvsweb.openbsd.org/annotate/src/lib/libcrypto/des/At...

Re:Sshole by za_creature on Thursday November 05, 2026 @04:15PM (#50384545)
The most charitable interpretation here is that musl authors are incompetent.

There is simply no universe in which a security-conscientious reviewer looks at the code, spots * being a valid return value, remembers that * is the default value in /etc/shadow for "no password login please" and then is all like:

This is fine, you check for * and return + instead.

There are more 32-long character sequences than atoms in the universe. Pick one, any of them instead.

Re:Sshole by ruslan on Thursday November 05, 2026 @05:22PM (#50385337)
> Also check FreeBSD's OpenPAM for a case in point. Even today, it does not check for a NULL return from crypt() and leaps straight to strcmp().

Damn, that's a bug! Please file bug report.

Re:Sshole by JdeBP on Thursday November 05, 2026 @07:34PM (#50386623)
I suggest finding a code path where FreeBSD crypt() ever returns NULL, which would mean one of its internal functions returning non-zero, before getting too excited. They all end in return (0) . (-:

* https://cgit.freebsd.org/src/tree/lib/libcrypt

As I said, the callers of crypt() have for a long time been using the knowledge that crypt() on their platform simply never returns NULL. Unix has never been returning NULL from crypt() as far back as 7th Edition, when it simply always returned a pointer to a single internal static buffer.

* https://github.com/dspinellis/unix-history-repo/blob/Researc...

The reality is that all C library people have to work with a corpus of Unix applications that do not check for crypt() returning NULL that goes back almost 50 years, and an error return mechanism that barely exists outwith the pages of the SUS.

That includes callers in single-user mode in process 1 in some configurations.

* https://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/init/init.c?an...

Re:Sshole by ruslan on Thursday November 05, 2026 @08:50PM (#50387145)
Well, crypt_blowfish() has a number of returns with (-1). I'm not familiar with Blowfish, so it's hard for me to trace the possibility of failure here. But what if in a distant future someone adds more hashing algorithms to the list without possessing historical knowledge of this "never return not 0" ?

* https://cgit.freebsd.org/src/tree/secure/lib/libcrypt/crypt-...

Re:Sshole by JdeBP on Friday November 06, 2026 @05:05AM (#50390415)
I have no doubt, despite that Marshall Kirk McKusick is still committing in 2026, that FreeBSD developers will come along that do not know history. But they will get pointed to the manual page that (amusingly) says that returning NULL is 'not a standard behaviour' and that AT&T Unix never did that.

* https://man.freebsd.org/cgi/man.cgi?query=crypt&sektion=3&fo...

NetBSD's manual is more detailed on the subject, and explains the bind that library implementors have been in for decades, thanks to almost 50 years of applications knowing what crypt() 'really' does.

* https://man.netbsd.org/crypt.3#RETURN%20VALUES

And this despite the SUS trying to shoehorn an error return mechanism into crypt(3) in order to accommodate the problems that operating systems had exporting encryption code, two decades afterwards. (The 1997 GoSolo book explains that this is why there's an ENOSYS error.)

Re:Sshole by boomlinde on Friday November 06, 2026 @01:32AM (#50388912)
> Check the GNU libc crypt() doco. It defines a whole family of 'impossible' values that signal errors, by dint of listing a load of magic characters that should never be in the encrypted string. Including asterisk.

No. https://man7.org/linux/man-pages/man3/crypt.3.html

My guess is that you are reading the libxcrypt crypt(3) manual: https://www.mankier.com/3/crypt

That's not GNU libc, but frequently deployed on Linux systems.

Re:Sshole by JdeBP on Friday November 06, 2026 @04:33AM (#50390178)
Well caught. I was reading what man -s 3 crypt brought up, which mentions GNU and -lcrypt and only right at the very bottom says something else.

* https://manpages.debian.org/trixie/libcrypt-dev/crypt.3.en.h...

Although that's a fine distinction for the point being made, as it's still the manual page for the crypt() function that one gets on the operating system, which that other manual page is not.

Re:Sshole by boomlinde on Friday November 06, 2026 @07:30AM (#50391575)
That naturally depends on the operating system and the crypt implementation they include.
Re:Sshole by JdeBP on Friday November 06, 2026 @02:16PM (#50396979)
Not really. For Linux-based operatings systems, the GNU libc manual cryptography section is a shadow of its former self. It has no crypt() function to accompany it any more, and has not had since 2023.

* https://sourceware.org/git/?p=glibc.git;a=commit;h=e6e3c6668...

Notice that Debian didn't list your manual page, which doesn't accompany a crypt() function at all, since it isn't actually the GNU libc manual but a separate independent manual for Linux. The GNU libc manual nowadays acknowledges Michael Glad's work but no longer documents crypt(). It used to, and it used to explain some of the 'impossible' encrypted string values:

* https://sourceware.org/glibc/manual/2.38/html_node/Passphras...

You noticed that I'd not got the GNU libc manual. Neither had you. (-:

Re:Sshole by paparazzi678 on Thursday November 05, 2026 @03:05PM (#50383765)
weird chain of events and could have been handled in a better way for sure
Re:Sshole by forrestthewoods on Thursday November 05, 2026 @03:19PM (#50383935)
Great explanation. This affirms my biases that shell scripting and everything-is-strings is a mistake. Horrific.
Re:Sshole by Woodi on Friday November 06, 2026 @12:43AM (#50388635)
Shell is for humans to read and act on it.

Not to programmatically parse 'ls' output or some /proc/some/file.

Eg. git started as Perl scripts then moved to C to realy have data straight from C calls from system.

So for example all Internet things calling "openssl -some -options ...." are pure trash :>>

Re:Sshole by JoBrad on Friday November 06, 2026 @09:08AM (#50392464)
Even good, well-founded intentions can end terribly. The mistake is doubling down on those decisions when the mistake has become obvious.

I am also in the camp that CLI tools should return objects that can be parsed (by the shell or otherwise).

Re:Sshole by 1vuio0pswjnm7 on Thursday November 05, 2026 @03:48PM (#50384286)
"The OpenSSL adjustment ensures a minimum hash length for the user before logging them in, even if crypt() succeeds somehow."

OpenSSL??

Re:Sshole by mpyne on Thursday November 05, 2026 @05:35PM (#50385478)
Sorry, should have written OpenSSH.
Re:Sshole by amluto on Thursday November 05, 2026 @05:47PM (#50385611)
Caveat:

> $ret = crypt($pw, $hash); $ret == $hash

musl is actually safe against this use. OpenSSL takes a bizarre code path, detects that $hash is too short, calls crypt($pw, $other_string), forgets that it detected that the hash was too short, and checks $hash == return value.

See my other comment.

Re:Sshole by mpyne on Thursday November 05, 2026 @08:54PM (#50387174)
I did note that musl would normally work just fine here. Though I appreciate that your other comment goes into much better detail about what was actually going on in the code, as my analysis basically stopped once I understood the high-level flow of what was going on.
Re:Sshole by __david__ on Friday November 06, 2026 @03:45AM (#50389756)
Except OpenSSH qould have worked just fine if musl behaved correctly. Instead musl ignored the spec and tried to hack around badly written programs but ended up creating a security hole in a correctly written one!
Re:Sshole by smnc on Friday November 06, 2026 @02:05AM (#50389109)
> The goal from an attacker’s perspective is to get this to be true: `$ret = crypt($pw, $hash); $ret == $hash` when called by OpenSSH’s sshd.

A typo: `$ret = crypt($pw, $salt)`

Re:Sshole by kazinator on Friday November 06, 2026 @05:37PM (#50399437)
[delayed]