From nobody Tue May 7 11:21:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148878902485315.527758575445205; Mon, 6 Mar 2017 00:30:24 -0800 (PST) Received: from localhost ([::1]:42388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cko2B-0001Mm-Mx for importer@patchew.org; Mon, 06 Mar 2017 03:30:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cko1X-0001LT-8d for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cko1U-0006JH-3x for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:43 -0500 Received: from 18.mo1.mail-out.ovh.net ([46.105.35.72]:34083) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cko1T-0006J8-Tn for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:40 -0500 Received: from player756.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id 81E4C5C3D7 for ; Mon, 6 Mar 2017 09:29:37 +0100 (CET) Received: from [192.168.66.23] (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player756.ha.ovh.net (Postfix) with ESMTPA id 41D9E4200AF; Mon, 6 Mar 2017 09:29:33 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 06 Mar 2017 09:29:32 +0100 Message-ID: <148878897279.4635.8320563171450519845.stgit@bahia> In-Reply-To: <148878895545.4635.12311472774377490920.stgit@bahia> References: <148878895545.4635.12311472774377490920.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 2157505699061864811 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrfeelgdekgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.35.72 Subject: [Qemu-devel] [PATCH v2 1/2] 9pfs: fix O_PATH build break with older glibc versions 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: Mark Cave-Ayland , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When O_PATH is used with O_DIRECTORY, it only acts as an optimization: the openat() syscall simply finds the name in the VFS, and doesn't trigger the underlying filesystem. On systems that don't define O_PATH, because they have glibc version 2.13 or older for example, we can safely omit it. We don't want to deactivate O_PATH globally though, in case it is used without O_DIRECTORY. The is done with a dedicated macro. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- hw/9pfs/9p-util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 091f3ce88e15..cb7b2072d3ac 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -22,7 +22,12 @@ static inline void close_preserve_errno(int fd) =20 static inline int openat_dir(int dirfd, const char *name) { - return openat(dirfd, name, O_DIRECTORY | O_RDONLY | O_PATH); +#ifdef O_PATH +#define OPENAT_DIR_O_PATH O_PATH +#else +#define OPENAT_DIR_O_PATH 0 +#endif + return openat(dirfd, name, O_DIRECTORY | O_RDONLY | OPENAT_DIR_O_PATH); } =20 static inline int openat_file(int dirfd, const char *name, int flags, From nobody Tue May 7 11:21:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488789101803940.85384349347; Mon, 6 Mar 2017 00:31:41 -0800 (PST) Received: from localhost ([::1]:42396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cko3Q-0002M5-0C for importer@patchew.org; Mon, 06 Mar 2017 03:31:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cko1h-0001SO-Hb for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cko1e-0006Ls-CQ for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:53 -0500 Received: from 15.mo1.mail-out.ovh.net ([188.165.38.232]:46500) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cko1e-0006LV-5R for qemu-devel@nongnu.org; Mon, 06 Mar 2017 03:29:50 -0500 Received: from player756.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo1.mail-out.ovh.net (Postfix) with ESMTP id C856E5C3DA for ; Mon, 6 Mar 2017 09:29:47 +0100 (CET) Received: from [192.168.66.23] (huguette.tetaneutral.net [91.224.149.27]) (Authenticated sender: groug@kaod.org) by player756.ha.ovh.net (Postfix) with ESMTPA id EB6C24200B1; Mon, 6 Mar 2017 09:29:42 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 06 Mar 2017 09:29:42 +0100 Message-ID: <148878898250.4635.16941960568938577780.stgit@bahia> In-Reply-To: <148878895545.4635.12311472774377490920.stgit@bahia> References: <148878895545.4635.12311472774377490920.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 2160320450083985771 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrfeelgdekgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 188.165.38.232 Subject: [Qemu-devel] [PATCH v2 2/2] 9pfs: fix vulnerability in openat_dir() and local_unlinkat_common() 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: Mark Cave-Ayland , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 We should pass O_NOFOLLOW otherwise openat() will follow symlinks and make QEMU vulnerable. While here, we also fix local_unlinkat_common() to use openat_dir() for the same reasons (it was a leftover in the original patchset actually). This fixes CVE-2016-9602. Signed-off-by: Greg Kurz Reviewed-by: Daniel P. Berrange -- v2: - keep O_PATH (Eric Blake) Reviewed-by: Eric Blake --- hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p-util.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 0ca4c94ee4a8..45e9a1f9b0ca 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -960,7 +960,7 @@ static int local_unlinkat_common(FsContext *ctx, int di= rfd, const char *name, if (flags =3D=3D AT_REMOVEDIR) { int fd; =20 - fd =3D openat(dirfd, name, O_RDONLY | O_DIRECTORY | O_PATH); + fd =3D openat_dir(dirfd, name); if (fd =3D=3D -1) { goto err_out; } diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index cb7b2072d3ac..517027c52032 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -27,7 +27,8 @@ static inline int openat_dir(int dirfd, const char *name) #else #define OPENAT_DIR_O_PATH 0 #endif - return openat(dirfd, name, O_DIRECTORY | O_RDONLY | OPENAT_DIR_O_PATH); + return openat(dirfd, name, + O_DIRECTORY | O_RDONLY | O_NOFOLLOW | OPENAT_DIR_O_PATH); } =20 static inline int openat_file(int dirfd, const char *name, int flags,