qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-block@nongnu.org, kwolf@redhat.com, mreitz@redhat.com,
	qemu-devel@nongnu.org, dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH] file-posix: refuse to open directories
Date: Fri, 22 Dec 2017 09:26:25 +0000	[thread overview]
Message-ID: <20171222092625.GG30605@redhat.com> (raw)
In-Reply-To: <20171221224411.8901-1-jsnow@redhat.com>

On Thu, Dec 21, 2017 at 05:44:11PM -0500, John Snow wrote:
> I don't think there's a legitimate reason to open directories as if
> they were files. This prevents QEMU from opening and attempting to probe
> a directory inode, which can break in exciting ways. One of those ways
> is lseek on ext4/xfs, which will return 0x7fffffffffffffff as the file
> size instead of EISDIR. This can coax QEMU into responding with a
> confusing "file too big" instead of "Hey, that's not a file".
> 
> See: https://bugs.launchpad.net/qemu/+bug/1739304/
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  block/file-posix.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 36ee89e940..bd29bdada6 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -589,6 +589,11 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
>          s->needs_alignment = true;
>      }
>  #endif
> +    if (S_ISDIR(st.st_mode)) {
> +        ret = -EISDIR;
> +        error_setg_errno(errp, errno, "Cannot open directory as file");
> +        goto fail;
> +    }

Should we also do the same for S_ISCHR & S_ISFIFO, because neither of
them allow seeking, which IIUC would prevent usage in the file driver
for random I/O.  It would be fine todo that in a followup patch though,
so from this patch pov

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>


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 :|

  parent reply	other threads:[~2017-12-22  9:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 22:44 [Qemu-devel] [PATCH] file-posix: refuse to open directories John Snow
2017-12-21 22:56 ` no-reply
2017-12-21 23:00   ` John Snow
2017-12-21 23:30 ` Eric Blake
2017-12-22  9:26 ` Daniel P. Berrange [this message]
2017-12-22 13:00 ` Kevin Wolf
2018-01-12 23:30   ` John Snow
2018-01-15 13:23     ` Kevin Wolf

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=20171222092625.GG30605@redhat.com \
    --to=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.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).