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

ASN1 Buffer Overflow #19335

Closed
robszewczyk opened this issue Jun 8, 2022 · 1 comment
Closed

ASN1 Buffer Overflow #19335

robszewczyk opened this issue Jun 8, 2022 · 1 comment
Assignees

Comments

@robszewczyk
Copy link
Contributor

Problem

The ASN1Reader class has to keep track of the parsing state, and in one location it is
possible to cause the reader to access data outside the bounds of the buffer being read.
This occurs in the code excerpt below when the end of the container is set to a point that
might be beyond the end of the buffer containing the parsed data.

In ASN1Reader::EnterContainer, we find:

    CHIP_ERROR ASN1Reader::EnterContainer(uint32_t offset)
    {
        ReturnErrorCodeIf(mNumSavedContexts == kMaxContextDepth, ASN1_ERROR_MAX_DEPTH_EXCEEDED);
        mSavedContexts[mNumSavedContexts].ElemStart = mElemStart;
        mSavedContexts[mNumSavedContexts].HeadLen = mHeadLen;
        mSavedContexts[mNumSavedContexts].ValueLen = ValueLen;
        mSavedContexts[mNumSavedContexts].IndefiniteLen = IndefiniteLen;
        mSavedContexts[mNumSavedContexts].ContainerEnd = mContainerEnd;
        mNumSavedContexts++;
        mElemStart = Value + offset;
        if (!IndefiniteLen)
        {
            mContainerEnd = Value + ValueLen;
        }
        ResetElementState();
        return CHIP_NO_ERROR;
    }

If Value + ValueLen runs beyond mContainerEnd , a future access might be outside the bounds of
the buffer, as other locations within the code assume that mContainerEnd falls within the
bounds of the buffer passed to the Init function. This issue resulted in various out of
bounds read accesses throughout the reader, depending on the type being read.

@emargolis
Copy link
Contributor

Fixed with #19549. Closing

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

No branches or pull requests

3 participants