News for hackers. Stuff that matters.
Re:Why CVE-2022-3602 was not detected by fuzz testing by MuffinFlavored on Monday November 21, 2022 @11:15AM (#33694215)
> because ossl_a2ulabel had no unit tests until a few days ago

it's not realistic to enforce unit test coverage % with a project at the scale of OpenSSL, right?

Re:Why CVE-2022-3602 was not detected by fuzz testing by masklinn on Monday November 21, 2022 @11:26AM (#33694360)
> it's not realistic to enforce unit test coverage % with a project at the scale of OpenSSL, right?

Why not?

You can enforce that all new files should be covered (at the very least line-covered). It requires some setup effort (collecting code coverage and either sending it to a tool which perform the correlation or correlating yourself), but once that's done... it does its thing.

Then you can work on increasing coverage for existing files, and ratcheting requirements.

Re:Why CVE-2022-3602 was not detected by fuzz testing by duped on Monday November 21, 2022 @11:30AM (#33694426)
It's realistic to reject a CR for a new parsing function without proof that it works, which usually comes in the form of a unit test
Re:Why CVE-2022-3602 was not detected by fuzz testing by planede on Monday November 21, 2022 @11:34AM (#33694470)
Nit: a unit test never proves that it works. At best it can prove that it doesn't work.

Otherwise, I agree.

Re:Why CVE-2022-3602 was not detected by fuzz testing by hardware2win on Monday November 21, 2022 @11:54AM (#33694767)
Nit: "never"? Even if you unit test all cases?
Re:Why CVE-2022-3602 was not detected by fuzz testing by tz18 on Monday November 21, 2022 @12:08PM (#33694958)
Yes, never. You are assuming that the implementation of all unit test cases are themselves correct (that they would fail if there was any error in the case they cover). In fact unit tests are often wrong. In that context a unit test can't even prove code incorrect, unless we know that the unit test is correct.

IMO to prove that code is correct requires a proof; a unit test can only provide evidence suggestive of correctness.

Re:Why CVE-2022-3602 was not detected by fuzz testing by planede on Monday November 21, 2022 @12:21PM (#33695152)
Mistakes in proofs are just as probable as mistakes in exhaustive tests.

An exhaustive test is just one type of a machine verified proof.

Re:Why CVE-2022-3602 was not detected by fuzz testing by nicoburns on Monday November 21, 2022 @01:48PM (#33696289)
> An exhaustive test is just one type of a machine verified proof.

Not entirely sure I agree with this. A proof by construction is a very different beast to empirical unit tests that only cover a subset of inputs. The equivalent would be units tests that cover every single possible input.

Re:Why CVE-2022-3602 was not detected by fuzz testing by planede on Tuesday November 22, 2022 @03:57AM (#33703600)
> The equivalent would be units tests that cover every single possible input.

That's what "exhaustive" means.

Re:Why CVE-2022-3602 was not detected by fuzz testing by planede on Monday November 21, 2022 @12:19PM (#33695113)
Touché
Re:Why CVE-2022-3602 was not detected by fuzz testing by bluGill on Monday November 21, 2022 @04:59PM (#33698635)
How do you know you covered all cases. You can verify you cover all cases the code handles easily enough. However does the code actually handle all the cases that could exist? A formal proof can bring to your attention a case that you didn't handle at all.

Formal proofs also have limits. Donald Knuth once famously wrote "beware of bugs in the above code, I proved it correct but never ran it". Which is why I think we should write tests for code as well as formally prove it. (On the later I've never figured out how to prove my code - writing C++ I'm not sure if it is possible but I'd like to)

Re:Why CVE-2022-3602 was not detected by fuzz testing by planede on Tuesday November 22, 2022 @03:59AM (#33703606)
There are limited cases where this is possible. Like a pure function that takes a single 32bit number as input. Just go over all the possible inputs.
Re:Why CVE-2022-3602 was not detected by fuzz testing by bluGill on Tuesday November 22, 2022 @08:48AM (#33705710)
You can't as a verify all the outputs though, only that it doesn't crash, which isn't useful for detecting edge cases where the results are wrong but don't crash. And that is a single pure function, if that pure function with a wrong output is then fed into/used by some other function (a non-pure data storage in particular - a large part of what computers are used for is storage of some form, not pure functions) you can read off the end of the buffer or other bad things.

Even running through all 4 billion some cases a single 32 bit number can result in your test taking a significant amount of time - enough that you wouldn't want to run it very often. One value of real world tests is often that they can detect that you broke what you thought was a completely unrelated area of code.

Re:Why CVE-2022-3602 was not detected by fuzz testing by hardware2win on Tuesday November 22, 2022 @02:52PM (#33710476)
Seriously? It is pretty easy to imagine function which has limited and low combinations count

Enums, bools, etc.

>can result in your test taking a significant amount of time - enough that you wouldn't want to run it very often.

It is irrelevant in theoretical discussions like this

Re:Why CVE-2022-3602 was not detected by fuzz testing by asveikau on Monday November 21, 2022 @11:31AM (#33694433)
It's worth noting that coverage can be a deceptive metric sometimes.

You can have coverage on code that divides - it won't tell you if you ever divide by zero.

You can have coverage on code that follows a pointer - it won't tell you if you ever pass a bad pointer.

Re:Why CVE-2022-3602 was not detected by fuzz testing by adql on Monday November 21, 2022 @11:40AM (#33694548)
yeah but there isn't even a try here
Re:Why CVE-2022-3602 was not detected by fuzz testing by asveikau on Monday November 21, 2022 @12:55PM (#33695603)
Not saying it isn't worth an attempt, just that the real meaning shouldn't be lost.
Re:Why CVE-2022-3602 was not detected by fuzz testing by pca006132 on Monday November 21, 2022 @11:20AM (#33694261)
It should be realistic, line coverage isn't really that hard. The hard thing is that high line coverage alone is usually not enough for numerical stuff...
Re:Why CVE-2022-3602 was not detected by fuzz testing by stefan_ on Monday November 21, 2022 @11:27AM (#33694365)
No one is asking for that. But this is code that did one thing: punycode decoding, with millions of well documented test vectors. The code had zero dependencies on anything OpenSSL related. It is a very simple "text in, text out" problem, the most trivial thing to write unit tests for. At the same time, it's code that parses externally provided buffers and has to deal with things like unicode in C - there should be a massive red flashing warning light in every developers head here.
Re:Why CVE-2022-3602 was not detected by fuzz testing by jeffbee on Monday November 21, 2022 @11:22AM (#33694294)
It is trivial to enforce that new functions have new unit tests and fuzz tests. You are the reviewer of https://github.com/openssl/openssl/pull/9654 and you just say "Please add unit tests and fuzz tests for foo and bar" and you don't approve it.

I don't know what the deal is with their testing culture but in year 27 of the project they demonstrably haven't learned this lesson. It's nice that they added integration tests (testing given encoded certs) but as the article points out that was insufficient.

Re:Why CVE-2022-3602 was not detected by fuzz testing by dralley on Monday November 21, 2022 @11:44AM (#33694622)
IMO, one of the biggest benefits of "modern" systems languages like Rust, D, Zig is how much easier they make writing and running tests compared to C and C++. Yes, you can write tests for those languages, but it's nowhere near as trivial. And that makes a difference.
Re:Why CVE-2022-3602 was not detected by fuzz testing by pjmlp on Monday November 21, 2022 @12:31PM (#33695284)
I was writing unit tests for C in 1996, naturally we still haven't coined the term, so we just called them automatic tests.

It was part of our data structures and algorithms project, failure to execute the automatic tests meant no admission to the final exam.

We had three sets of tests, those provided initially at the begin of the term, those that we were expected to write ourselves, and a surprise set on the integration week at the end of the semester.

Re:Why CVE-2022-3602 was not detected by fuzz testing by fisf on Monday November 21, 2022 @12:07PM (#33694945)
I am not buying it.

Writing unit tests for c/c++ is trivial. There are perfectly fine test frameworks, used by developers every day, integrated in any major IDE or runnable as one-liner from the command line.

This is absolutely a cultural problem.

Re:Why CVE-2022-3602 was not detected by fuzz testing by edgyquant on Tuesday November 22, 2022 @12:43AM (#33702454)
In modern languages you either have built in testing or it’s a single package install away. It is nowhere near this simple with C or C++
Re:Why CVE-2022-3602 was not detected by fuzz testing by bluGill on Monday November 21, 2022 @05:03PM (#33698682)
Last week I code a "please add unit tests for this code". The person who wrote that comment wasn't aware that this was a refactoring where the functionality was well tested.

There is no substitute for reviewers who really understand the code in question. The problem is they are the ones writing the code and so are biased and not able to give a good review.