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

Memory corruption through mbedtls_mpi_sub_abs #4042

Closed
guidovranken opened this issue Jan 15, 2021 · 0 comments · Fixed by #4096
Closed

Memory corruption through mbedtls_mpi_sub_abs #4042

guidovranken opened this issue Jan 15, 2021 · 0 comments · Fixed by #4096

Comments

@guidovranken
Copy link
Contributor

#include <mbedtls/bignum.h>

#define CF_CHECK_EQ(expr, res) if ( (expr) != (res) ) { goto end; }

int main(void)
{
    mbedtls_mpi A, B, R;

    /* noret */ mbedtls_mpi_init(&A);
    /* noret */ mbedtls_mpi_init(&B);
    /* noret */ mbedtls_mpi_init(&R);

    CF_CHECK_EQ(mbedtls_mpi_read_string(&A, 10, "18446744073709551610"), 0);
    CF_CHECK_EQ(mbedtls_mpi_read_string(&B, 10, "700000000000000000000000000000000000000000000000000000000000000000000000000000"), 0);

    mbedtls_mpi_sub_abs(&R, &A, &B);

end:
    /* noret */ mbedtls_mpi_free(&A);
    /* noret */ mbedtls_mpi_free(&B);
    /* noret */ mbedtls_mpi_free(&R);
    return 0;
}
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Jan 27, 2021
Fix a buffer overflow in mbedtls_mpi_sub_abs() when calculating
|A| - |B| where |B| is larger than |A| and has more limbs (so the
function should return MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

Fix Mbed-TLS#4042

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Add test cases for mbedtls_mpi_sub_abs() where the second operand has
more limbs than the first operand (which, if the extra limbs are not
all zero, implies that the function returns
MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

This exposes a buffer overflow (reported in Mbed-TLS#4042).

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Fix a buffer overflow in mbedtls_mpi_sub_abs() when calculating
|A| - |B| where |B| is larger than |A| and has more limbs (so the
function should return MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

Fix Mbed-TLS#4042

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Add test cases for mbedtls_mpi_sub_abs() where the second operand has
more limbs than the first operand (which, if the extra limbs are not
all zero, implies that the function returns
MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

This exposes a buffer overflow (reported in Mbed-TLS#4042).

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Fix a buffer overflow in mbedtls_mpi_sub_abs() when calculating
|A| - |B| where |B| is larger than |A| and has more limbs (so the
function should return MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

Fix Mbed-TLS#4042

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Add test cases for mbedtls_mpi_sub_abs() where the second operand has
more limbs than the first operand (which, if the extra limbs are not
all zero, implies that the function returns
MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

This exposes a buffer overflow (reported in Mbed-TLS#4042).

Signed-off-by: Gilles Peskine <[email protected]>
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this issue Feb 1, 2021
Fix a buffer overflow in mbedtls_mpi_sub_abs() when calculating
|A| - |B| where |B| is larger than |A| and has more limbs (so the
function should return MBEDTLS_ERR_MPI_NEGATIVE_VALUE).

Fix Mbed-TLS#4042

Signed-off-by: Gilles Peskine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants