From nobody Wed Nov 5 07:57:50 2025 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.zohomail.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 1504509981988845.3910813940474; Mon, 4 Sep 2017 00:26:21 -0700 (PDT) Received: from localhost ([::1]:39261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dolm0-0000Ha-Ux for importer@patchew.org; Mon, 04 Sep 2017 03:26:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dolkv-00089n-3J for qemu-devel@nongnu.org; Mon, 04 Sep 2017 03:25:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dolkr-0001SZ-R5 for qemu-devel@nongnu.org; Mon, 04 Sep 2017 03:25:13 -0400 Received: from 2.mo178.mail-out.ovh.net ([46.105.39.61]:48657) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dolkr-0001JZ-Kw for qemu-devel@nongnu.org; Mon, 04 Sep 2017 03:25:09 -0400 Received: from player728.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo178.mail-out.ovh.net (Postfix) with ESMTP id 15461517A5 for ; Mon, 4 Sep 2017 09:25:01 +0200 (CEST) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player728.ha.ovh.net (Postfix) with ESMTPA id C60E35400A6; Mon, 4 Sep 2017 09:24:59 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 04 Sep 2017 09:24:53 +0200 Message-ID: <150450989314.1143.5582306195355968158.stgit@bahia.lan> User-Agent: StGit/0.17.1-46-g6855-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 18432107375561644425 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelledrvdehgdejhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.39.61 Subject: [Qemu-devel] [PATCH] 9pfs: local: clarify fchmodat_nofollow() implementation 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Since fchmodat(2) on Linux doesn't support AT_SYMLINK_NOFOLLOW, we have to implement it using workarounds. There are two different ways, depending on whether the system supports O_PATH or not. In the case O_PATH is supported, we rely on the behavhior of openat(2) when passing O_NOFOLLOW | O_PATH and the file is a symbolic link. Even if openat_file() already adds O_NOFOLLOW to the flags, this patch makes it explicit that we need both creation flags to obtain the expected behavior. This is only cleanup, no functional change. Signed-off-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/9pfs/9p-local.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index efb0b79a74bf..e51af87309c6 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -349,11 +349,11 @@ static int fchmodat_nofollow(int dirfd, const char *n= ame, mode_t mode) return -1; } =20 - /* Access modes are ignored when O_PATH is supported. We try O_RDONLY = and - * O_WRONLY for old-systems that don't support O_PATH. - */ - fd =3D openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL, 0); + fd =3D openat_file(dirfd, name, O_RDONLY | O_PATH_9P_UTIL | O_NOFOLLOW= , 0); #if O_PATH_9P_UTIL =3D=3D 0 + /* Fallback for systems that don't support O_PATH: we depend on the fi= le + * being readable or writable. + */ if (fd =3D=3D -1) { /* In case the file is writable-only and isn't a directory. */ if (errno =3D=3D EACCES) { @@ -368,6 +368,10 @@ static int fchmodat_nofollow(int dirfd, const char *na= me, mode_t mode) } ret =3D fchmod(fd, mode); #else + /* Access modes are ignored when O_PATH is supported. If name is a sym= bolic + * link, O_PATH | O_NOFOLLOW causes openat(2) to return a file descrip= tor + * referring to the symbolic link. + */ if (fd =3D=3D -1) { return -1; }