hannestschofenig / mbedtls

An open source, portable, easy to use, readable and flexible SSL library
https://tls.mbed.org
Apache License 2.0
15 stars 8 forks source link

Fix memory leak in mbedtls_ssl_handshake_free #360

Closed lhuang04 closed 3 years ago

lhuang04 commented 3 years ago

Summary: We try to mbedtls_free object inside handshake after its address is zeroed out by mbedtls_platform_zeroize

Test Plan: Here is from our report.

=================================================================
==3365627==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 256 byte(s) in 1 object(s) allocated from:
    #0 0x1ab37c7 in calloc (/data/users/lhuang04/fbsource/fbcode/buck-out/dbg/cells/fbsource/gen/aab7ed39/xplat/mobilenetwork/test/test+0x1ab37c7)
    #1 0x10f549d in ssl_server_hello_postprocess xplat/mobilenetwork/third-party/mbedtls/library/ssl_tls13_client.c:3369
    #2 0x10e7e2e in ssl_server_hello_process xplat/mobilenetwork/third-party/mbedtls/library/ssl_tls13_client.c:2864
    #3 0x10e6b6c in mbedtls_ssl_handshake_client_step_tls1_3 xplat/mobilenetwork/third-party/mbedtls/library/ssl_tls13_client.c:4175
    #4 0x10dfd77 in mbedtls_ssl_handshake_step xplat/mobilenetwork/third-party/mbedtls/library/ssl_tls.c:6090

Reviewers:

Subscribers:

Tasks:

Tags:

Notes:

Status

READY/IN DEVELOPMENT/HOLD

Requires Backporting

When there is a bug fix, it should be backported to all maintained and supported branches. Changes do not have to be backported if:

Yes | NO
Which branch?

Migrations

If there is any API change, what's the incentive and logic for it.

YES | NO

Additional comments

Any additional information that could be of interest

Todos

Steps to test or reproduce

Outline the steps to test or reproduce the PR here.