RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1276036 - Crash on QMP input exceeding limits
Summary: Crash on QMP input exceeding limits
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: qemu-kvm
Version: 7.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Markus Armbruster
QA Contact: CongLi
URL:
Whiteboard:
Depends On: 1276032
Blocks: 1288337
TreeView+ depends on / blocked
 
Reported: 2015-10-28 13:17 UTC by Markus Armbruster
Modified: 2016-11-03 20:06 UTC (History)
9 users (show)

Fixed In Version: qemu-kvm-1.5.3-121.el7
Doc Type: Bug Fix
Doc Text:
Clone Of: 1276032
Environment:
Last Closed: 2016-11-03 20:06:54 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2585 0 normal SHIPPED_LIVE Moderate: qemu-kvm security, bug fix, and enhancement update 2016-11-03 12:09:03 UTC

Description Markus Armbruster 2015-10-28 13:17:33 UTC
+++ This bug was initially created as a clone of Bug #1276032 +++

Description of problem:
The QMP parser attempts to limit nesting depth and input size to
defend against input triggering excessive heap or stack memory use.
However, it crashes when the nesting depth limit is exceeded.  I
suspect it also crashes when the input size is exceeded, but haven't
actually tested.

This is a regression since RHEL-6.

How reproducible:
Always

Steps to Reproduce:
1. Run with a QMP monitor, e.g.
   $ qemu-kvm -nodefaults -S -display none -qmp stdio
2. Input at least 1025 left braces

Actual results:
ERROR:/home/armbru/work/qemu-kvm-rhev7/qobject/json-parser.c:295:parser_context_peek_token: assertion failed: (ctxt->tokens.pos < ctxt->tokens.count)
Aborted (core dumped)

Expected results:
Same behavior as in RHEL-6, i.e.
{"error": {"class": "JSONParsing", "desc": "Invalid JSON syntax", "data": {}}}

Additional info:
It's really the 1025-th left brace.  1024 left braces followed by 1024
right braces doesn't crash.

Broken upstream in commit 65c0f1e "json-parser: don't replicate tokens
at each level of recursion", v1.2.0.

Comment 2 Markus Armbruster 2015-11-20 07:30:15 UTC
Proposed upstream fix:
http://lists.gnu.org/archive/html/qemu-devel/2015-11/msg04518.html

Related bug: the parser is a ridiculous memory hog.  If we get that fixed upstream together with this bug, I'll widen this bug's scope to cover it.  If not, I'll file a new one.

Comment 3 Markus Armbruster 2015-11-30 08:29:40 UTC
Both the crash and the excessive memory use have been fixed upstream:
df64983 qjson: Limit number of tokens in addition to total size
9bada89 qjson: surprise, allocating 6 QObjects per token is expensive
95385fe qjson: store tokens in a GQueue
d538b25 qjson: Convert to parser to recursive descent
d2ca7c0 qjson: replace QString in JSONLexer with GString
6b9606f qjson: Inline token_is_escape() and simplify
50e2a46 qjson: Inline token_is_keyword() and simplify
c546166 qjson: Give each of the six structural chars its own token type
b8d3b1d qjson: Spell out some silent assumptions
f0ae030 check-qjson: Add test for JSON nesting depth limit
0753113 qjson: Don't crash when input exceeds nesting limit
4f2d31f qjson: Apply nesting limit more sanely

Comment 4 Miroslav Rezanina 2016-08-02 09:11:42 UTC
Fix included in qemu-kvm-1.5.3-121.el7

Comment 6 CongLi 2016-08-10 07:48:23 UTC
Reproduce this bug on:
qemu-kvm-1.5.3-105.el7.x86_64

Steps:
1. Run qemu with a qmp monitor. 
# /usr/libexec/qemu-kvm -nodefaults -S -display none -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 3, "minor": 5, "major": 1}, "package": " (qemu-kvm-1.5.3-105.el7)"}, "capabilities": []}}

2. Input 1025 left braces.
{{{{{{{{{{{{{...

Results:
Qemu aborted with following error.
**
ERROR:qobject/json-parser.c:295:parser_context_peek_token: assertion failed: (ctxt->tokens.pos < ctxt->tokens.count)
Aborted


Verify this bug on:
qemu-kvm-1.5.3-121.el7.x86_64

Steps:
1. Run qemu with a qmp monitor.
# /usr/libexec/qemu-kvm -nodefaults -S -display none -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 3, "minor": 5, "major": 1}, "package": " (qemu-kvm-1.5.3-121.el7)"}, "capabilities": []}}

2. Input 1025 left braces.
{{{{{{{{{{{{{...

Results:
1. qemu not aborted and there is error in qmp.
{"error": {"class": "GenericError", "desc": "Invalid JSON syntax"}}
2. qemu not crash with 1025 left braces and 1024 right braces,
   got same error as above.


Please be free to correct if there is any problem.

Thanks.

Comment 9 errata-xmlrpc 2016-11-03 20:06:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-2585.html


Note You need to log in before you can comment on or make changes to this bug.