]> git.ipfire.org Git - thirdparty/libvirt.git/commit
rpc: for messages with FDs always decode count of FDs from the message
authorPavel Hrdina <phrdina@redhat.com>
Tue, 26 Sep 2017 14:47:20 +0000 (16:47 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 27 Sep 2017 16:56:32 +0000 (18:56 +0200)
commit5c52aed174b386f897fce870b2453e6cee5ebbc3
tree76f9e5ce9dc9a30c0c9faec23bbec74416e2da46
parent3685e2dd64f8565d739953bde871860f343436e4
rpc: for messages with FDs always decode count of FDs from the message

The packet with passed FD has the following format:

    --------------------------
    | len | header | payload |
    --------------------------

where "payload" has an additional count of FDs before the actual data:

    ------------------
    | nfds | payload |
    ------------------

When the packet is received we parse the "header", which as a side
effect updates msg->bufferOffset to point to the beginning of "payload".
If the message call contains FDs, we need to also parse the count of
FDs, which also updates the msg->bufferOffset.

The issue here is that when we attempt to read the FDs data from the
socket and we receive EAGAIN we finish the reading and call poll()
to wait for the data the we need.  When the data arrives we already have
the packet in our buffer so we read the "header" again but this time
we don't read the count of FDs because we already have it stored.

That means that the msg->bufferOffset is not updated to point to the
actual beginning of the payload data, but it points to the count of
FDs.  After all FDs are processed we dispatch the message to process
it and decode the payload.  Since the msg->bufferOffset points to wrong
data, we decode the wrong payload and the API call fails with
error messages:

    Domain not found: no domain with matching uuid '67656e65-7269-6300-0c87-5003ca6941f2' ()

Broken by commit 133c511b527 which fixed a FD and memory leak.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/rpc/virnetclient.c
src/rpc/virnetmessage.c
src/rpc/virnetserverclient.c