Bug 1839827 (CVE-2020-13249)

Summary: CVE-2020-13249 mariadb-connector-c: Improper validation of content in a OK packet received from server
Product: [Other] Security Response Reporter: Pedro Sampaio <psampaio>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: damien.ciabrini, databases-maint, dbecker, dciabrin, hhorak, jjanco, jjoyce, jorton, jschluet, jstanek, lhh, ljavorsk, lpeer, mbayer, mburns, mkocka, mmuzila, mschorm, sclewis, slinaber, SpikeFedora
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: mariadb-connector-c 3.1.8, mariadb 10.4.13, mariadb 10.3.23, mariadb 10.2.32 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-10-05 20:21:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1839828, 1841915, 1841916, 1841917, 1841918, 1843795, 1843796, 1843797, 1880332, 1894126, 1899069, 1899070, 1899071, 1899072, 1899073, 1899074, 1899075, 1899076    
Bug Blocks: 1839829    

Description Pedro Sampaio 2020-05-25 16:53:50 UTC
libmariadb/mariadb_lib.c in MariaDB Connector/C before 3.1.8 does not properly validate the content of an OK packet received from a client. NOTE: although mariadb_lib.c was originally based on code shipped for MySQL, this issue does not affect any MySQL components supported by Oracle.

Upstream fix:

https://github.com/mariadb-corporation/mariadb-connector-c/commit/2759b87d72926b7c9b5426437a7c8dd15ff57945
https://github.com/mariadb-corporation/mariadb-connector-c/compare/v3.1.7...v3.1.8

Comment 1 Pedro Sampaio 2020-05-25 16:54:13 UTC
Created mariadb-connector-c tracking bugs for this issue:

Affects: fedora-all [bug 1839828]

Comment 2 Tomas Hoger 2020-05-27 12:20:46 UTC
In reply to comment #0:
> libmariadb/mariadb_lib.c in MariaDB Connector/C before 3.1.8 does not
> properly validate the content of an OK packet received from a client.

This description is incorrect, as "An OK packet is sent from the server to the client to signal successful completion of a command.":

https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html

Comment 3 Tomas Hoger 2020-05-27 12:25:49 UTC
MariaDB Connector/C is included with MariaDB Server 10.2 and later.  The fixed Connector/C version was added to Server source code via this commit:

https://github.com/MariaDB/server/commit/1d1fb13e59

in versions 10.2.32, 10.3.23, 10.4.13, and 10.5.3.

Comment 4 Tomas Hoger 2020-05-28 22:10:51 UTC
The fix linked in comment 0 corrects multiple out-of-bounds read issues.  They were possible because of insufficient checks of lengths of various fields extracted from OK packets received form a MySQL/MariaDB server - when field length was extracted from the packet, MariaDB Connector/C did not ensure that the length does no exceed the remaining size of the package received.  These issues could trigger crash.

However, there was also an out-of-bounds write issue, where a value read from the packet was copied to a fixed size buffer cs_name[] without checking the size of the data:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/v3.1.7/libmariadb/mariadb_lib.c#L2132-L2135

Comment 6 Tomas Hoger 2020-06-04 07:29:39 UTC
Created mariadb tracking bugs for this issue:

Affects: fedora-all [bug 1843795]


Created mariadb:10.3/mariadb tracking bugs for this issue:

Affects: fedora-all [bug 1843796]


Created mariadb:10.4/mariadb tracking bugs for this issue:

Affects: fedora-all [bug 1843797]

Comment 7 Tomas Hoger 2020-06-04 08:08:29 UTC
There is another case when out-of-bounds write can happen.  The following code sets mysql->info to point directly into the input packet data without creating a copy:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/v3.1.7/libmariadb/mariadb_lib.c#L2045-L2046

and subsequently ensures that the data is correctly zero terminated:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/v3.1.7/libmariadb/mariadb_lib.c#L2065-L2067

However, missing field length checks as noted in comment 4 can cause the 0 to be written outside of the allocated buffer.

Comment 8 Tomas Hoger 2020-06-04 20:22:41 UTC
Actually, my info in comment 7 seems wrong - this check should have prevented write beyond the end of the packet:

https://github.com/mariadb-corporation/mariadb-connector-c/blob/v3.1.7/libmariadb/mariadb_lib.c#L2057

Comment 12 errata-xmlrpc 2020-10-05 15:15:53 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections for Red Hat Enterprise Linux 6
  Red Hat Software Collections for Red Hat Enterprise Linux 7
  Red Hat Software Collections for Red Hat Enterprise Linux 7.6 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS

Via RHSA-2020:4174 https://access.redhat.com/errata/RHSA-2020:4174

Comment 13 Product Security DevOps Team 2020-10-05 20:21:12 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):

https://access.redhat.com/security/cve/cve-2020-13249

Comment 14 errata-xmlrpc 2020-11-30 13:44:57 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections for Red Hat Enterprise Linux 7
  Red Hat Software Collections for Red Hat Enterprise Linux 7.6 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7.7 EUS

Via RHSA-2020:5246 https://access.redhat.com/errata/RHSA-2020:5246

Comment 15 errata-xmlrpc 2020-12-15 17:10:17 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2020:5500 https://access.redhat.com/errata/RHSA-2020:5500

Comment 16 errata-xmlrpc 2020-12-15 17:11:15 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2020:5503 https://access.redhat.com/errata/RHSA-2020:5503

Comment 17 errata-xmlrpc 2020-12-22 09:02:21 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.2 Extended Update Support

Via RHSA-2020:5654 https://access.redhat.com/errata/RHSA-2020:5654

Comment 18 errata-xmlrpc 2020-12-22 09:07:26 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.2 Extended Update Support

Via RHSA-2020:5655 https://access.redhat.com/errata/RHSA-2020:5655

Comment 19 errata-xmlrpc 2020-12-22 09:15:49 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.1 Extended Update Support

Via RHSA-2020:5660 https://access.redhat.com/errata/RHSA-2020:5660

Comment 20 errata-xmlrpc 2020-12-22 09:24:45 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.0 Update Services for SAP Solutions

Via RHSA-2020:5663 https://access.redhat.com/errata/RHSA-2020:5663

Comment 21 errata-xmlrpc 2020-12-22 09:25:56 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.1 Extended Update Support

Via RHSA-2020:5665 https://access.redhat.com/errata/RHSA-2020:5665

Comment 22 errata-xmlrpc 2020-12-22 09:27:57 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.0 Update Services for SAP Solutions

Via RHSA-2020:5662 https://access.redhat.com/errata/RHSA-2020:5662