From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: John Snow <jsnow@redhat.com>, Eric Blake <eblake@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>,
Peter Maydell <peter.maydell@linaro.org>
Subject: Re: Maximum QMP reply size
Date: Mon, 26 Sep 2022 09:08:03 +0100 [thread overview]
Message-ID: <YzFd44GS6Ad0DNis@redhat.com> (raw)
In-Reply-To: <87v8pzwgbm.fsf@pond.sub.org>
On Wed, Sep 07, 2022 at 01:54:05PM +0200, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
> > Hi, I suspect I have asked this before, but I didn't write it down in
> > a comment, so I forget my justification...
> >
> > In the QMP lib, we need to set a buffering limit for how big a QMP
> > message can be -- In practice, I found that the largest possible
> > response was the QAPI schema reply, and I set the code to this:
> >
> > # Maximum allowable size of read buffer
> > _limit = (64 * 1024)
> >
> > However, I didn't document if this was a reasonable limit or just a
> > "worksforme" one. I assume that there's no hard limit for the protocol
> > or the implementation thereof in QEMU. Is there any kind of value here
> > that would be more sensible than another?
> >
> > I'm worried that if replies get bigger in the future (possibly in some
> > degenerate case I am presently unaware of) that the library default
> > will become nonsensical.
> >
> > Any pointers/tips?
>
> Peter and Daniel already provided some. I can add a bit of insight into
> how QMP output works in QEMU, which may or may not help you.
>
> QEMU executes one command after the other. A command's response
> (success or failure) is a QDict. Which is then formatted as JSON and
> appended to the monitor's output buffer.
>
> Events work similarly.
>
> The conversion to JSON does not limit the resulting string's size. If
> it runs out of memory, QEMU dies.
>
> The output buffer is also unbounded. It drains into the monitor's
> character device.
>
> If the QMP client sends enough commands without reading their responses,
> QEMU can run out of memory and die.
>
> Now I'm ready to go back to your question, which is about a *single*
> message (QMP command response or event): nothing in QEMU limits the size
> of the QMP output message text.
>
> Weak consolation: I guess QEMU is somewhat likely to run out of memory
> and die before your client software does. That's because QDict is a
> pig: an empty one eats 4120 Bytes on my system. Compares unfavourable
> to its text representation "{}".
A malicious QEMU that's trying to attack the mgmt software client
wouldn't need to use QDict, so that's only consolation against
accidents. An evil QEMU would just write JSON directly onto the
monitor chardev. It wouldn't even have to be well formed JSON,
as it could just start a string and never end it.
{"blah..repeated for 1 TB for data...."
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2022-09-26 8:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 19:38 Maximum QMP reply size John Snow
2022-09-06 20:29 ` Peter Maydell
2022-09-15 15:21 ` Dr. David Alan Gilbert
2022-09-16 15:12 ` Peter Maydell
2022-09-16 15:36 ` Daniel P. Berrangé
2022-09-19 6:45 ` Markus Armbruster
2022-09-20 8:14 ` Daniel P. Berrangé
2022-09-20 15:52 ` Dr. David Alan Gilbert
2022-09-07 7:16 ` Daniel P. Berrangé
2022-09-07 7:57 ` Daniel P. Berrangé
2022-09-07 11:54 ` Markus Armbruster
2022-09-23 19:51 ` John Snow
2022-09-26 8:17 ` Daniel P. Berrangé
2022-09-26 8:08 ` Daniel P. Berrangé [this message]
2022-09-26 10:43 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YzFd44GS6Ad0DNis@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).