From nobody Sat Apr 27 18:24:43 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 1496048877376734.9854119913913; Mon, 29 May 2017 02:07:57 -0700 (PDT) Received: from localhost ([::1]:47636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGeY-0002kY-Jf for importer@patchew.org; Mon, 29 May 2017 05:07:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcm-0001d6-Hw for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGci-0006AB-H6 for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:04 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54526 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGci-00069u-B4 for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:00 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94CCF047780 for ; Mon, 29 May 2017 05:05:59 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aqm8pxqcd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:05:58 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:05:56 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:05:53 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T95q5v30212184; Mon, 29 May 2017 09:05:53 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B03E611C054; Mon, 29 May 2017 10:04:09 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7E6C11C05E; Mon, 29 May 2017 10:04:09 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:09 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 869DD22016C; Mon, 29 May 2017 11:05:52 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:30 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0008-0000-0000-00000456D3B5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0009-0000-0000-00001DD7C54A Message-Id: <1496048740-26578-2-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=15 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 01/11] virtio-9p/xen-9p: move 9p specific bits to core 9p code 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" These bits aren't related to the transport so let's move them to the core code. Signed-off-by: Greg Kurz Reviewed-by: Stefano Stabellini --- hw/9pfs/9p.c | 8 +++++++- hw/9pfs/9p.h | 2 +- hw/9pfs/virtio-9p-device.c | 8 +------- hw/9pfs/xen-9p-backend.c | 6 +----- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index ab3e22f23130..b3048371a8ee 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3446,12 +3446,16 @@ static inline bool is_read_only_op(V9fsPDU *pdu) } } =20 -void pdu_submit(V9fsPDU *pdu) +void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr) { Coroutine *co; CoroutineEntry *handler; V9fsState *s =3D pdu->s; =20 + pdu->size =3D le32_to_cpu(hdr->size_le); + pdu->id =3D hdr->id; + pdu->tag =3D le16_to_cpu(hdr->tag_le); + if (pdu->id >=3D ARRAY_SIZE(pdu_co_handlers) || (pdu_co_handlers[pdu->id] =3D=3D NULL)) { handler =3D v9fs_op_not_supp; @@ -3462,6 +3466,8 @@ void pdu_submit(V9fsPDU *pdu) if (is_ro_export(&s->ctx) && !is_read_only_op(pdu)) { handler =3D v9fs_fs_ro; } + + qemu_co_queue_init(&pdu->complete); co =3D qemu_coroutine_create(handler, pdu); qemu_coroutine_enter(co); } diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 5312d8a42405..c886ba78d2ee 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -347,7 +347,7 @@ ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const = char *fmt, ...); ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...); V9fsPDU *pdu_alloc(V9fsState *s); void pdu_free(V9fsPDU *pdu); -void pdu_submit(V9fsPDU *pdu); +void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); void v9fs_reset(V9fsState *s); =20 struct V9fsTransport { diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 3782f437029b..245abd8aaef1 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -70,13 +70,7 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQue= ue *vq) goto out_free_req; } =20 - pdu->size =3D le32_to_cpu(out.size_le); - - pdu->id =3D out.id; - pdu->tag =3D le16_to_cpu(out.tag_le); - - qemu_co_queue_init(&pdu->complete); - pdu_submit(pdu); + pdu_submit(pdu, &out); } =20 return; diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index 5df97c90fae9..922cc967be63 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -243,14 +243,10 @@ static int xen_9pfs_receive(Xen9pfsRing *ring) =20 /* cannot fail, because we only handle one request per ring at a time = */ pdu =3D pdu_alloc(&ring->priv->state); - pdu->size =3D le32_to_cpu(h.size_le); - pdu->id =3D h.id; - pdu->tag =3D le32_to_cpu(h.tag_le); ring->out_size =3D le32_to_cpu(h.size_le); ring->out_cons =3D cons + le32_to_cpu(h.size_le); =20 - qemu_co_queue_init(&pdu->complete); - pdu_submit(pdu); + pdu_submit(pdu, &h); =20 return 0; } --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049135144571.5818519029965; Mon, 29 May 2017 02:12:15 -0700 (PDT) Received: from localhost ([::1]:47660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGij-0006Rx-Dx for importer@patchew.org; Mon, 29 May 2017 05:12:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcp-0001dU-8A for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcl-0006Av-93 for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55339) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGck-0006Aa-Vs for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:03 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94Eje109581 for ; Mon, 29 May 2017 05:06:01 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aqg1p4k6g-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:01 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:05:58 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:05:55 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T95t7035061908; Mon, 29 May 2017 09:05:55 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE11E4204D; Mon, 29 May 2017 10:03:58 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5BF84203F; Mon, 29 May 2017 10:03:58 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:03:58 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 5027422016C; Mon, 29 May 2017 11:05:54 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:31 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0012-0000-0000-0000053C0FF5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0013-0000-0000-000018A3EA97 Message-Id: <1496048740-26578-3-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 02/11] fsdev: don't allow unknown format in marshal/unmarshal 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The code only uses well known format strings. An unknown format token is a bug. Signed-off-by: Greg Kurz Reviewed-by: Stefano Stabellini --- fsdev/9p-iov-marshal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsdev/9p-iov-marshal.c b/fsdev/9p-iov-marshal.c index 1d16f8df4bd4..a1c9beddd2e7 100644 --- a/fsdev/9p-iov-marshal.c +++ b/fsdev/9p-iov-marshal.c @@ -168,7 +168,7 @@ ssize_t v9fs_iov_vunmarshal(struct iovec *out_sg, int o= ut_num, size_t offset, break; } default: - break; + g_assert_not_reached(); } if (copied < 0) { return copied; @@ -281,7 +281,7 @@ ssize_t v9fs_iov_vmarshal(struct iovec *in_sg, int in_n= um, size_t offset, break; } default: - break; + g_assert_not_reached(); } if (copied < 0) { return copied; --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049016987716.9232544211899; Mon, 29 May 2017 02:10:16 -0700 (PDT) Received: from localhost ([::1]:47647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGgo-0004nV-GZ for importer@patchew.org; Mon, 29 May 2017 05:10:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcn-0001d8-Kw for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcj-0006AS-Ln for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:05 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:44627 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcj-0006AH-GN for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:01 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94D3P051805 for ; Mon, 29 May 2017 05:06:01 -0400 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aqf9jnfnd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:00 -0400 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:05:59 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:05:57 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T95uLx15663506; Mon, 29 May 2017 09:05:56 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA685A404D; Mon, 29 May 2017 10:04:10 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B81A2A4040; Mon, 29 May 2017 10:04:10 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:10 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id B780022016C; Mon, 29 May 2017 11:05:55 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:32 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0020-0000-0000-00000376F8DB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0021-0000-0000-000041EAADB4 Message-Id: <1496048740-26578-4-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 03/11] 9pfs: drop pdu_push_and_notify() 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Only pdu_complete() needs to notify the client that a request has completed. Signed-off-by: Greg Kurz Reviewed-by: Stefano Stabellini --- hw/9pfs/9p.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b3048371a8ee..a25d31e62f1c 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -65,11 +65,6 @@ ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const= char *fmt, ...) return ret; } =20 -static void pdu_push_and_notify(V9fsPDU *pdu) -{ - pdu->s->transport->push_and_notify(pdu); -} - static int omode_to_uflags(int8_t mode) { int ret =3D 0; @@ -668,7 +663,7 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssi= ze_t len) pdu->size =3D len; pdu->id =3D id; =20 - pdu_push_and_notify(pdu); + pdu->s->transport->push_and_notify(pdu); =20 /* Now wakeup anybody waiting in flush for this request */ if (!qemu_co_queue_next(&pdu->complete)) { --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496048946762134.23440734489816; Mon, 29 May 2017 02:09:06 -0700 (PDT) Received: from localhost ([::1]:47641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGfh-0003ui-E6 for importer@patchew.org; Mon, 29 May 2017 05:09:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGct-0001gV-Kc for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGco-0006C0-0C for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54102) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcn-0006Bm-MR for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:05 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94Dpn010402 for ; Mon, 29 May 2017 05:06:04 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2arf3hc617-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:04 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:00 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:05:58 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T95vGe11272568; Mon, 29 May 2017 09:05:57 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D7154C044; Mon, 29 May 2017 10:04:25 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2BB884C046; Mon, 29 May 2017 10:04:25 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:25 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 0E34F22016C; Mon, 29 May 2017 11:05:56 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:33 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0012-0000-0000-0000053C0FFB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0013-0000-0000-000018A3EA9E Message-Id: <1496048740-26578-5-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 04/11] 9pfs: local: fix unlink of alien files in mapped-file mode 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When trying to remove a file from a directory, both created in non-mapped mode, the file remains and EBADF is returned to the guest. This is a regression introduced by commit "df4938a6651b 9pfs: local: unlinkat: don't follow symlinks" when fixing CVE-2016-9602. It changed the way we unlink the metadata file from ret =3D remove("$dir/.virtfs_metadata/$name"); if (ret < 0 && errno !=3D ENOENT) { /* Error out */ } /* Ignore absence of metadata */ to fd =3D openat("$dir/.virtfs_metadata") unlinkat(fd, "$name") if (ret < 0 && errno !=3D ENOENT) { /* Error out */ } /* Ignore absence of metadata */ If $dir was created in non-mapped mode, openat() fails with ENOENT and we pass -1 to unlinkat(), which fails in turn with EBADF. We just need to check the return of openat() and ignore ENOENT, in order to restore the behaviour we had with remove(). Signed-off-by: Greg Kurz Reviewed-by: Eric Blake [groug: rewrote the comments as suggested by Eric] --- hw/9pfs/9p-local.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index a2486566afb7..226234d38642 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -992,6 +992,14 @@ static int local_unlinkat_common(FsContext *ctx, int d= irfd, const char *name, if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { int map_dirfd; =20 + /* We need to remove the metadata as well: + * - the metadata directory if we're removing a directory + * - the metadata file in the parent's metadata directory + * + * If any of these are missing (ie, ENOENT) then we're probably + * trying to remove something that wasn't created in mapped-file + * mode. We just ignore the error. + */ if (flags =3D=3D AT_REMOVEDIR) { int fd; =20 @@ -999,32 +1007,20 @@ static int local_unlinkat_common(FsContext *ctx, int= dirfd, const char *name, if (fd =3D=3D -1) { goto err_out; } - /* - * If directory remove .virtfs_metadata contained in the - * directory - */ ret =3D unlinkat(fd, VIRTFS_META_DIR, AT_REMOVEDIR); close_preserve_errno(fd); if (ret < 0 && errno !=3D ENOENT) { - /* - * We didn't had the .virtfs_metadata file. May be file cr= eated - * in non-mapped mode ?. Ignore ENOENT. - */ goto err_out; } } - /* - * Now remove the name from parent directory - * .virtfs_metadata directory. - */ map_dirfd =3D openat_dir(dirfd, VIRTFS_META_DIR); - ret =3D unlinkat(map_dirfd, name, 0); - close_preserve_errno(map_dirfd); - if (ret < 0 && errno !=3D ENOENT) { - /* - * We didn't had the .virtfs_metadata file. May be file created - * in non-mapped mode ?. Ignore ENOENT. - */ + if (map_dirfd !=3D -1) { + ret =3D unlinkat(map_dirfd, name, 0); + close_preserve_errno(map_dirfd); + if (ret < 0 && errno !=3D ENOENT) { + goto err_out; + } + } else if (errno !=3D ENOENT) { goto err_out; } } --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496048882786294.87864385338185; Mon, 29 May 2017 02:08:02 -0700 (PDT) Received: from localhost ([::1]:47638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGee-0002pc-UK for importer@patchew.org; Mon, 29 May 2017 05:08:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcq-0001fK-IP for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcm-0006Ba-KO for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:08 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54353 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcm-0006BG-CO for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:04 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94D7t011501 for ; Mon, 29 May 2017 05:06:03 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2aqn3fwkuq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:03 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:01 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:05:59 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T95xZ536438166; Mon, 29 May 2017 09:05:59 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C46AAAE056; Mon, 29 May 2017 10:03:43 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1F11AE045; Mon, 29 May 2017 10:03:43 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:03:43 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 501F122016C; Mon, 29 May 2017 11:05:58 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:34 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-00000399C1EC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000258A9BF8 Message-Id: <1496048740-26578-6-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 05/11] fsdev: fix virtfs-proxy-helper cwd 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since chroot() doesn't change the current directory, it is indeed a good practice to chdir() to the target directory and then then chroot(), or to chroot() to the target directory and then chdir("/"). The current code does neither of them actually. Let's go for the latter. This doesn't fix any security issue since all of this takes place before the helper begins to process requests. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- fsdev/virtfs-proxy-helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 54f7ad1c48f0..4c4238f62e53 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -1129,14 +1129,14 @@ int main(int argc, char **argv) } } =20 - if (chdir("/") < 0) { - do_perror("chdir"); - goto error; - } if (chroot(rpath) < 0) { do_perror("chroot"); goto error; } + if (chdir("/") < 0) { + do_perror("chdir"); + goto error; + } =20 get_version =3D false; #ifdef FS_IOC_GETVERSION --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049243523629.5104946658972; Mon, 29 May 2017 02:14:03 -0700 (PDT) Received: from localhost ([::1]:47668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGkU-0008Cy-5F for importer@patchew.org; Mon, 29 May 2017 05:14:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGct-0001gW-Kg for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGco-0006CE-L1 for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:10 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37353) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGco-0006Br-Ab for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:06 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94H5L102873 for ; Mon, 29 May 2017 05:06:05 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2arfakbjx5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:04 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:02 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:00 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T9602t39452746; Mon, 29 May 2017 09:06:00 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3ABC11C058; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1E3211C052; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 9635422016C; Mon, 29 May 2017 11:05:59 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:35 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-000003B91265 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000204ABE7A Message-Id: <1496048740-26578-7-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 06/11] 9pfs: assume utimensat() and futimens() are present 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The utimensat() and futimens() syscalls have been around for ages (ie, glibc 2.6 and linux 2.6.22), and the decision was already taken to switch to utimensat() anyway when fixing CVE-2016-9602 in 2.9. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- fsdev/virtfs-proxy-helper.c | 3 ++- hw/9pfs/9p-handle.c | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index 4c4238f62e53..6c066ec9a0ce 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -945,7 +945,8 @@ static int process_requests(int sock) &spec[0].tv_sec, &spec[0].tv_nsec, &spec[1].tv_sec, &spec[1].tv_nsec); if (retval > 0) { - retval =3D qemu_utimens(path.data, spec); + retval =3D utimensat(AT_FDCWD, path.data, spec, + AT_SYMLINK_NOFOLLOW); if (retval < 0) { retval =3D -errno; } diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 1687661bc95a..9875f1894cc5 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -378,7 +378,6 @@ static int handle_utimensat(FsContext *ctx, V9fsPath *f= s_path, const struct timespec *buf) { int ret; -#ifdef CONFIG_UTIMENSAT int fd; struct handle_data *data =3D (struct handle_data *)ctx->private; =20 @@ -388,10 +387,6 @@ static int handle_utimensat(FsContext *ctx, V9fsPath *= fs_path, } ret =3D futimens(fd, buf); close(fd); -#else - ret =3D -1; - errno =3D ENOSYS; -#endif return ret; } =20 --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049392793314.27195628837023; Mon, 29 May 2017 02:16:32 -0700 (PDT) Received: from localhost ([::1]:47681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGmt-0001MJ-B1 for importer@patchew.org; Mon, 29 May 2017 05:16:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcv-0001hU-07 for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcq-0006EO-UV for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51718) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcq-0006Ca-Kh for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:08 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94E4o059698 for ; Mon, 29 May 2017 05:06:07 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2aqfqjwbwe-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:07 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:04 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:02 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T961bL37093512; Mon, 29 May 2017 09:06:01 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25929A4053; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1349EA4051; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:16 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 17BD122016C; Mon, 29 May 2017 11:06:01 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:36 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-00000399C1F9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000258A9C0A Message-Id: <1496048740-26578-8-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 07/11] util: drop old utimensat() compat code 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that 9pfs and virtfs-proxy-helper have been converted to utimensat(), we don't need to keep qemu_utimens() anymore. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- configure | 22 ---------------------- include/sysemu/os-posix.h | 11 ----------- util/oslib-posix.c | 47 -------------------------------------------= ---- 3 files changed, 80 deletions(-) diff --git a/configure b/configure index 1a5ee4b909b8..0586ec9c64de 100755 --- a/configure +++ b/configure @@ -3629,25 +3629,6 @@ if compile_prog "" "" ; then inotify1=3Dyes fi =20 -# check if utimensat and futimens are supported -utimens=3Dno -cat > $TMPC << EOF -#define _ATFILE_SOURCE -#include -#include -#include - -int main(void) -{ - utimensat(AT_FDCWD, "foo", NULL, 0); - futimens(0, NULL); - return 0; -} -EOF -if compile_prog "" "" ; then - utimens=3Dyes -fi - # check if pipe2 is there pipe2=3Dno cat > $TMPC << EOF @@ -5434,9 +5415,6 @@ fi if test "$curses" =3D "yes" ; then echo "CONFIG_CURSES=3Dy" >> $config_host_mak fi -if test "$utimens" =3D "yes" ; then - echo "CONFIG_UTIMENSAT=3Dy" >> $config_host_mak -fi if test "$pipe2" =3D "yes" ; then echo "CONFIG_PIPE2=3Dy" >> $config_host_mak fi diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h index 900bdcb45ad0..629c8c648b7a 100644 --- a/include/sysemu/os-posix.h +++ b/include/sysemu/os-posix.h @@ -51,17 +51,6 @@ int os_mlock(void); typedef struct timeval qemu_timeval; #define qemu_gettimeofday(tp) gettimeofday(tp, NULL) =20 -#ifndef CONFIG_UTIMENSAT -#ifndef UTIME_NOW -# define UTIME_NOW ((1l << 30) - 1l) -#endif -#ifndef UTIME_OMIT -# define UTIME_OMIT ((1l << 30) - 2l) -#endif -#endif -typedef struct timespec qemu_timespec; -int qemu_utimens(const char *path, const qemu_timespec *times); - bool is_daemonized(void); =20 /** diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 4d9189e9efcf..7e28c161b257 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -207,53 +207,6 @@ int qemu_pipe(int pipefd[2]) return ret; } =20 -int qemu_utimens(const char *path, const struct timespec *times) -{ - struct timeval tv[2], tv_now; - struct stat st; - int i; -#ifdef CONFIG_UTIMENSAT - int ret; - - ret =3D utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW); - if (ret !=3D -1 || errno !=3D ENOSYS) { - return ret; - } -#endif - /* Fallback: use utimes() instead of utimensat() */ - - /* happy if special cases */ - if (times[0].tv_nsec =3D=3D UTIME_OMIT && times[1].tv_nsec =3D=3D UTIM= E_OMIT) { - return 0; - } - if (times[0].tv_nsec =3D=3D UTIME_NOW && times[1].tv_nsec =3D=3D UTIME= _NOW) { - return utimes(path, NULL); - } - - /* prepare for hard cases */ - if (times[0].tv_nsec =3D=3D UTIME_NOW || times[1].tv_nsec =3D=3D UTIME= _NOW) { - gettimeofday(&tv_now, NULL); - } - if (times[0].tv_nsec =3D=3D UTIME_OMIT || times[1].tv_nsec =3D=3D UTIM= E_OMIT) { - stat(path, &st); - } - - for (i =3D 0; i < 2; i++) { - if (times[i].tv_nsec =3D=3D UTIME_NOW) { - tv[i].tv_sec =3D tv_now.tv_sec; - tv[i].tv_usec =3D tv_now.tv_usec; - } else if (times[i].tv_nsec =3D=3D UTIME_OMIT) { - tv[i].tv_sec =3D (i =3D=3D 0) ? st.st_atime : st.st_mtime; - tv[i].tv_usec =3D 0; - } else { - tv[i].tv_sec =3D times[i].tv_sec; - tv[i].tv_usec =3D times[i].tv_nsec / 1000; - } - } - - return utimes(path, &tv[0]); -} - char * qemu_get_local_state_pathname(const char *relative_pathname) { --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049022532589.9327567366092; Mon, 29 May 2017 02:10:22 -0700 (PDT) Received: from localhost ([::1]:47648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGgv-0004t1-4t for importer@patchew.org; Mon, 29 May 2017 05:10:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcw-0001id-Bq for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcs-0006F3-BC for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:14 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41508 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcs-0006Er-5x for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:10 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94D6X189269 for ; Mon, 29 May 2017 05:06:09 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 2arghb0m05-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:09 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:07 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:03 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T9635H36176086; Mon, 29 May 2017 09:06:03 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5750952041; Mon, 29 May 2017 09:03:02 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id 45C8C5204B; Mon, 29 May 2017 09:03:02 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 5479C22016C; Mon, 29 May 2017 11:06:02 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:37 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-00000399C1FA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000258A9C13 Message-Id: <1496048740-26578-9-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=13 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 08/11] 9pfs: check return value of v9fs_co_name_to_path() 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" These v9fs_co_name_to_path() call sites have always been around. I guess no care was taken to check the return value because the name_to_path operation could never fail at the time. This is no longer true: the handle and synth backends can already fail this operation, and so will the local backend soon. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- hw/9pfs/9p.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index a25d31e62f1c..96d268334865 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2571,7 +2571,10 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU= *pdu, V9fsFidState *fidp, err =3D -EINVAL; goto out; } - v9fs_co_name_to_path(pdu, &dirfidp->path, name->data, &new_path); + err =3D v9fs_co_name_to_path(pdu, &dirfidp->path, name->data, &new= _path); + if (err < 0) { + goto out; + } } else { old_name =3D fidp->path.data; end =3D strrchr(old_name, '/'); @@ -2583,8 +2586,11 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU= *pdu, V9fsFidState *fidp, new_name =3D g_malloc0(end - old_name + name->size + 1); strncat(new_name, old_name, end - old_name); strncat(new_name + (end - old_name), name->data, name->size); - v9fs_co_name_to_path(pdu, NULL, new_name, &new_path); + err =3D v9fs_co_name_to_path(pdu, NULL, new_name, &new_path); g_free(new_name); + if (err < 0) { + goto out; + } } err =3D v9fs_co_rename(pdu, &fidp->path, &new_path); if (err < 0) { @@ -2664,20 +2670,26 @@ out_nofid: v9fs_string_free(&name); } =20 -static void coroutine_fn v9fs_fix_fid_paths(V9fsPDU *pdu, V9fsPath *olddir, - V9fsString *old_name, - V9fsPath *newdir, - V9fsString *new_name) +static int coroutine_fn v9fs_fix_fid_paths(V9fsPDU *pdu, V9fsPath *olddir, + V9fsString *old_name, + V9fsPath *newdir, + V9fsString *new_name) { V9fsFidState *tfidp; V9fsPath oldpath, newpath; V9fsState *s =3D pdu->s; - + int err; =20 v9fs_path_init(&oldpath); v9fs_path_init(&newpath); - v9fs_co_name_to_path(pdu, olddir, old_name->data, &oldpath); - v9fs_co_name_to_path(pdu, newdir, new_name->data, &newpath); + err =3D v9fs_co_name_to_path(pdu, olddir, old_name->data, &oldpath); + if (err < 0) { + goto out; + } + err =3D v9fs_co_name_to_path(pdu, newdir, new_name->data, &newpath); + if (err < 0) { + goto out; + } =20 /* * Fixup fid's pointing to the old name to @@ -2689,8 +2701,10 @@ static void coroutine_fn v9fs_fix_fid_paths(V9fsPDU = *pdu, V9fsPath *olddir, v9fs_fix_path(&tfidp->path, &newpath, strlen(oldpath.data)); } } +out: v9fs_path_free(&oldpath); v9fs_path_free(&newpath); + return err; } =20 static int coroutine_fn v9fs_complete_renameat(V9fsPDU *pdu, int32_t olddi= rfid, @@ -2724,8 +2738,8 @@ static int coroutine_fn v9fs_complete_renameat(V9fsPD= U *pdu, int32_t olddirfid, } if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { /* Only for path based fid we need to do the below fixup */ - v9fs_fix_fid_paths(pdu, &olddirfidp->path, old_name, - &newdirfidp->path, new_name); + err =3D v9fs_fix_fid_paths(pdu, &olddirfidp->path, old_name, + &newdirfidp->path, new_name); } out: if (olddirfidp) { --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049320027309.34134594821035; Mon, 29 May 2017 02:15:20 -0700 (PDT) Received: from localhost ([::1]:47677 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGli-0000Yw-GO for importer@patchew.org; Mon, 29 May 2017 05:15:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcv-0001iB-VP for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcr-0006Ew-Vk for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:13 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54652 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcr-0006Ed-Qk for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:09 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94DDX011442 for ; Mon, 29 May 2017 05:06:09 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2aqn3fwkyf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:09 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:07 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:04 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T964DZ15466808; Mon, 29 May 2017 09:06:04 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC53111C05B; Mon, 29 May 2017 10:04:20 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B969611C052; Mon, 29 May 2017 10:04:20 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:20 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 9A63522016C; Mon, 29 May 2017 11:06:03 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:38 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-000003B9126B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000204ABE92 Message-Id: <1496048740-26578-10-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=13 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 09/11] 9pfs: local: resolve special directories in paths 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When using the mapped-file security mode, the creds of a path /foo/bar are stored in the /foo/.virtfs_metadata/bar file. This is okay for all paths unless they end with '.' or '..', because we cannot create the corresponding file in the metadata directory. This patch ensures that '.' and '..' are resolved in all paths. The core code only passes path elements (no '/') to the backend, with the notable exception of the '/' path, which refers to the virtfs root. This patch preserves the current behavior of converting it to '.' so that it can be passed to "*at()" syscalls ('/' would mean the host root). Signed-off-by: Greg Kurz Reviewed-by: Eric Blake --- hw/9pfs/9p-local.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 226234d38642..68e92652ed73 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1134,14 +1134,32 @@ static int local_name_to_path(FsContext *ctx, V9fsP= ath *dir_path, } =20 if (dir_path) { - v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); - } else if (strcmp(name, "/")) { - v9fs_path_sprintf(target, "%s", name); + if (!strcmp(name, ".")) { + /* "." relative to "foo/bar" is "foo/bar" */ + v9fs_path_copy(target, dir_path); + } else if (!strcmp(name, "..")) { + if (!strcmp(dir_path->data, ".")) { + /* ".." relative to the root is "." */ + v9fs_path_sprintf(target, "."); + } else { + char *tmp =3D g_path_get_dirname(dir_path->data); + /* Symbolic links are resolved by the client. We can assume + * that ".." relative to "foo/bar" is equivalent to "foo" + */ + v9fs_path_sprintf(target, "%s", tmp); + g_free(tmp); + } + } else { + assert(!strchr(name, '/')); + v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); + } + } else if (!strcmp(name, "/") || !strcmp(name, ".") || + !strcmp(name, "..")) { + /* This is the root fid */ + v9fs_path_sprintf(target, "."); } else { - /* We want the path of the export root to be relative, otherwise - * "*at()" syscalls would treat it as "/" in the host. - */ - v9fs_path_sprintf(target, "%s", "."); + assert(!strchr(name, '/')); + v9fs_path_sprintf(target, "./%s", name); } return 0; } --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049140118866.00748627238; Mon, 29 May 2017 02:12:20 -0700 (PDT) Received: from localhost ([::1]:47661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGio-0006V9-NR for importer@patchew.org; Mon, 29 May 2017 05:12:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGcz-0001jZ-2b for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcv-0006G6-3N for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37788) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcu-0006FX-Qp for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:13 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94Gu0102814 for ; Mon, 29 May 2017 05:06:11 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2arfakbk3t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:11 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:08 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:06 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T965cA35586202; Mon, 29 May 2017 09:06:05 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9C2CA4065; Mon, 29 May 2017 10:04:19 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0BE1A4059; Mon, 29 May 2017 10:04:19 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:19 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id D522B22016C; Mon, 29 May 2017 11:06:04 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:39 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0040-0000-0000-000003B91270 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0041-0000-0000-0000204ABE98 Message-Id: <1496048740-26578-11-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=13 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 10/11] 9pfs: local: simplify file opening 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The logic to open a path currently sits between local_open_nofollow() and the relative_openat_nofollow() helper, which has no other user. For the sake of clarity, this patch moves all the code of the helper into its unique caller. While here we also: - drop the code to skip leading "/" because the backend isn't supposed to pass anything but relative paths without consecutive slashes. The assert() is kept because we really don't want a buggy backend to pass an absolute path to openat(). - use strchrnul() to get a simpler code. This is ok since virtfs is for linux+glibc hosts only. - don't dup() the initial directory and add an assert() to ensure we don't return the global mountfd to the caller. BTW, this would mean that the caller passed an empty path, which isn't supposed to happen either. Signed-off-by: Greg Kurz Reviewed-by: Eric Blake [groug: fixed typos in changelog] --- hw/9pfs/9p-local.c | 34 +++++++++++++++++++++++++++++----- hw/9pfs/9p-util.c | 43 ------------------------------------------- hw/9pfs/9p-util.h | 2 -- 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 68e92652ed73..ddc5038cff39 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -53,13 +53,37 @@ int local_open_nofollow(FsContext *fs_ctx, const char *= path, int flags, mode_t mode) { LocalData *data =3D fs_ctx->private; - - /* All paths are relative to the path data->mountfd points to */ - while (*path =3D=3D '/') { - path++; + int fd =3D data->mountfd; + + while (*path && fd !=3D -1) { + const char *c; + int next_fd; + char *head; + + /* Only relative paths without consecutive slashes */ + assert(*path !=3D '/'); + + head =3D g_strdup(path); + c =3D strchrnul(path, '/'); + if (*c) { + /* Intermediate path element */ + head[c - path] =3D 0; + path =3D c + 1; + next_fd =3D openat_dir(fd, head); + } else { + /* Rightmost path element */ + next_fd =3D openat_file(fd, head, flags, mode); + path =3D c; + } + g_free(head); + if (fd !=3D data->mountfd) { + close_preserve_errno(fd); + } + fd =3D next_fd; } =20 - return relative_openat_nofollow(data->mountfd, path, flags, mode); + assert(fd !=3D data->mountfd); + return fd; } =20 int local_opendir_nofollow(FsContext *fs_ctx, const char *path) diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util.c index fdb4d5737635..f709c27a1fbd 100644 --- a/hw/9pfs/9p-util.c +++ b/hw/9pfs/9p-util.c @@ -14,49 +14,6 @@ #include "qemu/xattr.h" #include "9p-util.h" =20 -int relative_openat_nofollow(int dirfd, const char *path, int flags, - mode_t mode) -{ - int fd; - - fd =3D dup(dirfd); - if (fd =3D=3D -1) { - return -1; - } - - while (*path) { - const char *c; - int next_fd; - char *head; - - /* Only relative paths without consecutive slashes */ - assert(path[0] !=3D '/'); - - head =3D g_strdup(path); - c =3D strchr(path, '/'); - if (c) { - head[c - path] =3D 0; - next_fd =3D openat_dir(fd, head); - } else { - next_fd =3D openat_file(fd, head, flags, mode); - } - g_free(head); - if (next_fd =3D=3D -1) { - close_preserve_errno(fd); - return -1; - } - close(fd); - fd =3D next_fd; - - if (!c) { - break; - } - path =3D c + 1; - } - - return fd; -} - ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *= name, void *value, size_t size) { diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 517027c52032..91299a24b8af 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -50,8 +50,6 @@ static inline int openat_file(int dirfd, const char *name= , int flags, return fd; } =20 -int relative_openat_nofollow(int dirfd, const char *path, int flags, - mode_t mode); ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name, void *value, size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name, --=20 2.7.4 From nobody Sat Apr 27 18:24:43 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 1496049075802759.9011780844021; Mon, 29 May 2017 02:11:15 -0700 (PDT) Received: from localhost ([::1]:47656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGhm-0005cp-Cj for importer@patchew.org; Mon, 29 May 2017 05:11:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFGd0-0001ko-FN for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFGcw-0006GV-DB for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:18 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54625) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFGcw-0006GA-3u for qemu-devel@nongnu.org; Mon, 29 May 2017 05:06:14 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4T94CeT010298 for ; Mon, 29 May 2017 05:06:13 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2arf3hc69c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 May 2017 05:06:12 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 May 2017 10:06:09 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 29 May 2017 10:06:07 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4T966M114745772; Mon, 29 May 2017 09:06:06 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DBF84C04A; Mon, 29 May 2017 10:04:34 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 352B34C05E; Mon, 29 May 2017 10:04:34 +0100 (BST) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 29 May 2017 10:04:34 +0100 (BST) Received: from bahia.lan (icon-9-164-152-88.megacenter.de.ibm.com [9.164.152.88]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 17CC622016C; Mon, 29 May 2017 11:06:06 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Mon, 29 May 2017 11:05:40 +0200 X-Mailer: git-send-email 2.7.5 In-Reply-To: <1496048740-26578-1-git-send-email-groug@kaod.org> References: <1496048740-26578-1-git-send-email-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17052909-0012-0000-0000-0000053C1009 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17052909-0013-0000-0000-000018A3EAD1 Message-Id: <1496048740-26578-12-git-send-email-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-29_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=4 malwarescore=0 phishscore=0 adultscore=10 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705290171 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 11/11] 9pfs: local: metadata file for the VirtFS root 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: Peter Maydell , Greg Kurz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When using the mapped-file security, credentials are stored in a metadata directory located in the parent directory. This is okay for all paths with the notable exception of the root path, since we don't want and probably can't create a metadata directory above the virtfs directory on the host. This patch introduces a dedicated metadata file, sitting in the virtfs root for this purpose. It relies on the fact that the "." name necessarily refers to the virtfs root. As for the metadata directory, we don't want the client to see this file. The current code only cares for readdir() but there are many other places to fix actually. The filtering logic is hence put in a separate function. Before: # ls -ld drwxr-xr-x. 3 greg greg 4096 May 5 12:49 . # chown root.root . chown: changing ownership of '.': Is a directory # ls -ld drwxr-xr-x. 3 greg greg 4096 May 5 12:49 . After: # ls -ld drwxr-xr-x. 3 greg greg 4096 May 5 12:49 . # chown root.root . # ls -ld drwxr-xr-x. 3 root root 4096 May 5 12:50 . and from the host: ls -al .virtfs_metadata_root -rwx------. 1 greg greg 26 May 5 12:50 .virtfs_metadata_root $ cat .virtfs_metadata_root virtfs.uid=3D0 virtfs.gid=3D0 Reported-by: Leo Gaspard Signed-off-by: Greg Kurz Reviewed-by: Eric Blake Tested-by: Leo Gaspard --- hw/9pfs/9p-local.c | 81 ++++++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index ddc5038cff39..6442f642d326 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -107,6 +107,7 @@ static void unlinkat_preserve_errno(int dirfd, const ch= ar *path, int flags) } =20 #define VIRTFS_META_DIR ".virtfs_metadata" +#define VIRTFS_META_ROOT_FILE VIRTFS_META_DIR "_root" =20 static FILE *local_fopenat(int dirfd, const char *name, const char *mode) { @@ -143,13 +144,17 @@ static void local_mapped_file_attr(int dirfd, const c= har *name, char buf[ATTR_MAX]; int map_dirfd; =20 - map_dirfd =3D openat_dir(dirfd, VIRTFS_META_DIR); - if (map_dirfd =3D=3D -1) { - return; - } + if (strcmp(name, ".")) { + map_dirfd =3D openat_dir(dirfd, VIRTFS_META_DIR); + if (map_dirfd =3D=3D -1) { + return; + } =20 - fp =3D local_fopenat(map_dirfd, name, "r"); - close_preserve_errno(map_dirfd); + fp =3D local_fopenat(map_dirfd, name, "r"); + close_preserve_errno(map_dirfd); + } else { + fp =3D local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "r"); + } if (!fp) { return; } @@ -227,26 +232,38 @@ static int local_set_mapped_file_attrat(int dirfd, co= nst char *name, int ret; char buf[ATTR_MAX]; int uid =3D -1, gid =3D -1, mode =3D -1, rdev =3D -1; - int map_dirfd; - - ret =3D mkdirat(dirfd, VIRTFS_META_DIR, 0700); - if (ret < 0 && errno !=3D EEXIST) { - return -1; - } - - map_dirfd =3D openat_dir(dirfd, VIRTFS_META_DIR); - if (map_dirfd =3D=3D -1) { - return -1; - } + int map_dirfd, map_fd; + bool is_root =3D !strcmp(name, "."); + + if (is_root) { + fp =3D local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "r"); + if (!fp) { + if (errno =3D=3D ENOENT) { + goto update_map_file; + } else { + return -1; + } + } + } else { + ret =3D mkdirat(dirfd, VIRTFS_META_DIR, 0700); + if (ret < 0 && errno !=3D EEXIST) { + return -1; + } =20 - fp =3D local_fopenat(map_dirfd, name, "r"); - if (!fp) { - if (errno =3D=3D ENOENT) { - goto update_map_file; - } else { - close_preserve_errno(map_dirfd); + map_dirfd =3D openat_dir(dirfd, VIRTFS_META_DIR); + if (map_dirfd =3D=3D -1) { return -1; } + + fp =3D local_fopenat(map_dirfd, name, "r"); + if (!fp) { + if (errno =3D=3D ENOENT) { + goto update_map_file; + } else { + close_preserve_errno(map_dirfd); + return -1; + } + } } memset(buf, 0, ATTR_MAX); while (fgets(buf, ATTR_MAX, fp)) { @@ -264,12 +281,21 @@ static int local_set_mapped_file_attrat(int dirfd, co= nst char *name, fclose(fp); =20 update_map_file: - fp =3D local_fopenat(map_dirfd, name, "w"); - close_preserve_errno(map_dirfd); + if (is_root) { + fp =3D local_fopenat(dirfd, VIRTFS_META_ROOT_FILE, "w"); + } else { + fp =3D local_fopenat(map_dirfd, name, "w"); + close_preserve_errno(map_dirfd); + } if (!fp) { return -1; } =20 + map_fd =3D fileno(fp); + assert(map_fd !=3D -1); + ret =3D fchmod(map_fd, 0600); + assert(ret =3D=3D 0); + if (credp->fc_uid !=3D -1) { uid =3D credp->fc_uid; } @@ -478,7 +504,8 @@ static off_t local_telldir(FsContext *ctx, V9fsFidOpenS= tate *fs) =20 static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *n= ame) { - return !strcmp(name, VIRTFS_META_DIR); + return + !strcmp(name, VIRTFS_META_DIR) || !strcmp(name, VIRTFS_META_ROOT_F= ILE); } =20 static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) @@ -495,7 +522,7 @@ again: entry->d_type =3D DT_UNKNOWN; } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { if (local_is_mapped_file_metadata(ctx, entry->d_name)) { - /* skip the meta data directory */ + /* skip the meta data */ goto again; } entry->d_type =3D DT_UNKNOWN; --=20 2.7.4