Skip to content
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

Adding unsigned int sanitization and SCRUTINICE fixes #2103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

smittals2
Copy link
Contributor

Issues:

Description of changes:

  • Removal of some dead code
  • Adding unsigned-integer-overflow to UBSAN for compilation checking
  • Casting work arounds

Call-outs:

Point out areas that need special attention or support during the review process. Discuss architecture or design changes.

Testing:

How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@smittals2 smittals2 requested a review from a team as a code owner January 10, 2025 01:53
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.74%. Comparing base (c826c21) to head (23e96b8).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crypto/bio/bio.c 86.36% 3 Missing ⚠️
crypto/bio/hexdump.c 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2103      +/-   ##
==========================================
- Coverage   78.76%   78.74%   -0.02%     
==========================================
  Files         598      598              
  Lines      103656   103656              
  Branches    14720    14719       -1     
==========================================
- Hits        81641    81624      -17     
- Misses      21363    21379      +16     
- Partials      652      653       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +88 to +94
long callback_ret = bio->callback_ex(bio, oper, buf, len, 0, 0L, ret, &processed);
if (callback_ret <= INT_MAX) {
ret = (int)callback_ret;
if (ret > 0) {
// BIO will only read int |len| bytes so this is a safe cast
ret = (int)processed;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • callback_ret might also be less than INT_MIN. (We do a similar check on line 139 below.)
if (callback_ret <= INT_MAX && callback_ret >= INT_MIN) {
      ret = (int)callback_ret;
  • If callback_ret is not in this range we're simply not setting it (i.e., there's no else block), but that doesn't seem right. What value do we set it to? Maybe -1?

Comment on lines +139 to +140
if (ret <= 0 && ret >= INT_MIN) {
return (int)ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If ret <= 0, the function should return even if ret < INT_MIN. Maybe return INT_MIN?
if (ret <= 0) {
  if (ret >= INT_MIN) {
    return (int)ret;
  } else {
    return INT_MIN;
  }
}
  • Ditto for the numerous similar changes below in this file.

@@ -448,7 +448,7 @@ BIGNUM *BN_mpi2bn(const uint8_t *in, size_t len, BIGNUM *out) {
}
out->neg = ((*in) & 0x80) != 0;
if (out->neg) {
BN_clear_bit(out, BN_num_bits(out) - 1);
BN_clear_bit(out, (int)BN_num_bits(out) - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: Should we verify that (BN_num_bits(out) - 1) <= INT_MAX?

@@ -85,12 +85,10 @@ void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
}
(*block)(out, out, key);
iv = out;
// This will always be true as a result of the first while loop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should instead change the while (len) above to an if (len > 0) and then there's no reason to break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants