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

Integer overflow check in memory allocation #213

Merged
merged 2 commits into from
Oct 22, 2019

Conversation

adamkaplan
Copy link
Contributor

@adamkaplan adamkaplan commented Oct 14, 2019

Synopsis

The copy of RSSwizzle embedded in TrustKit uses an unchecked outside value to allocate memory. The PR adds integer overflow protection to the memory allocation size.

Attack Details

This code was flagged by automated static security scanners at Yahoo. The vulnerability details are https://cwe.mitre.org/data/definitions/190.html

The scanner message:

Signed_Memory_Arithmetic issue exists @ TrustKit/TrustKit/Dependencies/RSSwizzle/RSSwizzle.m
Signed integer strlen at line 73 of TrustKit\TrustKit\Dependencies\RSSwizzle\RSSwizzle.m specifies size of memory to allocate.

Proposed Fix

Added a simple integer overflow check to the code: if (strlen(x) > strlen(..)+2) {...}. When this case is true, the Swizzling is aborted.

Impact

There is no realistic failure path that doesn't impact the library. In the event of integer overflow in the objective-c type specifier, I added return NO, effectively declining to swizzle the method. The alternative is to allow the integer overflow, which will almost certainly crash the containing program. I would say that the impact of having this fix is "less severe" than not having it.

@adamkaplan adamkaplan changed the title Don't rely on external variable for memory allocation Integer overflow check in memory allocation Oct 14, 2019
@nabla-c0d3 nabla-c0d3 merged commit 70e58a8 into datatheorem:master Oct 22, 2019
@nabla-c0d3
Copy link
Member

Thanks for the PR! I'm curious: can you say which tool was used to find this?

@adamkaplan
Copy link
Contributor Author

I'm really not too sure what they're using. The scanner automatically generates Jira tickets that get assigned to the responsible team. The Mitre link was provided in the ticket.

@adamkaplan adamkaplan deleted the memory-allocation branch November 4, 2019 03:46
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.

2 participants