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

Ensure that rc5 doesn't try to use a key longer than 2040 bits #8834

Closed
wants to merge 2 commits into from

Conversation

mattcaswell
Copy link
Member

The maximum key length for rc5 is 2040 bits so we should not attempt to
use keys longer than this. We truncate them to 2040 bits instead.

Issue found by OSS-Fuzz and Guido Vranken.

@mattcaswell mattcaswell added branch: master Merge to master branch branch: 1.1.1 Merge to OpenSSL_1_1_1-stable branch labels Apr 26, 2019
@mattcaswell
Copy link
Member Author

@guidovranken

@guidovranken
Copy link
Contributor

Confirmed that this resolves the issue.

@t-j-h
Copy link
Member

t-j-h commented Apr 26, 2019

Silent truncation seems like the wrong choice to me. It should fail.

@mattcaswell
Copy link
Member Author

Silent truncation seems like the wrong choice to me. It should fail.

That isn't possible to do without an API break because this is a void function. I did consider that, but it doesn't seem appropriate for a stable branch since this is targeting 1.1.1. Silent truncation seemed like the lesser of two evils.

=head1 BUGS

Currently the number of rounds in RC5 can only be set to 8, 12 or 16.
This is a limitation of the current RC5 code rather than the EVP interface.
Copy link
Member

Choose a reason for hiding this comment

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

This still seems to be the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I documented the restriction of 8, 12 or 16 in the section on the EVP_CTRL_SET_RC5_ROUNDS ctrl. I didn't see this as a "bug" so the writing it in a bugs section seemed misplaced. The fact that its a limitation of the rc5 code rather than the evp interface is an implementation detail that doesn't seem relevant to the end user.

@kroeckx
Copy link
Member

kroeckx commented Apr 26, 2019

In 3.0 you could at least change it to return something, that is API compatible. I doubt it's ABI compatible on all our platforms to suddenly return something, so for 1.1 either silent truncation, or just returning would be fine for me.

@mattcaswell
Copy link
Member Author

In 3.0 you could at least change it to return something, that is API compatible.

Yes, ok. That does make sense.

@guidovranken
Copy link
Contributor

Will this get merged at some point? https://oss-fuzz.com/testcase-detail/5750176758628352 is still active.

@guidovranken
Copy link
Contributor

Also see https://oss-fuzz.com/testcase-detail/5672061294346240 (RC5 integer overflow) which might be worth fixing.

The maximum key length for rc5 is 2040 bits so we should not attempt to
use keys longer than this.

Issue found by OSS-Fuzz and Guido Vranken.
If the key is too long we now return an error.
@mattcaswell
Copy link
Member Author

Thanks for the reminder. I've reworked and rebased this. There are now 2 commits:

  1. The first commit adds a check at the EVP layer for a key that is too long and fails if that occurs, but no changes are made to the underlying RC5_32_set_key function.

  2. The second commit changes the return type of RC5_32_set_key from void to int. The function is checked to ensure that the key is not too long. It returns 1 on success and 0 on error.

The second change should be API compatible but is not ABI compatible. I plan to push both commits to master and only the first commit to the 1.1.1 branch.

This means that, in 1.1.1, using RC5 via EVP will correctly fail if the key is too long. Using the low level RC5 functions directly with a key that is too long will still crash (as it does now).

Ping @kroeckx, @t-j-h.


=item EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_RC5_ROUNDS, 0, &rounds)

Stores the number of rounds currently configured in B<*rounds> where B<rounds>
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the second be *rounds too?
Alternatively, say it is a pointer to an int.

Copy link
Contributor

@paulidale paulidale left a comment

Choose a reason for hiding this comment

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

Pending the one documentation concern, this looks good for master and the first commit for 1.1.1.

@levitte
Copy link
Member

levitte commented Jun 29, 2019

(side note: I'm unsure if changing a void function to a function returning int is ABI incompatible. Such a change only means that old code ignores the return value, right?)

@levitte
Copy link
Member

levitte commented Jun 29, 2019

(ah, except letter downgrades, which is permissible. Never mind)

@kroeckx
Copy link
Member

kroeckx commented Jun 29, 2019 via email

levitte pushed a commit that referenced this pull request Jul 1, 2019
The maximum key length for rc5 is 2040 bits so we should not attempt to
use keys longer than this.

Issue found by OSS-Fuzz and Guido Vranken.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #8834)

(cherry picked from commit 792cb4e)
@mattcaswell
Copy link
Member Author

Pushed with the documentation fixup to master. Also cherry-picked the first commit only to 1.1.1.

@mattcaswell mattcaswell closed this Jul 1, 2019
levitte pushed a commit that referenced this pull request Jul 1, 2019
The maximum key length for rc5 is 2040 bits so we should not attempt to
use keys longer than this.

Issue found by OSS-Fuzz and Guido Vranken.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #8834)
levitte pushed a commit that referenced this pull request Jul 1, 2019
If the key is too long we now return an error.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from #8834)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch: master Merge to master branch branch: 1.1.1 Merge to OpenSSL_1_1_1-stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants