-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Prevent arithmetic on NULL pointer if the scratch space is too small #839
Conversation
Thanks for the PR! Before I have to time a real reply, let me note for anyone reading here that this is not something to worry about because scratch spaces are used nowhere in the public API currently. This is dead code used for future extensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
.travis.yml
Outdated
@@ -31,6 +31,7 @@ env: | |||
- BUILD=distcheck WITH_VALGRIND=no CTIMETEST=no BENCH=no | |||
- CPPFLAGS=-DDETERMINISTIC | |||
- CFLAGS=-O0 CTIMETEST=no | |||
- CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" CTIMETEST=no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should go to a different PR (if we want this at all). Not sure how long this takes on Travis, and it may not run on the GCC version on Travis etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the result on Travis: https://travis-ci.org/github/Fabcien/secp256k1-1/builds/738981454
UBSAN has a low overhead so the duration is only slightly impacted.
2fca70c
to
61dffd1
Compare
@real-or-random Now calling |
I'm ok with adding it here (can't speak for the others) but I think then it should look more like this line then (enable all the stuff) And should we add |
The best resource I could find is the documentation from LLVM. The GCC documentation explains the |
61dffd1
to
5fd2742
Compare
Concept ACK. I think CI tests with |
If the scratch space is too small when calling `secp256k1_ecmult_strauss_batch()`, the `state.pre_a` allocation will fail and the pointer will be `NULL`. This causes `state.pre_a_lam` to be computed from the `NULL` pointer. It is also possible that the first allocation to fail is for `state.ps`, which will cause the failure to occur when in `secp256k1_ecmult_strauss_wnaf()`. The issue has been detected by UBSAN using Clang 10: ``` CC=clang \ CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ ../configure UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 make check ```
Run UBSAN with both GCC and Clang, on Linux and macOS. The `halt_on_error=1` option is required to make the build fail if the sanitizer finds an issue.
5fd2742
to
29a299e
Compare
@sipa Sure, done. |
ACK 29a299e. Reviewed the code changes and verified that building with these sanitizer flags catches the existing error, as well as a signed integer overflow if introduced. |
There is an issue with Travis' s390x build, which I've cancelled. CI succeeded for all other builds. |
ACK 29a299e code inspection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 29a299e
…s too small Summary: ``` If the scratch space is too small when calling `secp256k1_ecmult_strauss_batch()`, the `state.pre_a` allocation will fail and the pointer will be `NULL`. This causes `state.pre_a_lam` to be computed from the `NULL` pointer. It is also possible that the first allocation to fail is for `state.ps`, which will cause the failure to occur when in `secp256k1_ecmult_strauss_wnaf()`. The issue has been detected by UBSAN using Clang 10: CC=clang \ CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ ../configure UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 make check ``` Backport of secp256k1 [[bitcoin-core/secp256k1#839 | PR839]]. Test Plan: With Clang and UBSAN: ninja check-secp256k1 Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8265
…s too small Summary: ``` If the scratch space is too small when calling `secp256k1_ecmult_strauss_batch()`, the `state.pre_a` allocation will fail and the pointer will be `NULL`. This causes `state.pre_a_lam` to be computed from the `NULL` pointer. It is also possible that the first allocation to fail is for `state.ps`, which will cause the failure to occur when in `secp256k1_ecmult_strauss_wnaf()`. The issue has been detected by UBSAN using Clang 10: CC=clang \ CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \ ../configure UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 make check ``` Backport of secp256k1 [[bitcoin-core/secp256k1#839 | PR839]]. Test Plan: With Clang and UBSAN: ninja check-secp256k1 Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8265
If the scratch space is too small when calling
secp256k1_ecmult_strauss_batch()
, thestate.pre_a
allocation willfail and the pointer will be
NULL
. This causesstate.pre_a_lam
to becomputed from the
NULL
pointer.It is also possible that the first allocation to fail is for
state.ps
,which will cause the failure to occur when in
secp256k1_ecmult_strauss_wnaf()
.The issue has been detected by UBSAN using Clang 10: