Remix.run Logo
▲ amluto 5 hours ago

On a very very quick read, the bug is that EVP_EncodeBlock malfunctions if the input is larger than ~1.5GB. EVP_EncodeBlock is a function that encodes base64.

https://docs.openssl.org/1.0.2/man3/EVP_EncodeInit/

As a seasoned C programmer, I can immediately observe that the whole API is bad: the caller is expected to calculate the buffer length on their own, using a nontrivial formula, and the caller does not pass in the output buffer length, so the implementation cannot validate it. But apparently OpenSSL 4 also implemented it wrong and wrote (possibly far) past the end of the buffer.

You should probably assume that, if you are running anything that can be convinced to use this API to encode a very long blob as base64, then you are in trouble. I don’t know why a modern server would do this.

BTW, OpenSSL seems to be a rather low quality implementation of a very low quality set of APIs. Stay away.

edit: Fixed my size threshold, hopefully. I was thinking of unsigned ints, but this is a signed int. I have not looked at the code, just the description.

▲socketcluster an hour ago | parent | next [-]

> BTW, OpenSSL seems to be a rather low quality implementation of a very low quality set of APIs.

Fully agree with your assessment above that line, but damn, this is a strong statement for a library this ubiquitous. You wonder; how could this happen? And yet, as an open source developer myself, I know how little people care about code quality.

▲Gigachad an hour ago | parent [-]

We have known this since at least heartbleed. The answer was that basically no one funds the project and it had only one developer.

All these trillion dollar tech companies have been leaching off open source for free and never contributed back to the projects they rely on.

▲k_sze 13 minutes ago | parent | next [-]

Honest question: shall free software licenses be changed to force large corporations to sponsor free software projects adequately?

▲socketcluster 22 minutes ago | parent | prev [-]

It's insane. I maintain a small open source project with only about 100k downloads per week and so, in terms of funding, it's crickets for me but I assumed famous projects like OpenSSL would get some decent funding.

Then I read articles about billionaires donating millions or even billions to various (sometimes frivolous) charities and I wonder WTF.

The numbers just don't add up. It's like there is an invisible force field preventing people from donating money to open source?

Crazy to think that the people who once posted a dumb viral 30-second meme video on YouTube probably got more money than the author of a complex, world-famous open source project which has been at the top for decades and which quite literally intermediates every aspect of almost every human's life.

Does not compute.

▲vlovich123 4 hours ago | parent | prev | next [-]

> BTW, OpenSSL seems to be a rather low quality implementation of a very low quality set of APIs. Stay away.

We’ve known this for well over two decade since heartbleed yet for some reason Linux distros haven’t migrated off of it

▲dcrazy 4 hours ago | parent | next [-]

For those too young to remember 2014, Heartbleed led to both BoringSSL and LibreSSL being forked from OpenSSL.

▲stock_toaster 2 hours ago | parent | next [-]

And also led to Amazon's s2n-tls and libcrypto being released around 2015 too as I call.

EDIT: found the release announcement - June 2015 - https://aws.amazon.com/blogs/security/introducing-s2n-a-new-...

▲b112 an hour ago | parent | prev | next [-]

I wonder. Realistically, Boring and Libre haven't taking off. I measure that by most use and default deploys. But with LLMs, we may be entering a new world.

In that world, certainly some projects may be impervious to fixes. We've all seen projects that basically eschew all change, and ignore issue trackers, and are basically dead.

But the ones which still live? Eventually this first wave of LLM derived fixes will get through the old churn. Presumably, code will improve dramatically. If that's so, OpenSSL will become "good code". And the same with old legacy projects which are still hanging around.

Meaning... will legacy simply exist forever? Our two forks above will likely fade away, if openssl's code becomes clean as can be.

▲morkalork 3 hours ago | parent | prev [-]

TIL it's 2036

▲wahern 2 hours ago | parent [-]

To be fair, frustrations with OpenSSL long preceded Heartbleed. Heartbleed was just the final straw for those who forked libressl and BoringSSL.

And to be fair to OpenSSL, it was one of the first widely used crypto libraries, along with Netscape's NSS. Setting aside the reasonablebess of the initial choices, the rapid uptake meant those choices were difficult if not impossible to completely unwind, particularly the style and typing of parameters and error reporting. Even today debates rage about signed vs unsigned, etc, in C and other languages. (But suffice it to say there are still alot of unforced errors, IMO, such as implicit output buffer sizes.)

▲DANmode 2 hours ago | parent | prev | next [-]

Not breaking userspace is more important than security………

▲Skunkleton 34 minutes ago | parent | next [-]

"not breaking userspace" refers to kernel development. OpenSSL is userspace.

▲yjftsjthsd-h 25 minutes ago | parent | next [-]

Paraphrasing to "don't make breaking API/ABI changes for projects consuming your API/ABI" doesn't materially change a reasonable point. (And I generally agree with that point, although I confess openssl specifically really strains my view)

▲charcircuit 29 minutes ago | parent | prev [-]

And this is why the Linux Desktop will never go mainstream. You should never break apps at all, the OS's API surface goes beyond just the kernel.

▲vasco 32 minutes ago | parent | prev [-]

Yeah, we all know users would rather be reliably hacked than unreliably safe.

▲CrimsonCape an hour ago | parent | prev [-]

I just don't get it; this is a task to hand to an LLM, "go rebuild OpenSSL, use Rust (no mistakes)" and have it churn through a greenfield implementation. Then open a PR =). Why hasn't this happened yet? The fact that the LLM will write tests and deal with all the compiler errors probably puts it lightyears ahead.

▲brianpane an hour ago | parent | next [-]

There’s already a Rust TLS library, rustls, that’s relatively mature (10 years in development, a couple of paid maintainers, robust development and release processes). It’s not a drop-in replacement for OpenSSL, though. There’s a companion project to build an OpenSSL-compatible wrapper API for it, but that’s not as far along. Interestingly, while rustls has a plug-in API that lets you choose your favorite Rust encryption library for the low-level operations (aws-lc-rs, Ring, Graviola, etc), those libraries all tend to contain a lot of assembly … not just for speed, but because it’s easier to avoid side channel timing vulnerabilities in assembly.

▲dralley 5 minutes ago | parent [-]

The side channels issue is where rust crypto libraries are currently the weakest

▲b112 an hour ago | parent | prev | next [-]

LLMs have a bottleneck, human review. And human review is absolutely required at this stage (the future is unknown). A rust built LLM only reviewed SSL library would be a recipe for disaster.

Beyond that, when it comes to exceptionally complex APIs, forward thinking implementation, and revising the 'way things are done'? These are weak points for LLMs. If you don't know how to write OpenSSL(or its replacement), and don't understand all its quirks, and the entire industry surrounding it, you cannot be the human driving the LLM successfully.

There is no way for a human to catch all the design mistakes an LLM will make, otherwise.

People seem to get upset, when I say this, for reasons I cannot fathom. However, we need to have a mental model of how we trust LLM output, and the 'new junior' is great for that. Especially considering that every day, is a new day for an LLM, its context window always loses yesterday.

So consider LLMs as an eager, intelligent, incredibly well read junior, just out of college. And on their third day of work.

Zero real world experience. Constant review required.

Would you want that junior to design, build, and write test scripts for a library to underpin the entire internet?

▲fock an hour ago | parent | prev [-]

you don't get credit for that because it is clear you are not very skillful at what AI-bros value most, namely manipulating other nerds...

if you look at the commit history of OpenSSL, you can easily notice how a lot of people started contributing once their clanker got up to speed. They are very happy to rip out weird C and replace it with assembler or intrinsics. Rip out lists of characters formatted as a single string and replace them with array syntax, each char quoted.

▲teunispeters 4 hours ago | parent | prev | next [-]

I like to declare that industry coding standards such as MISRA exist precisely because code bases like OpenSSL (specifically) exist, as it's such a good example of breaking every sensible rule in the standards.

▲gspr an hour ago | parent | prev | next [-]

> BTW, OpenSSL seems to be a rather low quality implementation of a very low quality set of APIs. Stay away.

Well sure, but the world doesn't seem to be able to agree on, or put resources into, a strong contender.

I'm usually for heterogeneity and diversity in the software ecosystem, but for cryptography I'd be happy with a single high-quality "anointed path". Because cryptography.

▲octoberfranklin 3 hours ago | parent | prev | next [-]

This is really embarrassing because this isn't even ancient code.

OpenSSL has been around a long time and has a lot of legacy code, but this is in OpenSSL 4.x only -- stuff that was written in the last ~year.

If they don't have the manpower to write new code safely they should just stick to maintaining what they've already written.

▲fock an hour ago | parent [-]

and now guess who helped writing this code. the chicken are coming home to roost, but people who are happy about their youthful productivity or stock packages will not be able to notice...

the code before this PR included the check. But that was old code!

▲kvuj 4 hours ago | parent | prev | next [-]

> EVP_EncodeBlock() encodes a full block of input data in f and of length dlen and stores it in t. For every 3 bytes of input provided 4 bytes of output data will be produced. If dlen is not divisible by 3 then the block is encoded as a final block of data and the output is padded such that it is always divisible by 4. Additionally a NUL terminator character will be added. For example if 16 bytes of input data is provided then 24 bytes of encoded data is created plus 1 byte for a NUL terminator (i.e. 25 bytes in total). The length of the data generated without the NUL terminator is returned from the function.

My god, you only see this type of horrendous API in C don't you.

▲cesarb 2 hours ago | parent | next [-]

> My god, you only see this type of horrendous API in C don't you.

This is the appropriate place to put a link to this pair of classics on API design:

"How Do I Make This Hard to Misuse?" https://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html

"What If I Don't Actually Like My Users?" https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html

▲td521534f12 4 hours ago | parent | prev | next [-]

"No way to prevent this" say users of only language where this regularly happens

https://xeiaso.net/blog/series/no-way-to-prevent-this/

▲userbinator 4 hours ago | parent | prev [-]

What's "horrendous"? I don't see anything which stands out as being wrong. It specifies exactly the lengths of input and output.

gets(), on the other hand, that is "horrendous".

▲IanCal 16 minutes ago | parent | next [-]

The thing that jumps out to me is that it returns “the size of the output data minus one” but if I’m passing in a pointer it’s on me to make sure there’s enough memory allocated isn’t it? So the caller must make sure it’s calculated this correctly - in which case why return the size? Taking the size as an argument could be safer as you’d be checking the caller calculated enough space too.

(Honest questions in this it’s probably been 20 years since I did c)

▲amluto 4 hours ago | parent | prev | next [-]

Even in C, if you have a function that takes an input buffer and output buffer of differing lengths, the right API has the caller pass both lengths.

But yes, gets is worse.

▲userbinator 3 hours ago | parent [-]

takes an input buffer and output buffer of differing lengths, the right API has the caller pass both lengths.

If there is no fixed relationship between the two, then that makes sense; but in this case there is a very simple and well-defined relationship between them. But to specify two lengths which must always agree; and if not, then what? You've effectively invented an additional artificial error condition, an additional branch, and burdened all the callers up the chain to do something, which is a treacherous path to complexity and the production of even more bugs.

Or are you just preaching the same mindless idiocy that lead to Microsoft's memcpy_s() (the "s" is for "stupid")?

▲kvuj 4 hours ago | parent | prev [-]

Perhaps I'm just used to having programmed in C# professionally for a little bit, but these sorts of APIs where you have to do a calculation to determine the destination buffer size make me feel like a caveman. A minuscule typo and you get a CVE like this.

I know, I know, C is low level and high performance, but surely in the year of our lord 2026, we could have come out with something simpler.

Horrendous is a strong word, you're right.

▲pjmlp 17 minutes ago | parent | next [-]

Not even that is usable as excuse, only those that never tried out the systems programming languages that either predated C, or where equally developed during the 1970's outside Bell Labs and UNIX ecosystem.

You could have come with something simpler in PL/I.

▲uecker 2 hours ago | parent | prev | next [-]

One can abstract buffer handling away in C just fine, eliminating all those problems. I don't know why programmers insist on open-coding low-level buffer management.

▲eptcyka an hour ago | parent [-]

Yes, of course, this isn’t C, this is just another case of people writing C wrong.

▲JSR_FDED 2 hours ago | parent | prev [-]

You should be comparing with assembly language, not C#.

▲landr0id 4 hours ago | parent | prev | next [-]

>As a seasoned C programmer, I can immediately observe that the whole API is bad: the caller is expected to calculate the buffer length in their own, using a nontrivial formula, and the caller does not pass in the output buffer length, so the implementation cannot validate it. But apparently OpenSSL 4 also implemented it wrong and wrote (possibly far) past the end of the buffer.

Many such cases.

I expect we'll see some fun libyuv bugs soon in applications which decode media. The APIs are begging for misuse.

https://chromium.googlesource.com/libyuv/libyuv/+/refs/heads...

▲baq 31 minutes ago | parent | prev | next [-]

One of the ‘rewrite it in rust’ projects that should really cause anyone to be offended IMHO.

▲Gibbon1 36 minutes ago | parent | prev | next [-]

What's obnoxious is the WG14 standard committee could have at any time in the last 40 years provided a standard slice and buffer type that would go a long way to discourage trash API's like this one.

I swear it's de rigueur in C that if an operation requires 5 parameters to insure the operation is error free than the function shall only take 4 parameters.

Rewriting the function with idiot mode disabled

int EVP_EncodeUpdate(EVP_ENCODE_CTX ctx, buffer_t out, const slice_t in);

▲adev_ 13 minutes ago | parent [-]

> What's obnoxious is the WG14 standard committee could have at any time in the last 40 years

Or just use bloody C++ that solved that years ago with std::span.

Unfortunately, many C dev prefers whining about "How horribly bloated" C++ is instead of using the part that makes sense.

▲Gibbon1 a minute ago | parent [-]

There are very few reasons to start a greenfield project in C++ at this point.

▲userbinator 4 hours ago | parent | prev [-]

if the input is larger than ~1.5GB.

...on a system where ints are 32 bits. The bottom line is that this doesn't appear to be easily exploitable and IMHO it should be the callers of EVP_EncodeBlock which need to be inspected to determine the actual risk.

using a nontrivial formula

It's base64. 4/3 expansion; round it up and add padding. What's "nontrivial" about that?

and the caller does not pass in the output buffer length, so the implementation cannot validate it

Not necessary, because the caller is responsible for allocation.

▲sweetjuly 2 hours ago | parent | next [-]

I am confused why you make out 32 bit int as being rare. Almost all devices that you'd reasonably connect to the internet at this point have int as 32 bits

▲mrheosuper 4 hours ago | parent | prev | next [-]

The question can be reduce to "who do the length validation".

In my case, if i write a public-facing API, i never trust the caller will do the correct thing, thus the caller must provide all the critical parameters, and i must validate all of them.

▲userbinator 3 hours ago | parent [-]

The question can be reduce to "who do the length validation".

At the boundary where untrusted input becomes trusted. This is commonly known as the sanitisation/validation layer.

▲amluto 3 hours ago | parent | prev [-]

> It's base64. 4/3 expansion; round it up and add padding. What's "nontrivial" about that?

If you mean ceil(inlen * 4/3) + 1 (even if you use exact arithmetic), then you are passing too small a buffer and you will overflow. Maybe your “add padding” part fixes it? In any case, I think that the fact that this confusion is even possible proves my point.

You should not need to read the manpage of a function you are calling in order to determine whether you have passed a large enough buffer to avoid overflow.

Reading the manpage to get the function to not return an error would be a different story.

▲userbinator 3 hours ago | parent [-]

If you mean ceil(inlen * 4/3) + 1 (even if you use exact arithmetic), then you are passing too small a buffer and you will overflow.

If you let untrusted input reach inlen and overflow that computation, you have already failed:

https://news.ycombinator.com/item?id=50570319

▲amluto 36 minutes ago | parent [-]

Are you saying that any code that base64’s a string of attacker-controlled length is a mistake?

▲Pinus 21 minutes ago | parent [-]

I think userbinator thought that you meant that the calculation would overflow, while I think you meant that the calculation, even if not overflowing, would return the wrong value under some conditions and that subsequent code would then overflow the buffer. (As for what I think about the actual issue, I’m too sleepy to even try. Which is probably an indication of something. =) )