From nobody Thu May 2 17:58:37 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513896362495748.3760639295793; Thu, 21 Dec 2017 14:46:02 -0800 (PST) Received: from localhost ([::1]:45343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS9ap-0005tN-RX for importer@patchew.org; Thu, 21 Dec 2017 17:45:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS9Zc-0005DQ-Uy for qemu-devel@nongnu.org; Thu, 21 Dec 2017 17:44:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eS9Zb-0004kb-VZ for qemu-devel@nongnu.org; Thu, 21 Dec 2017 17:44:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eS9ZX-0004fu-CX; Thu, 21 Dec 2017 17:44:15 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A57EC04B928; Thu, 21 Dec 2017 22:44:14 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-231.bos.redhat.com [10.18.17.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3565600D1; Thu, 21 Dec 2017 22:44:11 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org Date: Thu, 21 Dec 2017 17:44:11 -0500 Message-Id: <20171221224411.8901-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 21 Dec 2017 22:44:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] file-posix: refuse to open directories X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, mreitz@redhat.com, John Snow , qemu-devel@nongnu.org, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Daniel P. Berrange Reviewed-by: Eric Blake --- 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 =3D true; } #endif + if (S_ISDIR(st.st_mode)) { + ret =3D -EISDIR; + error_setg_errno(errp, errno, "Cannot open directory as file"); + goto fail; + } =20 #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) { --=20 2.14.3