-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault in some machines and not in others using OpenBSD adJ74 #206
Comments
I don't really know what "adj74" means, but I've managed to reproduce
This is not a suggested solution, just a test to confirm that we're looking at the same problem. |
Thanks for answering. adJ is a disribution of OpenBSD, see https://en.wikipedia.org/wiki/AdJ Note that I'm using go 1.22 while OpenBSD 7.4 has package of go 1.21. You could compile the port of go 1.22 available for current-OpenBSD, see https://cvsweb.openbsd.org/ports/lang/go/ or maybe the unsigned package for adJ 7.4 could work on OpenBSD, you could try with: 1. Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz:
2. Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
3. AMD FX(tm)-8350 4000.42 MHz
|
Just in case you wonder, 0x428a2f98 is the first constant in K256 table. Even though one system kept crashing, the fact that gdb prints the expected value indicates that it ought to be the same problem I've experienced. On it. Thanks for the confirmation. |
Could you test sha256-rodata branch from https://github.com/dot-asm/blst of mine? Just clone it and test the Go bindings. [For reference, the problem is not specific to Go, Rust was crashing too...] |
Yes. I notice that the situation improved in the first CPU. So the idea of adding read only sections is good. 1. Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
passes all 28 tests withouth issue. Although:
2. Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
fails, some lines that seems relevant to me:
while
keeps passing all the 28 tests. 3. AMD FX(tm)-8350 4000.42 MHz
fails, some lines that seems relevant to me:
And
|
I'm not convinced that you managed to exercise the updated code from the sha256-rodata branch on the systems that fail. And the reason for why I think that is because the difference between |
You right, I'm sorry. Cleaning the cache is necessary. The situation improved in all computers, in all of them all the tests pass with The non-portable tests kept failing in two of them but I noticed that it is because those processor don´t have support for ADX (https://en.wikipedia.org/wiki/Intel_ADX) neither BMI2 (https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set#BMI2) instruction sets (in particular they don´t have the instructions In both Since I guess that you don´t plan to add What follows is result of some experiments, I did them by installing 1. Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
2. Intel(R) Core(TM) i5-8265U CPU @ 1.60GHzSince the branch
But it is crazy that after this Repeating the procedure we found that what makes that the problem "disappears" temporarily is reading from K256 (i.e This could have relation with the security policy W^X of OpenBSD http://www.openbsd.org/papers/ven05-deraadt/mgp00029.html. But it is weird that:
Could it be that the problem is not with the policy W^X but with the requirement of recent OpenBSD of position independent code? 3. AMD FX(tm)-8350 4000.42 MHz
|
??? Portable builds are designed to run on CPUs without ADX, so what do you mean?
W^X effectively translates to "if writable, then non-executable" and it's the only thing that x86 hardware can actually enforce. In sense that executable page can be non-writable, but it can't be non-readable. OpenBSD appears to refuse to map .text pages upon data references, but if a .text page is mapped through execution, it's not a problem to read it. So that it's not really a policy, but rather just a artificial hurdle. One can even argue it's counterproductive :-) |
Sorry I meant non-portable builds for CPUs without ADX. But forget the comment please. Focusing in OpenBSD/adJ on platforms amd64 I need to remember that the portable |
After experimenting more I'm not so sure that the crash was due to a conflict with W^X. Could it be with the requirement of position indepenent executables of recent OpenBSD/adJ? (see PIE in https://www.openbsd.org/53.html and https://www.openbsd.org/papers/asiabsdcon2015-pie-slides.pdf possibly slide 22) I reviewed http://www.openbsd.org/papers/ven05-deraadt/mgp00016.html and some experiments I had done before https://dhobsd.pasosdejesus.org/wxorx.html (sorry it is in spanish, I had to update the example to be Position Independent, the first example is a program that tries to modify its code, second one is a program that writes code in its data and tries to execute it, both produce SIGSEGV due to the W^X policy). My understanding of W^X applied to ELF binaries that is our case is that there cannot be a section with the flag WRITE and with the flag EXEC. IMHO it is a secure practice (that has been adopted by several operating systems). |
Right, and sha256-x86_64 was not in violation of the policy in question. It had read-only data in the executable segment. And per x86 architecture specification no kernel can prevent it from working if the translation from logical to physical address for the relevant page is already established. And no OS had problems so far, and this is since the implementation inception in 2005. Yes, it means that if the page with K256 was mapped for whatever reason, it would have worked even here. As was demonstrated by "manually" mapping it in the debugger. |
The fix is committed. Thanks for the report! |
I have tested a lot your fix and it works, I agree before the fix you code was not in violation of the W^X policy. I guess that the change was necessary in OpenBSD/adJ with the answer of In any case I think that your changes dae1f94 and 6cca12a improve the security of |
@dot-asm may I know when do you plan to publish a new release? |
New release |
In the context of ava-labs/avalanchego#2782 and porting Avalanche tools to OpenBSD/adJ 7.4 we experienced segmentation faults and traced them to
blst
.We compiled and tested
blst
in different CPUS all of them running OpenBSD/adJ 7.4 wihllvm 13.0.0
andgo 1.22.0
we tested non-portable and portable builds as follows:The summary of results is:
The details of the test that didn´t pass was too long for this issue so it is available at: https://github.com/vtamara/blst/wiki/Segmentation-fault-in-some-machines-and-not-in-others-using-OpenBSD-adJ74
The text was updated successfully, but these errors were encountered: