376 points · by JacobHenner · 1w ago · 348 comments
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.
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.
All these trillion dollar tech companies have been leaching off open source for free and never contributed back to the projects they rely on.
And when Redis changed their license for such reasons, companies and people united to create ValKey or even the Centos/Rocky linux situation.
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.
All yours! Use it to your heart's content.
The API is a fractal of bad design. Not just that, but because of the API refusing to make sensible choices, it forces everyone using it to be an expert in cryptography, with predictable results for those programs that use it.
It all came from a bad place. OpenSSL grew from primitives created by cryptographers. Cryptographers are great, and they make fabulous things. But almost none of the understand software development or care a great deal about the mundane matters of API design, or the obnoxious limitations of naively designed processing elements.
Others have cited the documentation for EVP_EncodeBlock(). In the mind of a cryptographer, the text is perfectly clear and trivial, and they likely haven't exposed themselves for many years to anyone that can't read that exactly once and not immediately and correctly visualize the necessary formulae. Nothing wrong here at all. The fact that on real computers, numbers don't just scale to whatever value a computation requires is merely a defect in the design of the machine.
There is a reason why people did not do a lot of TLS (outside of anything involving monetary transactions) before Firesheep, the NSA leaks were the final nail in the coffin for unencrypted HTTP. On top of that Let's Encrypt and ACME did not exist, so TLS was behind a paywall on top of that.
And then everything proliferated relatively quick even for tech standards. I guess people grabbed onto the next available tooling just like a drowning person would take any piece of driftwood.
Not so fun fact: AFAIK the openssl binary was initially explicitly meant to be only used for testing. That is why its command line is so strange. It was initially meant to expose a couple of low-level primitives, not to implement workflows. One example would be the openssl-ca man page, which explicitly mentions this. People didn't care because unfortunately you could somehow do everything you could ever want with the openssl binary and I guess that is also something how the impression stuck that openssl is the most advanced library.
I'm in shock ! Someone noticed ! Thanks man ! :)
In the meantime in real world IT :>>
line 57: https://github.com/acmesh-official/acme.sh/blob/master/acme....
line 306: "This script requires openssl binary" https://github.com/dehydrated-io/dehydrated/blob/master/dehy...
Pretty recommended scripts :)
And I'm sure there are more and not only for ACME, for example I'm sure I saw few examples in production setup docs from IBM and Redhat... :>
Yes, openssl library is wholesale backdoor, subtype: footgun.
Among the deeply technical and highly credible and detailed articles I've read in my life, it's definitely the spiciest. At the end:
> It is often said that fixing a problem requires smarter minds than those who created that problem. When the problem was architected by a team with strong convictions about the solution‘s correctness, it seems extremely unlikely that the resolution will come from the team that created that problem in the first place. The lack of progress in the latest releases tends to confirm these unfortunate hypotheses. The only path forward seems to be for the team to revert some of the major changes that plague the 3.x versions, but discussions suggest that this is out of the equation for them.
IOW this extremely strong claim does seem to be supported by extremely credible actors.
> And yet, as an open source developer myself, I know how little people care about code quality.
This is a weird statement. I am someone who has worked on closed-source internal enterprise software for my entire career. Universally, the internal source is worse that the numerous open source libraries that we use. If anything, open source has "more eyeballs" than closed source, so the code quality will be better.We’ve known this for well over two decade since heartbleed yet for some reason Linux distros haven’t migrated off of it
EDIT: found the release announcement - June 2015 - https://aws.amazon.com/blogs/security/introducing-s2n-a-new-...
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.
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?
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.
Yep, this is not news. https://en.wikipedia.org/wiki/LibreSSL was forked off OpenSSL now more than ten years ago to address exactly these kind of issues, and more (at the price of occasionally taking some drastic measures)
But somehow we're still here.
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.
the code before this PR included the check. But that was old code!
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.
"Although BoringSSL is an open source project, it is not intended for general use, as OpenSSL is. We don't recommend that third parties depend upon it. Doing so is likely to be frustrating because there are no guarantees of API or ABI stability." (Their README).
> LibreSSL
That does indeed still seem like the most promising avenue. But it is "just" a fork of OpenSSL.
> rustls
It relies on one of two crates for cryptographic primitives, both of which have zero regard for long term support. "Latest release or bust" doesn't cut it for crypto.
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
gets(), on the other hand, that is "horrendous".
But yes, gets is worse.
(Honest questions in this it’s probably been 20 years since I did c)
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.
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...
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);
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.
Well, it depends. if in the coming weeks many more Heartbleed-level vulnerabilities would be exposed, {Amazon, Google, OpenAI, Anthropic} can just rewrite it in Rust, formally verified.
There does not exist such implementation as of now as OpenSSL was good enough, AI may expose so many security flaws it would no longer be good enough.
A fair amount of such implementation do exist.
I see this is your first time reading OpenSSL code
...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.
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.
If you let untrusted input reach inlen and overflow that computation, you have already failed:
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.
At the boundary where untrusted input becomes trusted. This is commonly known as the sanitisation/validation layer.
For those wondering about TLS: speaking as someone who has written a TLS implementation, AFAIK neither base64 encoding nor decoding occurs in the protocol itself, and the longest length field is 24 bits (Hello stream). Certificate processing involves ASN.1 which does support arbitrarily-long integers, but that's a big hint to check that they're within a sensical range.
I'm starting to get annoyed about the OMG OMG BREAKING BREAKING ALARM-EMOJI crap that's not a real emergency.
Four times in the last month, I dropped everything and started investigating whether a serious CVE related to any of our dependencies warranted an emergency bump, only to be frustrated that images, even from AWS, did not have the fix yet. So then I had to worry about whether I should build from source. We actually built PHP from source and deployed it to prod, just to get ahead of the PHP2Shell vulnerability
But yesterday's PHP vulnerability, CVE-2026-115560, didn't even apply to us or most people running PHP, and I don't think there are any realistic working exploits out there. I'm not saying that it's not possible, but I'm starting to feel that there's a large difference between what's theoretically possible and what's practically possible. And given the storm of patches and vulnerabilities found, this will become increasingly important to ask.
I think everything above a CVE score of 9.0 should warrant some level of “how exploitable is this in real life,” and anything above 9.5 should be proven to be easy for an attacker to execute, not just “possible in theory.” I don't see how we will survive as developers if there isn't some sort of better triage for vulnerability severity assessment. If everything is an emergency, then nothing is an emergency.
So you can take e.g. a 9.3 critical down to 6.5 medium by setting CIA requirements to low and exploit maturity to Unreported.
I’m not saying CVSS is perfect but if you want to have a score that applies to your environment, you have to input some info about your environment into it.
“how exploitable is this in real life” is answered by the exploitability score, which is calculated from Attack Vector, Attack Complexity, Attack Requirements, Privileges Required, and User Interaction scores.
Heartbleed, Spectre, log4shell, they were all worthy of a 9.8.
This isn’t.
The score is just fine. The people misinterpreting everything with a CVSS score higher than 8 as the end of the world are panicking over nothing.
But risk or severity is not what CVSS measures. It's a score intended for security professionals who know the context, graded against a fixed algorithm, with a fixed definition for each answer. The nvd.nist.gov site isn't always the easiest to use, so grab a good CVSS calculator[1] and look at what it means. That's why the alphabet soup vector string is there: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
I'm sorry, CVSS wasn't meant to eliminate your need to think or understand your environment. Yes, if it's a 9.8 CVSS you should look at it. Triggering you to look at it is all the CVSS is meant to do!
Now, whether you think CVSS scores mark too many things as High or Critical is a little secondary. There is a reason we're at CVSS v4. Defining metrics and keeping them useful while remaining objective is difficult. This vulnerability, however, is exactly the kind a chain exploit would take advantage of.
[0]: https://www.cve.org/CVERecord?id=CVE-2026-121481 [1]: https://www.metaeffekt.com/security/cvss/calculator/
Risk is not what the CVSS score measures, correct. However the CVSS base score is first and foremost a measure of severity (of the vulnerability). I think they were being loose with their terminology when they wrote "severity is low" and probably meant to say "risk".
The spec talks about this in depth. Paraphrasing: The base score captures intrinsic characteristics of the vulnerability assuming a (reasonable) worst-case configuration.
It's a measure of "How screwed am I if I'm using this software in this specific-but-reasonable manner?", it's not a measure of "How screwed is everyone using this software?".
P.S. I broadly agree, just adding a minor correction on the terminology.
They are indeed, but that means CVSS has turned into a trigger for The Boy Who Cried Wolf. So we need a different metric. The problem, of course, is that adding a new score creates an xkcd 927 issue.
If you want a quick overview of the risk: CVE-2026-121481 is listed as CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H which is what calculates the CVE score. This is missing the temporal/environmental components (which rarely ever seems to get entered).
(Although I agree it should be an internal function.)
Someone should design something better, and less malleable.
Something that was super complex a few years ago might be super simple today. And I'm not talking about LLMs, I'm talking about stuff like if some CVE was dependent on you breaking e.g. MD5 in 1998, then it'd be "high", but in 2026 it's most certainly not that. And it doesn't need to take 28 years for something like that to change. It can theoretically happen over night or as the result of some other vulnerability. It even goes the other way too e.g. when ASLR was introduced.
Then again, given that I once had to respond to a report which assigned a similar amount of severity to the strlen() function claiming that it will read beyond its bounds if its input is missing a null terminator (DUH!), I'm not surprised at the lack of critical thought among a certain population in this industry.
They will statically determine (e.g. by SSHing in and rummaging around) that a library with a known vulnerability exists on the filesystem, but determining the reachability of that bug in the system as a whole (can this be exploited by the entire internet, or 3 sysadmins, or no one at all?) is not really an automatable task.
You have fuzzing, test coverage checks, overflow checks, static analysis, llm review. There is no conceivable reason why you might have a problem with using an u16 for a buffer length.
Even reading the PR comments shows that these libraries are just really low quality.
They are discussing if they should check the error return on callsites now that they made a function fallible.
Even a library like openssl using raw arithmetic operators all over the place is just weird imo. Every arithmetic operation should be checked version of the operation unless there is a provable performance hit. Languages should just not have operators
There was just a nginx issue that highlights how problematic the use of unsigned is in this context: CVE -2026-123007
For why I think it's unrealistic to go all-in on signed integers in C, it's because sizeof is unsigned, and most APIs dealing with lengths use size_t, and there are many pitfalls when mixing signed and unsigned types.
But I agree that there's a good case for using signed for the task behind that CVE. As I said, there are compelling reasons.
OpenSSL is a case study in the pitfalls with mixing signed and unsigned in C code. A major reason is the careful dance it has to do mixing signed and unsigned, and it stumbles. There's no substitute for being careful with arithmetic, and at least for me, when I expend that effort I also tend to use overflow checking APIs, clamping, etc, because it's less prone to error. Do that and the benefits of signed start to disappear, or at least the debate starts to lose relevance. Why OpenSSL doesn't create and use a set of overflow checking routines is beyond me as it would simplify an incredible amount of very hairy and brittle code.
With unsigned you only need one check: 'i < bound', it works always, regardless how i is computed, and it doesn't matter if the calculation overflowed or wrapped around, still works.
With signed you need: 'i >= 0 && i < bound', and you need to be very careful how you calculate i because overflow is undefined behavior.
> That's why it's recommended to use size_t for passing sizes of buffers.
I have always been told it is a bad idea to use unsigned integers in your interfaces. Why? An accidental negative (signed) value will be cast into an enormous unsigned value. For example, if you look at the vast majority of the Win32 API, inputs are normally signed integers. They rarely use unsigned integers.If you use mostly unsigned values it's not a huge problem, as long as you don't perform subtractions or operations with possibility of overflow. If obtaining a negative value or getting an overflow may occur, you should perform proper checks before calling an API function. And in case of WinAPI or something similar usually no extra computations before a call are necessary, arguments are already precomputed (like with buffer sizes).
I like the site: concise explanations, commands to check if you’re affected (if available), and low traffic RSS subscriptions as they only process vital CVEs. Hope it continues to operate!
This is what the scores should have been, I'm tired of these 9.0+ vulns every other day.
And yea, I'd really like a day where I'm not writing an email to customers about what they do and don't need to update regarding our software.
Haven't we suffered enough yet with lack of a basic feature in C? Why are enhancements going into C that never address this fundamental problem?
I wrote this proposal for C 17 years ago:
file:///C:/digitalmars/articles/C-biggest-mistake.html
It's a simple addition, it breaks 0 code, and provides a path forward to stop array overflows for good.
It's a foundational feature for D. We don't have buffer overflows.
You don't have that class of buffer overflows, but for as long as D allows raw pointer arithmetic, you still got buffer overflows, i.e. here's a simple snippet triggering ASAN: https://godbolt.org/z/qPhMKzM1z
Is that URL supposed to be a joke?
I feel like in the post heartbleed era, a lot of people are not including new features of upstream openssl as much as they used to.
pacman -Q | grep openssl
openssl 4.1.0-1
openssl-3 3.5.9-2Fortunately it doesn't look like I need to patch anything at work though.
Bleeding edge distros like Arch/Fedora are already on 4.x, so they'll be impacted, but they should also receive a patch relatively quickly.
- Let's return -1 for error
- People might not expect new -1 value, let's return 0
- How are clients supposed to differ between old 0 and new 0
The Unix flavour of C, which relies on passing magical numbers, is making C's lack of proper error handling patterns a lot worse.
I need some of you people to get hacked so I have something to point to, or I won't be able to convince management that this is worth taking seriously for much longer.
It's a number to guide your risk assessment process. If you don't have one of those, you shouldn't worry about them and read what people with risk assessment processes write about the CVEs.
Some people processing a lot of data are probably panicking right now. I doubt any website will get hacked.
# Hardcoded weights for AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
attack_vector = 0.85 # Network
attack_complexity = 0.77 # Low
privileges_required = 0.85 # None
user_interaction = 0.85 # None
confidentiality = 0.56 # High
integrity = 0.56 # High
availability = 0.56 # High
impact_sub_score = 1 - (1 - confidentiality) \* (1 - integrity) \* (1 - availability) # -> 0.91
impact = 6.42 \* impact_sub_score # -> 5.87
exploitability = (
8.22 \* attack_vector \* attack_complexity \* privileges_required \* user_interaction) # -> 3.88
score = impact + exploitability # -> 9.76
(using Github's values from https://github.com/advisories/GHSA-83xj-7xh4-4p7x)Interesting that the impact calculation treats C, I, A as equal. And of course a lot of those inputs are just human(?) supplied vibes and/or context dependent in your use case.
Plus we're seeing "AI has found this bug and it looks super duper scary everyone panic" followed by two weeks later "well actually it took sustained and direct assault on a website and sometimes it didn't work and it was actually more like a 6.4" lately.
Geezus_42's "you probably haven't actually shipped this code anywhere anyhow" is more like what I was looking for.
This is another base64 encoder where it takes a blob and coverts it to base64. I'm assuming an attacker control bit of data could be passed to the function which then overflows. Not sure if it can attempt to control a valid address or not, but unlocked AI likely could pretty quick.
Rust fixes it.
Things like the dumb (not like I'm any individual being dumb. Just collective accumulated stupidity) a*hole vulnerability some weeks ago. That wasn't even performance sensitive.
If you want a safe interface that does not require passing random sizes around in extra arguments, this can also be done in C.
Like time-constant, and it's hard to be time-constant in a performance optimised language like Rust. LLVM is doing some magic, and you don't want any magic in a crypto library.
Meanwhile, ring [2] carries an explicit disclaimer of "This is an experiment".
It's not "just keep up with the patches". That's going to be a losing strat.
My feeling is that if we use traditional security approaches that seems like a losing strategy. You cannot just keep patching. I mean obviously you should, but that is not enough.
LLMs are finding zero days in operating systems, language runtimes, everything. They will definitely be finding holes in your API. It is not a question of 'if'.
As a thought experiment if this hypothetical application code were written in something resembling haskell I suspect it would actually prove fairly difficult if not impossible to find novel ways to exploit it. I think at that point an attackers only options are logical inconsistencies in the underlying business logic (see that one NASA rocket) or bugs in the compiler and runtime.
Sometimes the fix can be worse than the bug. Like patching a hole in the wall.
I really find sad how far we have gone. Purely technical merits of a fix should always be an open conversation.