qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [Qemu-devel] [PATCH] file-posix: refuse to open directo


From: Eric Blake
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH] file-posix: refuse to open directories
Date: Thu, 21 Dec 2017 17:30:56 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 12/21/2017 04:44 PM, 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 <address@hidden>
---
  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;
+    }

Reviewed-by: Eric Blake <address@hidden>

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]