Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

ber.go: Protocol Validation and Defense #3

Closed
wants to merge 1 commit into from

Conversation

jentfoo
Copy link

@jentfoo jentfoo commented Aug 17, 2023

Replacement PR for #2

This PR attempts to address possible panic conditions due to access outside of the bounds of the slice. There are specifically three changes:

  • A couple log messages are commented out due to them attempting to do an out of bounds view into the slice.
  • Existing protocol validation was fixed. There was an attempt to guard against these conditions, however in many cases there was an off by one error, or other conditions had not been considered.
  • A PR from the parent fork which attempts to bring in a protocol fix for lengths between 0x80 and 0xFF was also included as part of this: fix BER tag length check when length is between 0x80 and 0xFF mozilla-services/pkcs7#68

The logic for slice access has been reviewed carefully in an attempt to make sure we are defensive, but still allowing the nuance of the PKCS7 structure. In addition extensive fuzzing has been conducted on these changes.

These changes are motivated to fix this issue: https://github.com/gravitational/teleport-private/issues/572

This change is temporary for Teleport, eventually we would like to depend on the more active project once the PR here is merged: digitorus#12

This commit attempts to address possible `panic` conditions due to access outside of the bounds of the slice.  There are specifically three changes:
 * A couple log messages are commented out due to them attempting to do an out of bounds view into the slice.
 * Existing protocol validation was fixed.  There was an attempt to guard against these conditions, however in many cases there was an off by one error, or other conditions had not been considered.
 * A PR from the parent fork which attempts to bring in a protocol fix for lengths between `0x80` and `0xFF` was also included as part of this: mozilla-services#68

The logic for slice access has been reviewed carefully in an attempt to make sure we are defensive, but still allowing the nuance of the PKCS7 structure.  In addition extensive fuzzing has been conducted on these changes.
return nil, 0, errors.New("ber2der: BER tag length has leading zero")
}
debugprint("--> (compute length) indicator byte: %x\n", l)
debugprint("--> (compute length) length bytes: % X\n", ber[offset:offset+numberOfBytes])
//debugprint("--> (compute length) length bytes: %x\n", ber[offset:offset+numberOfBytes])
Copy link

Choose a reason for hiding this comment

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

Revert this?

Copy link
Author

Choose a reason for hiding this comment

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

I was keeping this commented out on purpose. The debugprint does no action without manual code changes, and I feel like the slice index lookup is not worth general usage. What do you think?

@jentfoo
Copy link
Author

jentfoo commented Aug 18, 2023

Closing PR, digitorus#12 was merged 🎉

@jentfoo jentfoo closed this Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants