From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zrq1S-0000Oa-IS for qemu-devel@nongnu.org; Thu, 29 Oct 2015 12:25:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zrq1P-0007r3-5z for qemu-devel@nongnu.org; Thu, 29 Oct 2015 12:25:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49693) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zrq1O-0007qi-Qn for qemu-devel@nongnu.org; Thu, 29 Oct 2015 12:25:51 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 5B3F4AAA for ; Thu, 29 Oct 2015 16:25:50 +0000 (UTC) References: <1446122683-2355-1-git-send-email-armbru@redhat.com> <1446122683-2355-3-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <5632488D.8040109@redhat.com> Date: Thu, 29 Oct 2015 10:25:49 -0600 MIME-Version: 1.0 In-Reply-To: <1446122683-2355-3-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pdgjdtKOd0uv3qfgjCasu7ROprOHnwAXj" Subject: Re: [Qemu-devel] [PATCH 2/4] json-streamer: Don't crash when input exceeds nesting limit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --pdgjdtKOd0uv3qfgjCasu7ROprOHnwAXj Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/29/2015 06:44 AM, Markus Armbruster wrote: > We limit nesting depth and input size to defend against input > triggering excessive heap or stack memory use (commit 29c75dd > json-streamer: limit the maximum recursion depth and maximum token > count). However, when the nesting limit is exceeded, > parser_context_peek_token()'s assertion fails. >=20 > Broken in commit 65c0f1e "json-parser: don't replicate tokens at each > level of recursion". >=20 > To reproduce stuff 1025 open braces or brackets into QMP. >=20 > Fix by taking the error exit instead of the normal one. >=20 > Reported-by: Eric Blake > Signed-off-by: Markus Armbruster > --- > qobject/json-streamer.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Eric Blake However, a couple comments about the context: > if (type =3D=3D JSON_ERROR) { > goto out_emit_bad; > } else if (parser->brace_count < 0 || > parser->bracket_count < 0 || > (parser->brace_count =3D=3D 0 && > parser->bracket_count =3D=3D 0)) { > goto out_emit; Should we go to out_emit_bad for brace_count/bracket_count < 0, and save out_emit only for the case where brace =3D=3D bracket =3D=3D 0? Can we e= ven trigger negative counts (probably by attempting unpaired "{]]", but will that trigger earlier errors?) > } else if (parser->token_size > MAX_TOKEN_SIZE || > parser->bracket_count > MAX_NESTING || > parser->brace_count > MAX_NESTING) { > /* Security consideration, we limit total memory allocated per object > * and the maximum recursion depth that a message can force. > */ > goto out_emit; > } > > return; > >out_emit_bad: > /* clear out token list and tell the parser to emit and error Typo: s/and error/an error/ --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --pdgjdtKOd0uv3qfgjCasu7ROprOHnwAXj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWMkiNAAoJEKeha0olJ0NqxPUH/0MICxkXZ5L+DZ/YJ3LRNGhh G7POUfPnImLmQELR08881ZiTiNkPiS3f/cQgDTSZn6jd0kquGHKkTSMWt1rVKQF1 WlryDyyEhtK0Wibl4i/Qv4yuZXWvsglyjmwkdKHca+nNtv4pPjNQ+KgXCPVrYGpk ySLWsVeYinU6XQGM2g4rPTeUnujiGUNPiBZdWohNCpQqn1FYdsYFibsxh7NqmOz5 mkSux0hieffxqpUetmJcCE7O8nxdmI5sNfEqgv3XWh5ilZ2ouPPmUQSiupQj5PYt SGGd96Pn8Tw6BjMVZgIQfQVGN6B4VMj1tfFyz9R0ESsKOmriAsTo3bcl/crZ+zo= =jfNQ -----END PGP SIGNATURE----- --pdgjdtKOd0uv3qfgjCasu7ROprOHnwAXj--