From: "Michael S. Tsirkin" <mst@redhat.com>
To: Tetsuya Mukawa <mukawa@igel.co.jp>
Cc: jasowang@redhat.com, n.nikolaev@virtualopensystems.com,
qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 3/5] vhost-user: Shutdown vhost-user connection when wrong messages are passed
Date: Mon, 22 Jun 2015 09:54:15 +0200 [thread overview]
Message-ID: <20150622095122-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1434945048-27958-4-git-send-email-mukawa@igel.co.jp>
On Mon, Jun 22, 2015 at 12:50:46PM +0900, Tetsuya Mukawa wrote:
> When wrong vhost-user message are passed, the connection should be shutdown.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
This silently changes the protocol semantics: previously
unknown messages were ignored. We can't do this.
See email titled "vhost-user: protocol extensions" which relies on this
to detect protocol version.
> ---
> hw/virtio/vhost-user.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index d6f2163..2215c39 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -183,6 +183,7 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg,
> static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
> void *arg)
> {
> + CharDriverState *chr = dev->opaque;
> VhostUserMsg msg;
> VhostUserRequest msg_request;
> struct vhost_vring_file *file = 0;
> @@ -242,7 +243,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
> if (!fd_num) {
> error_report("Failed initializing vhost-user memory map, "
> "consider using -object memory-backend-file share=on");
> - return -1;
> + goto close;
> }
>
> msg.size = sizeof(m.memory.nregions);
> @@ -289,7 +290,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
> break;
> default:
> error_report("vhost-user trying to send unhandled ioctl");
> - return -1;
> + goto close;
> break;
> }
>
> @@ -305,33 +306,36 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
> if (msg_request != msg.request) {
> error_report("Received unexpected msg type."
> " Expected %d received %d", msg_request, msg.request);
> - return -1;
> + goto close;
> }
>
> switch (msg_request) {
> case VHOST_USER_GET_FEATURES:
> if (msg.size != sizeof(m.u64)) {
> error_report("Received bad msg size.");
> - return -1;
> + goto close;
> }
> *((__u64 *) arg) = msg.u64;
> break;
> case VHOST_USER_GET_VRING_BASE:
> if (msg.size != sizeof(m.state)) {
> error_report("Received bad msg size.");
> - return -1;
> + goto close;
> }
> msg.state.index -= dev->vq_index;
> memcpy(arg, &msg.state, sizeof(struct vhost_vring_state));
> break;
> default:
> error_report("Received unexpected msg type.");
> - return -1;
> - break;
> + goto close;
> }
> }
>
> return 0;
> +
> +close:
> + qemu_chr_disconnect(chr);
> + return -1;
> }
>
> static int vhost_user_init(struct vhost_dev *dev, void *opaque)
> --
> 2.1.4
next prev parent reply other threads:[~2015-06-22 7:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-22 3:50 [Qemu-devel] [PATCH v2 0/5] Add feature to start QEMU without vhost-user backend Tetsuya Mukawa
2015-06-22 3:50 ` [Qemu-devel] [PATCH v2 1/5] vhost-user: Add ability to know vhost-user backend disconnection Tetsuya Mukawa
2015-06-22 3:50 ` [Qemu-devel] [PATCH v2 2/5] qemu-char: Add qemu_chr_disconnect to close a fd accepted by listen fd Tetsuya Mukawa
2015-06-22 3:50 ` [Qemu-devel] [PATCH v2 3/5] vhost-user: Shutdown vhost-user connection when wrong messages are passed Tetsuya Mukawa
2015-06-22 7:54 ` Michael S. Tsirkin [this message]
2015-06-23 8:33 ` Tetsuya Mukawa
2015-08-06 17:29 ` Marc-André Lureau
2015-06-22 3:50 ` [Qemu-devel] [PATCH v2 4/5] vhost-user: Enable 'nowait' and 'reconnect' option Tetsuya Mukawa
2015-08-06 17:41 ` Marc-André Lureau
2015-06-22 3:50 ` [Qemu-devel] [PATCH v2 5/5] vhost-user: Add new option to specify vhost-user backend supports Tetsuya Mukawa
2015-08-06 19:11 ` Marc-André Lureau
2015-06-22 8:14 ` [Qemu-devel] [PATCH v2 0/5] Add feature to start QEMU without vhost-user backend Michael S. Tsirkin
2015-06-23 8:31 ` Tetsuya Mukawa
2015-06-23 9:41 ` Michael S. Tsirkin
2015-06-24 5:46 ` Tetsuya Mukawa
2015-06-24 5:57 ` Michael S. Tsirkin
2015-06-24 7:13 ` Tetsuya Mukawa
2015-07-19 12:48 ` Michael S. Tsirkin
2015-07-22 2:44 ` Tetsuya Mukawa
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=20150622095122-mutt-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=jasowang@redhat.com \
--cc=mukawa@igel.co.jp \
--cc=n.nikolaev@virtualopensystems.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).