-
Notifications
You must be signed in to change notification settings - Fork 735
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
Remove integer arithmetic on values converted from pointers #101
Comments
Ideally, we would use C's |
Yep, I'm @ch3root on github too. I filled the name in the profile now:-) Quick search with coccinelle gives the following cases of casts of pointers to non-pointers: Line 338 in 72db3b2
ring/crypto/poly1305/poly1305_vec.c Line 85 in 72db3b2
Line 581 in 72db3b2
Line 744 in 72db3b2
Line 145 in 72db3b2
Line 159 in 72db3b2
|
Thanks and sorry!
There's also, at least, this one in ring/crypto/poly1305/poly1305_arm.c Line 186 in 72db3b2
Thanks for the tip about coccinelle. |
Yeah, coccinelle doesn't find everything -- sometimes it doesn't see enough info about types etc. But in this case it's not its fault -- I was searching pointers only and arrays were skipped. A bit more advanced script additionally finds three instances of the code you quoted -- the one you linked to and these two: ring/crypto/poly1305/poly1305_arm.c Line 212 in 72db3b2
ring/crypto/poly1305/poly1305_arm.c Line 260 in 72db3b2
The script is attached -- pointer-cast.cocci.zip. Run it as BTW the code you quoted could invoke UB when there is signed integer overflow in unary minus. |
Also MOD_EXP_CTIME_ALIGN and related things in crypto/bn/exponentiation.c. |
I notified OpenSSL of the issues in |
I submitted a PR to BoringSSL: https://boringssl-review.googlesource.com/#/c/7492/. But, I think they don't want to take it. |
Fixed.
These are just assertions verifying that alignment is done correctly when traversing the Rust <-> C interface. We may be able to remove this when we replace crypto/modes/gcm.c with Rust code. |
As of now, there's no use of |
Done (in the C code) |
We have done some work already to remove some uses of
uintptr_t
, such as bccbeb2. We should remove all of them. If, for some reason, we need to keep any, then we should encapsulate those uses in functions as described in http://trust-in-soft.com/when-in-doubt-express-intent-and-leave-the-rest-to-the-compiler/.The C standard says that it must be possible to convert a pointer to a
uintptr_t
and then convert theuintptr_t
back to a pointer, losslessly. However, the values of the resultant integers are implementation-defined. Also,uintptr_t
is optional in C11 and it is not guaranteed that any integer type can hold the value of a pointer."'6.2.8 Alignment of objects' in C11 hints that it should work in a natural way" and the mapping is "'intended to be consistent with the addressing structure of the exec. env.'" as pointed out by @AlekseyCherepanov on Twitter. However, I don't think we can rely on these, especially when it comes to undefined behavior prevention and compiler bug avoidance.
Note that some pointer -> integer conversions are not using
uintptr_t
orintptr_t
. It is common for the code to usesize_t
and I've also seen casts toint
. Those need to be found and fixed.The text was updated successfully, but these errors were encountered: