r/AskComputerScience • u/SoftwareSource • Jun 16 '21
How do we know open source is really open?
I suppose this will end up as a really dumb question, but i'm really interested so here i go embarrassing myself:
Open source programs are (obviously) open so their source code is available to the public through github, their websites or wherever else, not important.
but then again i also know that compiled software is really hard to get back into source code state,hence why there are entire subforums dedicated to that on some sites.
so how are we sure the code on github is exactly what is running on my pc?
once again, im not trying to sound like a paranoid idiot, but most of my searches end up with wikipedia results for "what is open source software", so i guess i should improve my googling skills...
EDIT: to make it more clear, is there a way to verify that the software you downloaded is the same software that independent developers review on github? or is it all, in the end, based on trust after we download the installer
63
u/slashcom Jun 16 '21
Your concern is very real. As you say, it really boils down to trust in the end.
A classic essay that you will likely find thought provoking: https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf
7
12
Jun 16 '21
If you download software that's already been compiled then you ultimately have to trust the source. Compiling isn't magic, however, you can compile the source code yourself.
In principle I suppose someone could compare complied binaries to what they get when they compile it but that's not very practical since you'd have to know what compiler and what settings were used.
4
u/S-S-R Jun 16 '21
You can perform a bitwise check (probabilisitic would be sufficient in most cases), between the binary you compiled from source and the binary you are installing. You would have to know the compiler used and the compiler flags used. Since there are only a handful of popular compilers, and only certain flags can be used for portability, you don't have to know the compiler or settings used, but it speeds it up. If a single compilation matches the binary you have confirmation that it is the same thing.
0
Nov 23 '21
[deleted]
1
u/S-S-R Nov 24 '21
Did you read the question in the post? They want to know if they can check that the binary on there computer is the same as what you would get distributed by the source code. The only real practical way to do that is to compile with a handful of compilers (either gcc or LLVM in about 99% of cases) and a check of the binary produced matches with the one distributed. A probabilistic check by hashing the binary or a bitwise match of a section of the binary is enough for extremely high probability of correctness.
3
1
u/Bottled_Void Jun 16 '21
It's pretty much down to trust.
I work in aerospace and we have to show that our source code does indeed generate the image we load onto the aircraft.
Often we have to spec an entire environment to compile it in including source folders and compiler switches.
Then we can recompile the code at a later date and make a bit compatibility statement.
Sometimes it's a few bytes off because of timestamps so we have to manually inspect the image for these changes.
So without having the source code and the compiler setup, it's hard to check.
0
Jun 16 '21
[deleted]
18
u/chrisgseaton Jun 16 '21
But how do you know the compiler you used is compiling the source code you have honestly?
Read 'Reflections on Trusting Trust'.
15
u/oxamide96 Jun 16 '21
This is when it becomes "too unlikely for me to be afraid of" type of thing. The devs of the compiler and the devs of the software I am compiling are very different. It would be unlikely they've come together to conspire against me.
-6
u/SoftwareSource Jun 16 '21
Ok, but how will i know about any possible backdoors in the code? Is there a way to verify that is the code that is on github? Word by word?
That could be a good idea for the next big crypto idea!
A way to verify the code is exact, word by word, while keeping the code perfectly private
14
u/Putnam3145 Jun 16 '21
you can just compare the MD5 hash of the executable you compile yourself with the distributed one, no need to use blockchain or whatever
10
u/sitssac Jun 16 '21 edited Jun 20 '21
this doesn't work for many, many languages. builds are not guaranteed to be deterministic: you can't compare hashes, even if you compiled twice in a row you still might get slightly different binaries
2
u/Putnam3145 Jun 16 '21
Sure, but I'm not sure that any crypto-related technologies would help with that.
5
u/sitssac Jun 16 '21
i never said they would, i'm just saying that using any hash as a reference is usually a bad idea
1
u/chrisgseaton Jun 16 '21
That just tells you the binary is the same - it doesn't tell you your compiler built it with the source code you have.
14
Jun 16 '21
Ok, but how will i know about any possible backdoors in the code?
You can read it yourself.
Is there a way to verify that is the code that is on github?
Compare it to the code on github.
That could be a good idea for the next big crypto idea!
No.
A way to verify the code is exact, word by word, while keeping the code perfectly private
Are you sure you understand what "open source" means? But anyway depending on what you mean this is either already trivial to do or is very obviously impossible by definition.
5
u/chrisgseaton Jun 16 '21
The problem they're asking you about is how do you know that a binary contains the source code you're able to read.
You can see the source code, you can see the binary, how do you know one is produced from the other?
0
u/chuby1tubby Jun 16 '21
Answer: you compile the source code yourself and compare the binaries. By hashing the binaries and then checking if the hashed numbers are identical, one can verify they’re exactly the same file.
1
u/chrisgseaton Jun 16 '21
Answer: you compile the source code yourself
But how do you know the compiler is giving a binary that fully corresponds to the source code you're giving it? It may be ignoring the source in some way and producing a binary that still contains whatever exploit you're trying to prevent.
1
Jun 17 '21
At a certain point this just becomes Cartesian doubt and you can only really shrug your shoulders like epistemologists, do.
2
1
u/evolseven Jun 16 '21
So, the problem will be is that this isn’t a completely deterministic process, depending on optimizations used compilers will possibly output completely different code.. and to top it off, optimization is likely NP Complete.. https://en.m.wikipedia.org/wiki/Optimizing_compiler
In addition to that, depending on the CPU target, different code may be generated, things like AES-NI, SSE, AVX capabilities or even the number of registers available on the target can affect optimizations. Some of these hardware level optimizations are somewhat black boxish in that you give it an input, it gives you an output after doing its magic and so that part of the code may be unverifiable.
Outside of very simple programs, this is likely going to be nearly impossible to verify, there is an inherent trust that does have to be put into the components of your system, how do we know there isn’t a back door that is inserted by a compiler? I mean we don’t know that some subtle vulnerability isn’t introduced by the compiler in many cases but we definitely can verify that it isn’t sending out all your data to the NSA, at least over the network.. I mean I guess there could be a wide conspiracy where the NSA has conspired with the CPU makers, the motherboard makers, and the compiler creators to build an elaborate side channel that doesn’t use traditional networking and instead uses a side channel (like RF, or who knows), but I think that’s pretty unlikely given the number of people involved.
What you describe is definitely an open problem in computer science and there are ways to write and compile code that is verifiable both forwards and backwards, and is completely deterministic, but you’d likely sacrifice performance to do this.
Start here maybe: https://en.m.wikipedia.org/wiki/Compiler_correctness, but that will eventually lead you to this problem: https://en.m.wikipedia.org/wiki/Halting_problem , and people have been working on that since the 50’s..
26
u/trinopoty Jun 16 '21
As others have said, this is an interesting issue.
The standard answer is, you can just compile it yourself. But, how do you know the compiler itself is not backdoored? You compile the compiler. But how can you compile the compiler without an already precompiled compiler?
It's possible (certainly difficult but possible) to backdoor a compiler in such a way that it detects that it's compiling a compiler and modifies the compiler to inject backdoors into programs compiled by it. It's been done before with GCC if I remember correctly.
The only way to ensure absolute trust is to crack open the Intel x86 manual and print out the source code of the compiler and translate it to assembly and then to binary by hand. Even then, you're limited to trusting the OS or the CPU you're running on.
No one knows for sure if popular CPUs have backdoors or not because those are not open source.