Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xd0Ae-0001gZ-0j for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Oct 2014 17:09:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xd0Ad-0000FN-Gk for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Oct 2014 17:09:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xcz4x-0008Du-TV for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 15:59:35 +0000 Received: from smarthost01b.mail.zen.net.uk ([212.23.1.3]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xcz4u-0000L0-5n for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 15:59:34 +0000 Received: from [88.96.211.230] (helo=ash.forest) by smarthost01b.mail.zen.net.uk with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Xcz4t-000Fzm-JU; Sat, 11 Oct 2014 15:59:31 +0000 Received: from 88-96-211-230.dsl.zen.co.uk ([88.96.211.230] helo=[10.0.0.12]) by ash.forest with esmtpa (Exim 4.80) (envelope-from ) id 1Xcz4q-0005Ro-Qk; Sat, 11 Oct 2014 16:59:30 +0100 Message-ID: <543953E2.1080305@opalsoftware.co.uk> Date: Sat, 11 Oct 2014 16:59:30 +0100 From: Mark Simonetti User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: pgxml bug (crash) in xslt_proc.c References: <543920CE.9090505@opalsoftware.co.uk> <24870.1413041595@sss.pgh.pa.us> <5439523F.8030500@opalsoftware.co.uk> In-Reply-To: <5439523F.8030500@opalsoftware.co.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Spam-Report: Spam detection software, running on the system "ash.forest", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: PS, I forgot to mention that this is on a Windows system. I have not yet tried to repeat it on Linux but I can give it a try. Regards, Mark. -- On 11/10/2014 16:52, Mark Simonetti wrote: > Hi Tom, > I hadn't really thought of it as a security issue, it came about from > just trying to use it normally while developing software for one of my > clients. At first I found it hard to repeat, but I eventually found a > query to repeat the problem 100% of the time. Unfortunately the XML I > used to repeat it is vast and generated from lots of database data so > it would be hard to submit that as a test case (though I can if it > would help by capturing the XML data into a file and sending it along > with the XSLT file). It seems to be to do with the order in which > resources are freed: > > I changed this (xslt_proc.c, pgxml, postgres 9.3.5, line 167 onwards) : - > > xsltFreeStylesheet(stylesheet); > xmlFreeDoc(restree); > xmlFreeDoc(doctree); > xsltFreeSecurityPrefs(xslt_sec_prefs); > xsltFreeTransformContext(xslt_ctxt); <== crash here > > To this: > > xsltFreeTransformContext(xslt_ctxt); > xsltFreeSecurityPrefs(xslt_sec_prefs); > xsltFreeStylesheet(stylesheet); > xmlFreeDoc(restree); > xmlFreeDoc(doctree); > > No more crash. > > The offending part seemed to be freeing the transform "xslt_ctxt" > context before freeing the doc "doctree". Indeed if I check the XSLT > example with the XSLT distribution > (http://xmlsoft.org/libxslt/downloads.html) they do free the transform > context first. > > I'm guessing that when the transform context is freed, it is trying to > free something related to the previously already freed document. > > I also switched the order in the "catch" segment just above (line 147 > onwards). > > Regards, > Mark. > -- > > On 11/10/2014 16:33, Tom Lane wrote: >> Mark Simonetti writes: >>> I think I've found a bug in xslt_proc.c in the pgxml contrib module >>> that >>> I've also fixed. It is a serious bug as it crashes the entire database >>> backend. Do I just describe it here, or is there somewhere else to >>> report that, or is there a way for me to submit the actual bug fix? >> If you want you can report it to [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.0 TVD_RCVD_IP TVD_RCVD_IP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Originating-smarthost01b-IP: [88.96.211.230] X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org PS, I forgot to mention that this is on a Windows system. I have not yet tried to repeat it on Linux but I can give it a try. Regards, Mark. -- On 11/10/2014 16:52, Mark Simonetti wrote: > Hi Tom, > I hadn't really thought of it as a security issue, it came about from > just trying to use it normally while developing software for one of my > clients. At first I found it hard to repeat, but I eventually found a > query to repeat the problem 100% of the time. Unfortunately the XML I > used to repeat it is vast and generated from lots of database data so > it would be hard to submit that as a test case (though I can if it > would help by capturing the XML data into a file and sending it along > with the XSLT file). It seems to be to do with the order in which > resources are freed: > > I changed this (xslt_proc.c, pgxml, postgres 9.3.5, line 167 onwards) : - > > xsltFreeStylesheet(stylesheet); > xmlFreeDoc(restree); > xmlFreeDoc(doctree); > xsltFreeSecurityPrefs(xslt_sec_prefs); > xsltFreeTransformContext(xslt_ctxt); <== crash here > > To this: > > xsltFreeTransformContext(xslt_ctxt); > xsltFreeSecurityPrefs(xslt_sec_prefs); > xsltFreeStylesheet(stylesheet); > xmlFreeDoc(restree); > xmlFreeDoc(doctree); > > No more crash. > > The offending part seemed to be freeing the transform "xslt_ctxt" > context before freeing the doc "doctree". Indeed if I check the XSLT > example with the XSLT distribution > (http://xmlsoft.org/libxslt/downloads.html) they do free the transform > context first. > > I'm guessing that when the transform context is freed, it is trying to > free something related to the previously already freed document. > > I also switched the order in the "catch" segment just above (line 147 > onwards). > > Regards, > Mark. > -- > > On 11/10/2014 16:33, Tom Lane wrote: >> Mark Simonetti writes: >>> I think I've found a bug in xslt_proc.c in the pgxml contrib module >>> that >>> I've also fixed. It is a serious bug as it crashes the entire database >>> backend. Do I just describe it here, or is there somewhere else to >>> report that, or is there a way for me to submit the actual bug fix? >> If you want you can report it to pgsql-security at postgresql.org >> instead of the regular bugs list. We'd probably only treat it as >> a security issue if the bug seems exploitable for more than a mere >> crash (eg, if it could lead to privilege escalation or arbitrary >> code execution). If you're not sure about the possible consequences >> probably best to let the -security list see it first. >> >> Whichever way you report it, please include your proposed fix along >> with the bug report. >> >> regards, tom lane > -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs