qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] file-posix: refuse to open directories
@ 2017-12-21 22:44 John Snow
  2017-12-21 22:56 ` no-reply
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Snow @ 2017-12-21 22:44 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, qemu-devel, dgilbert, mreitz, John Snow

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;
+    }
 
 #ifdef CONFIG_XFS
     if (platform_test_xfs_fd(s->fd)) {
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-01-15 13:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2017-12-22 13:00 ` Kevin Wolf
2018-01-12 23:30   ` John Snow
2018-01-15 13:23     ` Kevin Wolf

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).