Bug 1797450 (CVE-2019-14493)

Summary: CVE-2019-14493 opencv: NULL pointer dereference in function cv::XMLParser::parse() in persistence_xml.cpp leading to DoS
Product: [Other] Security Response Reporter: Dhananjay Arunesh <darunesh>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED NOTABUG QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: andrew, databases-maint, hhorak, jkucera, jmlich83, jridky, karlthered, kwizart, pkajaba, rakesh.pandit, sergio, viktor.vix.jancik
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: opencv 4.1.1 Doc Type: If docs needed, set a value
Doc Text:
A NULL pointer dereference flaw was found in OpenCV in the way the Cascade Classifier algorithm loaded and processed certain classifiers. A remote attacker could exploit this flaw by providing a specially crafted XML file that, when loaded by an application linked to OpenCV, would crash the application causing a denial of service.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-02-13 20:09:44 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: 1797451    
Bug Blocks: 1797452    

Description Dhananjay Arunesh 2020-02-03 08:12:01 UTC
An issue was discovered in OpenCV before 4.1.1. There is a NULL pointer dereference in the function cv::XMLParser::parse at modules/core/src/persistence.cpp.

Reference:
https://github.com/opencv/opencv/compare/371bba8...ddbd10c
https://github.com/opencv/opencv/issues/15127

Comment 1 Dhananjay Arunesh 2020-02-03 08:12:55 UTC
Created opencv tracking bugs for this issue:

Affects: fedora-all [bug 1797451]

Comment 2 Mauro Matteo Cascella 2020-02-12 14:03:18 UTC
Upstream fix:
https://github.com/opencv/opencv/commit/5691d998ead1d9b0542bcfced36c2dceb3a59023

Comment 3 Mauro Matteo Cascella 2020-02-12 17:00:52 UTC
The flaw lies in the implementation of Cascade Classifier, an algorithm used internally by OpenCV to detect objects in digital images. It is a machine learning based algorithm where a classifier is trained from a lot of "positive" and "negative" images, and then used to detect objects in other images. 

Specifically, the NULL pointer dereference can be triggered when the classifier (in the form of a XML file) is loaded and parsed by the cv::CascadeClassifier::load() function.

Comment 4 Mauro Matteo Cascella 2020-02-13 15:33:31 UTC
This flaw was apparently introduced in OpenCV upstream version 4.0.0 with commit https://github.com/opencv/opencv/commit/0f622206e48f6050536f00d47abf47c4a2d1824a.

This commit replaced function icvXMLSkipSpaces() with skipSpaces() in persistence_xml.cpp; the new implementation made it possible for skipSpaces() to return a NULL pointer: https://github.com/opencv/opencv/commit/0f622206e48f6050536f00d47abf47c4a2d1824a#diff-c9729b5bab1646d0cf30a15a7de41fd5R416.
 
Conversely, the older implementation took care of re-initializing the NULL pointer before returning it: https://github.com/opencv/opencv/commit/0f622206e48f6050536f00d47abf47c4a2d1824a#diff-c9729b5bab1646d0cf30a15a7de41fd5L81.

Comment 6 Mauro Matteo Cascella 2020-02-13 15:42:11 UTC
Statement:

This flaw did not affect the versions of OpenCV as shipped with Red Hat Enterprise Linux 6, 7, and 8 as they did not include the vulnerable code, which was introduced in a newer version of the library.

Comment 7 Product Security DevOps Team 2020-02-13 20:09:44 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-2019-14493

Comment 8 Mauro Matteo Cascella 2020-04-15 15:09:18 UTC
Mitigation:

Avoid loading cascade classifiers from external untrusted sources.