Skip to contentSkip to conversation

QMP accepts double dict keys

Qemu-devel Max Reitz 5 participants 6 messages Dec 3, 2018 – Dec 5, 2018

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

Hi,

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

$ qemu-system-x86_64 -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 3},
"package": "v3.1.0-rc3-7-g87a45d86ed"}, "capabilities": []}}
{'execute':'qmp_capabilities'}
{"return": {}}
{'execute':'blockdev-add','arguments':{'driver':'null-co',
 'node-name':'foo','node-name':'bar'}}
{"return": {}}
{'execute':'query-named-block-nodes'}
{"return": [{ [...] "node-name": "bar" [...] }]}

Another test case is iotest 229 which specifies both mode=absolute-paths and mode=existing (it wants the latter).

Max

#1 lore raw
Quoted 4 lines · Max Reitz

Hi,

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

JSON says it is undefined what happens when a client passes double keys.
We are probably best off if we teach our parser to be strict and
reject doubled keys in QMP as invalid.

Hmm - can a client abuse QMP with duplicate keys to cause qemu to leak memory?

Quoted 17 lines
$ qemu-system-x86_64 -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 3},
"package": "v3.1.0-rc3-7-g87a45d86ed"}, "capabilities": []}}
{'execute':'qmp_capabilities'}
{"return": {}}
{'execute':'blockdev-add','arguments':{'driver':'null-co',
  'node-name':'foo','node-name':'bar'}}
{"return": {}}
{'execute':'query-named-block-nodes'}
{"return": [{ [...] "node-name": "bar" [...] }]}

Another test case is iotest 229 which specifies both mode=absolute-paths and mode=existing (it wants the latter).

Max

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 9 lines · Eric Blake
Quoted 4 lines · Max Reitz

Hi,

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

JSON says it is undefined what happens when a client passes double keys. We are probably best off if we teach our parser to be strict and reject doubled keys in QMP as invalid.

Not bug-compatible. Do we care?

Quoted 2 lines

Hmm - can a client abuse QMP with duplicate keys to cause qemu to leak memory?

No. parse_pair() inserts with qdict_put_obj(), which replaces the old value without leaking it.

Quoted 17 lines
Quoted 17 lines
$ qemu-system-x86_64 -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 3},
"package": "v3.1.0-rc3-7-g87a45d86ed"}, "capabilities": []}}
{'execute':'qmp_capabilities'}
{"return": {}}
{'execute':'blockdev-add','arguments':{'driver':'null-co',
  'node-name':'foo','node-name':'bar'}}
{"return": {}}
{'execute':'query-named-block-nodes'}
{"return": [{ [...] "node-name": "bar" [...] }]}

Another test case is iotest 229 which specifies both mode=absolute-paths and mode=existing (it wants the latter).

Max

#3 lore raw
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Eric Blake
Quoted 2 lines · Max Reitz

Hi,

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

JSON says it is undefined what happens when a client passes double keys. We are probably best off if we teach our parser to be strict and reject doubled keys in QMP as invalid.

Not bug-compatible. Do we care?

I don't think so. Such a client was already invoking undefined behavior. Relying on first- or last-past-the-post to win is not portable, since JSON parsers are allowed to use hash tables with non-deterministic lookups. I think erroring out is nicer than silently accepting one thing, especially if that might have been different than what the client (incorrectly) expected. I'm not even sure that we would want a deprecation period.

Quoted 6 lines
Quoted 3 lines

Hmm - can a client abuse QMP with duplicate keys to cause qemu to leak memory?

No. parse_pair() inserts with qdict_put_obj(), which replaces the old value without leaking it.

Good to know.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Another test case is iotest 229 which specifies both mode=absolute-paths and mode=existing (it wants the latter).

We'll have to fix such broken clients, of course. If it is just our iotests (and not libvirt), I'm less worried about the change in behavior.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
Quoted 13 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Eric Blake
Quoted 4 lines · Max Reitz

Hi,

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

JSON says it is undefined what happens when a client passes double keys. We are probably best off if we teach our parser to be strict and reject doubled keys in QMP as invalid.

Quoted 8 lines
Quoted 1 line

Not bug-compatible. Do we care?

I don't think so. Such a client was already invoking undefined behavior. Relying on first- or last-past-the-post to win is not portable, since JSON parsers are allowed to use hash tables with non-deterministic lookups. I think erroring out is nicer than silently accepting one thing, especially if that might have been different than what the client (incorrectly) expected. I'm not even sure that we would want a deprecation period.

Erroring out immediately, without any deprecation period sounds fine to me, as this is simply a bug fix.

IMHO the ABI/API compatibility stability only applies to things that are intended behaviour / correct usage.

Regards,
Daniel

Signature · 3 lines
|: 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 :|
#5 lore raw
In reply to Eric Blake
Quoted 13 lines · * Eric Blake ([email protected]) wrote:
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Eric Blake
Quoted 4 lines · Max Reitz

Hi,

QMP accepts double keys in dicts without complaining. The value it is using is apparently the last one specified:

JSON says it is undefined what happens when a client passes double keys. We are probably best off if we teach our parser to be strict and reject doubled keys in QMP as invalid.

Quoted 8 lines
Quoted 1 line

Not bug-compatible. Do we care?

I don't think so. Such a client was already invoking undefined behavior. Relying on first- or last-past-the-post to win is not portable, since JSON parsers are allowed to use hash tables with non-deterministic lookups. I think erroring out is nicer than silently accepting one thing, especially if that might have been different than what the client (incorrectly) expected. I'm not even sure that we would want a deprecation period.

Agreed, because it's the type of thing that ends up being potentially dangerous, since if you had some form of security check that was looking at QMP messages it might check one version of the field and not the other.

Dave

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Hmm - can a client abuse QMP with duplicate keys to cause qemu to leak memory?

No. parse_pair() inserts with qdict_put_obj(), which replaces the old value without leaking it.

Quoted 14 lines

Good to know.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Another test case is iotest 229 which specifies both mode=absolute-paths and mode=existing (it wants the latter).

We'll have to fix such broken clients, of course. If it is just our iotests (and not libvirt), I'm less worried about the change in behavior.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK