Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-883

Schannel: ClientHello buffer from InitializeSecurityContext is not freed after a successful handshake (memory leak per TLS connect)

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None
    • Windows 10 x64 (build 19045), Schannel. Found with MariaDB Connector/ODBC 3.2.10 (64-bit, libmariadb submodule be67a4f), server MariaDB 12.3.4 on the same machine.

    Description

      Every successful TLS connect through the Schannel backend leaks the ClientHello buffer (about 250 bytes per connection).

      Cause: libmariadb/secure/ma_schannel.c, ma_schannel_client_handshake(). InitializeSecurityContext (line 312, ISC_REQ_ALLOCATE_MEMORY) allocates the ClientHello in BuffersOut.pvBuffer. On success the function returns at line 356 ("return sRet;"), so FreeContextBuffer under "end:" (line 359) is only reached on the error paths.

      Fix: remove line 356, so the success path falls through to "end:"
      (sRet is SEC_E_OK there).

      How to repeat (attached connleak.c, ODBC API only): SQLConnect / SQLDisconnect in a loop against a DSN of Connector/ODBC 3.2.10 with FORCETLS=1, private bytes every 1000 connects. Result: +259 bytes per connect, linear; flat without FORCETLS.

      The attached schannel_hello.c (no server needed) repeats only the first InitializeSecurityContext with the flags of Connector/C: +265 bytes per iteration without FreeContextBuffer, flat with it.

      Seen in Connector/ODBC 3.2.10 (libmariadb be67a4f); the code is the same on the 3.3 and 3.4 branches.

      Attachments

        1. build.bat
          0.5 kB
        2. connleak.c
          7 kB
        3. schannel_hello.c
          5 kB

        Activity

          People

            Lawrin Lawrin Novitsky
            KritzelKratzel Kritzel Kratzel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.