From nobody Sun Jul 26 12:38:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1781711093; cv=none; d=zohomail.com; s=zohoarc; b=XyTMh0eGLE+yqVYTMU3Y306ekiPyX7Q62LpC+W99ZwlSH1ceTwnl2OOkRLQiHHsn1fg60GHUGX5TPIsGvmD4NWgHbCKQvsdgrEioiLuhhNnll3obDCQchDjTwYO5LoSkkGnxQQjoO5kCAztU7hfwNNlURn+yWgeF6rFndgVGm7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781711093; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OaQCMTHN5Q1bX2MsH9spPLL7wft92aNI47qi3ILU7yo=; b=NY4xWcz+wzin5U7YZ8VfsdJyq8qlHdkwuuQs/L/RYQknezKudgYbgvWDquz9swTa/0XN9+zE3RRO02NJKiQiowUthlnatG6CZA0KRus6+Dp18/dVvlaTBqyLP4vNEXfxlgppZ/DhSfEMRWa6Y4T011DuVofleKR7HBoNe5Gbiek= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781711093412153.38717420109492; Wed, 17 Jun 2026 08:44:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZsQY-0003mL-NH; Wed, 17 Jun 2026 11:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <7f5445e7e4050cc117ed4b137bb7dd1474e49d57@kylie.crudebyte.com>) id 1wZsQW-0003kr-LC; Wed, 17 Jun 2026 11:43:40 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <7f5445e7e4050cc117ed4b137bb7dd1474e49d57@kylie.crudebyte.com>) id 1wZsQV-0002IX-8o; Wed, 17 Jun 2026 11:43:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=OaQCMTHN5Q1bX2MsH9spPLL7wft92aNI47qi3ILU7yo=; b=XBFzt /A8cApMNd9XAQEo10DQ5YGfXGK/IKCrxkJGpvWNzE2q2lmZ8yj563llEA5xdbP/nEIAMd/bSD9Aei b+1I5ochUf4VP5cQy8q62lW5+Zz1sFZrR68XHrlr25HZGapiaYtjdYwSmFWx7OBzXjF1pjpacN4H7 QQKdPhmRYEHfoKantWFg1c453KnyHW2jSp+UZuVsd8tMhLnvE5B/HD+ocV41GVEh+1avomJX2cu5F 7Iiy2DLpjIDsGkBEu7Mi0DB5Hpd95yKQAzE2nqZgXMTMv23XBUy5N/4bN2bYHQyLeqCS+bk1q3Qle KhvN7kZixaY2vGHP4p68pKTMjUI4MOF9BWEz3xWS5qcw3pWlp3cjXEfasm9vgvt9SVKk+rdNVzuXJ YW/45eg3Q3CkEmmY3fXkfCZxTT9OPDxhEghDxaRucq5uv/uzoadR+G9XDVo5q2PB5hriY4Ma6powj JdBPWm/02ZIciqcsHhDBJ0Pv8QwfQ9wDZurhNV8BHkS9AoiuvQHE769nZ7YcSoBQRhJpp2Ks4Dg5Y B4ImtVk0arBNzGsF8tcgKhx8sKcDgzio7rrc4yN1dhT1aCJmIPTH6KQLqs1kqlGSzHJttdYbsYo7h y2DA+ilZ0DSFdBlc35mRpb1eJrZ6pCz/n77gWU1MPa3xpjhYYDhwjJha/CYyTY=; Message-ID: <7f5445e7e4050cc117ed4b137bb7dd1474e49d57.1781710785.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 17 Jun 2026 17:39:46 +0200 Subject: [PULL 1/3] hw/9pfs: fix abort due to illegal name with Twstat rename To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Greg Kurz , Peter Maydell , Feifan Qian Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=5.189.157.229; envelope-from=7f5445e7e4050cc117ed4b137bb7dd1474e49d57@kylie.crudebyte.com; helo=kylie.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1781711095807158501 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The legacy Twstat 9p request can be used to rename files and directories. Unlike the other, more recent rename requests like Trename and Trenameat, Twstat does not validate the submitted new name before passing it to v9fs_complete_rename(). A priviliged guest user with direct communication access to 9p server could pass a string containing '/' as new name, which causes an assertion fault (DoS) in local_name_to_path(). Fix this by rejecting such strings by checking the client supplied new name with name_is_illegal(), similar to how Trename and Trenameat handlers do already. Reported-by: Feifan Qian Fixes: 8cf89e007a ("virtio-9p: Add P9_TWSTAT support") Link: https://lore.kernel.org/qemu-devel/ba09716828e82992f9d8cac7f00eee0bc1= c43c61.1780072238.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b4314d2549..f84698bfcc 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3638,6 +3638,11 @@ static void coroutine_fn v9fs_wstat(void *opaque) err =3D -EOPNOTSUPP; goto out; } + if (name_is_illegal(v9stat.name.data)) { + err =3D -ENOENT; + goto out; + } + v9fs_path_write_lock(s); err =3D v9fs_complete_rename(pdu, fidp, -1, &v9stat.name); v9fs_path_unlock(s); --=20 2.47.3 From nobody Sun Jul 26 12:38:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1781711093; cv=none; d=zohomail.com; s=zohoarc; b=OrJm5+sy1IHG/DA0L6yAuVh3WLzS3dNfzgtQ/x9iRaN5bsQAsy+oAYiEa52OM9y7CALygPWktQK9dz9BU9aJz5gbGzgSutIC2WmhH7MBb4xgq69SUTug2tr4Kq0NBobQvlImJiN6AsEx/GyeJ0phhDw0dV1/eTieq1+8i3gqVSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781711093; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3BZ27s7P7Q8df9ELxbX/Yz9rKy7ELrktCVvJzz21ZN8=; b=FWk1L2pS7po5Mx8J3vrPfiGL3MUs1nMXbbmwZz98d/hODmZEkBdPA0cNv8C2mpNYJCo9ctKW3lI/4cA/pzjON5ma8uf+3iGRfxQ15uCuICn9sbF3s2X8IaV8/b7409EQWPpz78QC20kIzGLbmZCRDbbPM7Tfc3/kUJKVz+1pYrk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178171109350079.93000851995032; Wed, 17 Jun 2026 08:44:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZsQg-0003rY-Og; Wed, 17 Jun 2026 11:43:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <08750e31fcdccf5352dc3b44475ed5ba6bc80221@kylie.crudebyte.com>) id 1wZsQc-0003qm-Vr; Wed, 17 Jun 2026 11:43:47 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <08750e31fcdccf5352dc3b44475ed5ba6bc80221@kylie.crudebyte.com>) id 1wZsQb-0002JY-FQ; Wed, 17 Jun 2026 11:43:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=3BZ27s7P7Q8df9ELxbX/Yz9rKy7ELrktCVvJzz21ZN8=; b=b3kCz fOBRepmQZMOsTafCPx1GswCGc6Lz1uiQm4VY2df4oKMynlb6KFOV93TqkTc9EqyLoTOaHU74MXpnz Ar5DkPoVvjqkSapCJt2LoZFxgfc7qSDWSiHX7+0edUfZpVU0rYKBR7noM98U3PbfXBWpBChwb2foW I3FoD7FreGQtR9846yHaOVGxfgro9mM191GnSlrj79ed7GrhSPN1GksNWCS6QGmogMS3MTRUYtP29 mRkd2b3TZakOhxrd2hpyJ4PVh8KU2HI1uKoMmiqTOubY8CxS5ezKakW5sdg0o/LAVDqM5qsHoq05c S7Lsr7VFCKIhQDLskmOTOIRqldd4BSu1EAu8nrmEkTy69AOxv6S8UQKMzEct+Ps5aZSAUw31a8ur3 wHAoDtRtVhAupaIc71MzSEC+/akGbYcPd27DEyXZ8ItTGY6Dahw4f+HNcHNok3KRlK63pPJ4aIu5D +SW0NhpBPbfajh54qa1Pt3tlq7whteceE7dGXTGALvcoWwEfPL5DYhEsVXg+Y3z9IGWDKp2bMjRtT 4PkKGqBoJk/dPaWBgkbHk2/MynBcVf5oKSJkjaDrypCEm4jJcfn23SjdtY3Mk2ucFbPg88bptiKGh sFZwr71rxdFBQGk5xbpPQNp1JAZiW74Don87euq80NHILC9RBcYa2puT3nBGzM=; Message-ID: <08750e31fcdccf5352dc3b44475ed5ba6bc80221.1781710785.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 17 Jun 2026 17:39:46 +0200 Subject: [PULL 2/3] hw/9pfs: reject . and .. in Twstat rename To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Greg Kurz , Peter Maydell Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=5.189.157.229; envelope-from=08750e31fcdccf5352dc3b44475ed5ba6bc80221@kylie.crudebyte.com; helo=kylie.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1781711095807158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The other Trename and Trenameat handlers already reject "." and ".." as new name on rename requests by returning -EISDIR in this case. The legacy Twstat rename handler is missing this validation. While passing "." or ".." does not trigger a crash as fixed by the previous patch (since the fs backend driver's system calls handle these gracefully), it creates a behavioral inconsistency, as it is semantically meaningless to rename a file to a directory reference in the first place. Fix this by rejecting "." and ".." in Twstat rename handler with -EISDIR to match behavior of Trename and Trenameat handlers. Fixes: 8cf89e007a ("virtio-9p: Add P9_TWSTAT support") Link: https://lore.kernel.org/qemu-devel/662333331d371c6c343c8091161de8eaa1= 21880e.1780072238.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index f84698bfcc..936e4e9349 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3642,6 +3642,10 @@ static void coroutine_fn v9fs_wstat(void *opaque) err =3D -ENOENT; goto out; } + if (!strcmp(".", v9stat.name.data) || !strcmp("..", v9stat.name.da= ta)) { + err =3D -EISDIR; + goto out; + } =20 v9fs_path_write_lock(s); err =3D v9fs_complete_rename(pdu, fidp, -1, &v9stat.name); --=20 2.47.3 From nobody Sun Jul 26 12:38:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1781711095; cv=none; d=zohomail.com; s=zohoarc; b=Go6VCHX0oHwky0asy1Ib9cOOZ3cdtdhdwmKuoXVMl1ufLoAdGYlN4Af/pvcYqW6QmhVMjSlxw9VrvjLDzqIvbhrwilG7U9PXcUERfK3VRc3Zloo31GO/aeILsiSZwCKcAq8sBZXlMsLw4MoyOyKroIc613EBa0Mu2UW1PAEYLZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781711095; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ydKD9ckopWFoZeAHR6Jgy9oNnMyCzK+l886VcxKDjv0=; b=RoRqPp6uBXUPEX1o7HMO93RwyMDAHvAiJR5ZF9/A3PjfV/su52BI5tkBrjPUDvYse9EyHlMS7l0cLmULPFwy9ZFqZJDvAoSVeGgFSQsxGfJpWE9WfIH/iSOaMm0vIxKRdDZhXEZfeCngrSs9BHq8dNZAW9YreQVekjb0Ueev2os= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781711095360374.91732502474315; Wed, 17 Jun 2026 08:44:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZsQm-0003sy-Mb; Wed, 17 Jun 2026 11:43:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <116db2986b11c914217bbd1547815b6c7efb944a@kylie.crudebyte.com>) id 1wZsQi-0003s3-PF for qemu-devel@nongnu.org; Wed, 17 Jun 2026 11:43:52 -0400 Received: from kylie.crudebyte.com ([5.189.157.229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <116db2986b11c914217bbd1547815b6c7efb944a@kylie.crudebyte.com>) id 1wZsQg-0002KA-BQ for qemu-devel@nongnu.org; Wed, 17 Jun 2026 11:43:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-ID:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=ydKD9ckopWFoZeAHR6Jgy9oNnMyCzK+l886VcxKDjv0=; b=QiakA 6jJ8oHt6iCCfkowGBTy1mAMrGYT7xj3dOM9blpzltjAA7yzXpad29FXRCjAnbd9Xt4PmZMYQpF3PM e34T2ePdip7SeWJEL2WXRGVl5namnaiDvKXQ4xQq6KJFSIQG5CwHqeVD4PgIR8O+/qNQi+BgftqW/ BuLtET3s4n1Ivikh2wTFKTEZ2d9a9sknMPU2wmVxC35dVjeVyzUSmEi5HlJ5B4nFqk3sGwM1SPQf6 luawLdc3dhRmrZOa3viSFbmNdfnuFlEGcFjCk/sPexYj12CJs8lZt/LrQdLLtfmBvIYtJW3eh74G8 dV1rAVy0S3SkcX5f59okT2ueVEp+rJEU5tJUSXsKZf38hss3BK7oqzdN6C29NmJ44JCU9p7DEm1TR koLjUNN26fiBYP1bdnl+/Y4KsaXFkMDJFITNanJBsObZierGRc2rk8zINM7h38bFMmpmXglZoCa2g kqezCtDJTOyBTNcOovSjQwyIyq+/64Y53gPsUERCAaxMiWlVoxwDuA3nOnlQuGKyPAhLcixjXcHEH ErjjTeKp49mcF2T2hnjl7kzn8PyHiX2GMa4+tM2P5OvN5MdIeOEaHGii/fhrV4hXOaFrnn5Oe4ZPj kUG7iUGAF3JzEkPaWciTmz3cO6ZjvKxk5skbC7qUZ4thdC/kOSevzFabwDYnm4=; Message-ID: <116db2986b11c914217bbd1547815b6c7efb944a.1781710785.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 17 Jun 2026 17:39:46 +0200 Subject: [PULL 3/3] hw/9pfs: consolidate name validation with check_name() To: qemu-devel@nongnu.org Cc: Greg Kurz , Peter Maydell Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=5.189.157.229; envelope-from=116db2986b11c914217bbd1547815b6c7efb944a@kylie.crudebyte.com; helo=kylie.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1781711097538158500 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a new, shared helper function check_name() that consolidates the name validation logic (illegal name check and "." / ".." rejection) currently spread over multiple 9p handlers, unnecessarily duplicating code. This is pure refactoring with no behavior change. The existing error code semantics are preserved: rename operations return -EISDIR, create operations return -EEXIST. Note: These current error codes actually differ from native Linux system calls (e.g. rename() returns -EBUSY, open(O_CREAT) returns -EISDIR). The 9P protocol does not mandate specific error codes for these validation errors. Hence consolidating to a single error code (e.g., -EINVAL) for all cases could be considered in the future for simplicity reason. This change reduces code duplication across 9 functions: - v9fs_lcreate - v9fs_create - v9fs_symlink - v9fs_link - v9fs_rename - v9fs_renameat - v9fs_wstat - v9fs_mknod - v9fs_mkdir Link: https://lore.kernel.org/qemu-devel/0573103880129eb543f07b68c77e86f2f5= 72f6bf.1780072238.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 100 ++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 936e4e9349..b486cce48a 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1823,6 +1823,25 @@ static bool name_is_illegal(const char *name) return !*name || strchr(name, '/') !=3D NULL; } =20 +static int check_name(const char *name, V9fsPDU *pdu) +{ + int request_type =3D pdu->id; + + if (name_is_illegal(name)) { + return -ENOENT; + } + if (!strcmp(name, ".") || !strcmp(name, "..")) { + /* + * TODO: The different error codes here are just there to preserve + * pre-existing behaviour of 9p server. In future it might make se= nse to + * consolidate this and e.g. just return -EINVAL for everyone. + */ + return (request_type =3D=3D P9_TRENAME || request_type =3D=3D P9_T= RENAMEAT || + request_type =3D=3D P9_TWSTAT) ? -EISDIR : -EEXIST; + } + return 0; +} + static bool same_stat_id(const struct stat *a, const struct stat *b) { return a->st_dev =3D=3D b->st_dev && a->st_ino =3D=3D b->st_ino; @@ -2173,13 +2192,8 @@ static void coroutine_fn v9fs_lcreate(void *opaque) } trace_v9fs_lcreate(pdu->tag, pdu->id, dfid, flags, mode, gid); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -2861,13 +2875,8 @@ static void coroutine_fn v9fs_create(void *opaque) } trace_v9fs_create(pdu->tag, pdu->id, fid, name.data, perm, mode); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -3055,13 +3064,8 @@ static void coroutine_fn v9fs_symlink(void *opaque) } trace_v9fs_symlink(pdu->tag, pdu->id, dfid, name.data, symname.data, g= id); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -3148,13 +3152,8 @@ static void coroutine_fn v9fs_link(void *opaque) } trace_v9fs_link(pdu->tag, pdu->id, dfid, oldfid, name.data); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -3385,13 +3384,8 @@ static void coroutine_fn v9fs_rename(void *opaque) goto out_nofid; } =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EISDIR; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -3526,14 +3520,12 @@ static void coroutine_fn v9fs_renameat(void *opaque) goto out_err; } =20 - if (name_is_illegal(old_name.data) || name_is_illegal(new_name.data)) { - err =3D -ENOENT; + err =3D check_name(old_name.data, pdu); + if (err < 0) { goto out_err; } - - if (!strcmp(".", old_name.data) || !strcmp("..", old_name.data) || - !strcmp(".", new_name.data) || !strcmp("..", new_name.data)) { - err =3D -EISDIR; + err =3D check_name(new_name.data, pdu); + if (err < 0) { goto out_err; } =20 @@ -3638,12 +3630,8 @@ static void coroutine_fn v9fs_wstat(void *opaque) err =3D -EOPNOTSUPP; goto out; } - if (name_is_illegal(v9stat.name.data)) { - err =3D -ENOENT; - goto out; - } - if (!strcmp(".", v9stat.name.data) || !strcmp("..", v9stat.name.da= ta)) { - err =3D -EISDIR; + err =3D check_name(v9stat.name.data, pdu); + if (err < 0) { goto out; } =20 @@ -3776,13 +3764,8 @@ static void coroutine_fn v9fs_mknod(void *opaque) } trace_v9fs_mknod(pdu->tag, pdu->id, fid, mode, major, minor); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 @@ -3938,13 +3921,8 @@ static void coroutine_fn v9fs_mkdir(void *opaque) } trace_v9fs_mkdir(pdu->tag, pdu->id, fid, name.data, mode, gid); =20 - if (name_is_illegal(name.data)) { - err =3D -ENOENT; - goto out_nofid; - } - - if (!strcmp(".", name.data) || !strcmp("..", name.data)) { - err =3D -EEXIST; + err =3D check_name(name.data, pdu); + if (err < 0) { goto out_nofid; } =20 --=20 2.47.3