Blame SOURCES/libxml2-2.9.7-CVE-2021-3541.patch

6ce3da
From 8598060bacada41a0eb09d95c97744ff4e428f8e Mon Sep 17 00:00:00 2001
6ce3da
From: Daniel Veillard <veillard@redhat.com>
6ce3da
Date: Thu, 13 May 2021 14:55:12 +0200
6ce3da
Subject: [PATCH] Patch for security issue CVE-2021-3541
6ce3da
6ce3da
This is relapted to parameter entities expansion and following
6ce3da
the line of the billion laugh attack. Somehow in that path the
6ce3da
counting of parameters was missed and the normal algorithm based
6ce3da
on entities "density" was useless.
6ce3da
---
6ce3da
 parser.c | 26 ++++++++++++++++++++++++++
6ce3da
 1 file changed, 26 insertions(+)
6ce3da
6ce3da
diff --git a/parser.c b/parser.c
6ce3da
index f5e5e169..c9312fa4 100644
6ce3da
--- a/parser.c
6ce3da
+++ b/parser.c
6ce3da
@@ -140,6 +140,7 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
6ce3da
                      xmlEntityPtr ent, size_t replacement)
6ce3da
 {
6ce3da
     size_t consumed = 0;
6ce3da
+    int i;
6ce3da
 
6ce3da
     if ((ctxt == NULL) || (ctxt->options & XML_PARSE_HUGE))
6ce3da
         return (0);
6ce3da
@@ -177,6 +178,28 @@ xmlParserEntityCheck(xmlParserCtxtPtr ctxt, size_t size,
6ce3da
 	    rep = NULL;
6ce3da
 	}
6ce3da
     }
6ce3da
+
6ce3da
+    /*
6ce3da
+     * Prevent entity exponential check, not just replacement while
6ce3da
+     * parsing the DTD
6ce3da
+     * The check is potentially costly so do that only once in a thousand
6ce3da
+     */
6ce3da
+    if ((ctxt->instate == XML_PARSER_DTD) && (ctxt->nbentities > 10000) &&
6ce3da
+        (ctxt->nbentities % 1024 == 0)) {
6ce3da
+	for (i = 0;i < ctxt->inputNr;i++) {
6ce3da
+	    consumed += ctxt->inputTab[i]->consumed +
6ce3da
+	               (ctxt->inputTab[i]->cur - ctxt->inputTab[i]->base);
6ce3da
+	}
6ce3da
+	if (ctxt->nbentities > consumed * XML_PARSER_NON_LINEAR) {
6ce3da
+	    xmlFatalErr(ctxt, XML_ERR_ENTITY_LOOP, NULL);
6ce3da
+	    ctxt->instate = XML_PARSER_EOF;
6ce3da
+	    return (1);
6ce3da
+	}
6ce3da
+	consumed = 0;
6ce3da
+    }
6ce3da
+
6ce3da
+
6ce3da
+
6ce3da
     if (replacement != 0) {
6ce3da
 	if (replacement < XML_MAX_TEXT_LENGTH)
6ce3da
 	    return(0);
6ce3da
@@ -7963,6 +7986,9 @@ xmlParsePEReference(xmlParserCtxtPtr ctxt)
6ce3da
             xmlChar start[4];
6ce3da
             xmlCharEncoding enc;
6ce3da
 
6ce3da
+	    if (xmlParserEntityCheck(ctxt, 0, entity, 0))
6ce3da
+	        return;
6ce3da
+
6ce3da
 	    if ((entity->etype == XML_EXTERNAL_PARAMETER_ENTITY) &&
6ce3da
 	        ((ctxt->options & XML_PARSE_NOENT) == 0) &&
6ce3da
 		((ctxt->options & XML_PARSE_DTDVALID) == 0) &&
6ce3da
-- 
6ce3da
GitLab
6ce3da