qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Greg Kurz <groug@kaod.org>, qemu-devel@nongnu.org
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 1/7] 9pfs: restrict open to regular files and directories
Date: Tue, 10 Jan 2017 08:38:27 -0600	[thread overview]
Message-ID: <b227e7dc-ba0b-7da7-8fdb-dece1cbe51d4@redhat.com> (raw)
In-Reply-To: <148405873540.9522.2224634666374633695.stgit@bahia.lab.toulouse-stg.fr.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 1545 bytes --]

On 01/10/2017 08:32 AM, Greg Kurz wrote:
> It really does not make sense for the 9P server to open anything else but
> a regular file or a directory.
> 
> Malicious code in a guest could for example create a named pipe, associate
> it to a valid fid and pass it to the server in a RLOPEN message. This would
> cause QEMU to hang in open(), waiting for someone to open the other end of
> the pipe.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---
>  hw/9pfs/9p.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index fa58877570f6..edd7b97270e3 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1462,7 +1462,7 @@ static void coroutine_fn v9fs_open(void *opaque)
>              goto out;
>          }
>          err += offset;
> -    } else {
> +    } else if (S_ISREG(stbuf.st_mode)) {
>          if (s->proto_version == V9FS_PROTO_2000L) {

TOCTTOU race.  You are checking the stat() results and only then calling
open(), rather than calling open() first and validating fstat().  That
means the guest can STILL cause you to open() a pipe by changing the
file type in between the stat and the open.

I think you need to rework this patch to open() first, then validate
(closing the fd if necessary); the open can be done with O_NONBLOCK to
avoid hanging on a pipe.  Yes, that's more annoying, but that's life
with TOCTTOU races.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2017-01-10 14:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 14:32 [Qemu-devel] [PATCH 0/7] fix potential hangs in 9pfs Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 1/7] 9pfs: restrict open to regular files and directories Greg Kurz
2017-01-10 14:38   ` Eric Blake [this message]
2017-01-10 14:41     ` Eric Blake
2017-01-11  9:54     ` Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 2/7] tests: virtio-9p: improve error reporting Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 3/7] tests: virtio-9p: add LOPEN operation test Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 4/7] tests: virtio-9p: TLOPEN should fail to open a FIFO Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 5/7] 9pfs: don't create files if pathname already exists Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 6/7] tests: virtio-9p: add LCREATE operation test Greg Kurz
2017-01-10 14:32 ` [Qemu-devel] [PATCH 7/7] tests: virtio-9p: TLCREATE should fail if pathname exists Greg Kurz

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=b227e7dc-ba0b-7da7-8fdb-dece1cbe51d4@redhat.com \
    --to=eblake@redhat.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=groug@kaod.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).