From nobody Sat May 30 17:43:34 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=1780074481; cv=none; d=zohomail.com; s=zohoarc; b=kDP1t/f5BuzpiCXX6+FwEyy1wAGtBw2Y9N5Evk8xIAy2F6XanO7qKJaHb1kDsG3dX8NH723lKp1oSYEbk5jCBhH7MVNhAeUjluI30jDytgrR3Iba8CqdC/WEBxSpefNzsQQHGoFcZjucSg9zPc8TaA7IZo1WGia7SEE0YwdToqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780074481; 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=kuDU0SJYEpQm+SDC87IHg0dE+llS/Ci4L0J44gT7NX8=; b=lZQ+TSekxpCNxULYta6Cbb4X1V+5Th7aNsct7A/UKCsiPbI2AuDBHJCdTqZkWE8+iBf2fNGCoEEWqcjXUrtCl6hsewf981fx5MK7gGMnJWNfHTfUQ5zETIfbxRz2JxK7NNxg66rxFkAR3EMZVfpCxfvHBO6rr/Z/rLEwiocAvvo= 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 1780074481533694.4248089259288; Fri, 29 May 2026 10:08:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT0g4-0006GP-RT; Fri, 29 May 2026 13:07:20 -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 ) id 1wT0fq-0006BO-0k; Fri, 29 May 2026 13:07:07 -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 ) id 1wT0fn-0005zd-VS; Fri, 29 May 2026 13:07:05 -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=kuDU0SJYEpQm+SDC87IHg0dE+llS/Ci4L0J44gT7NX8=; b=h8qvR lnhB21YF2ZT08BW8VPKdyBEllYYLwbqPafSDlH22kSmXJJoddLhUsBevf1/tf/Oc1lPAdEqpfuLDu rYvLF4Kw4Pkm3n73UJ8g7WbwqyDtXDs4A86HFVL3GFZ8Dz75Yyp1MweeQ3MrCgJCK1mO3mv5hAREv W5DONmwjUXSrpjMC++MXFTNjIi27pQLo2Bgzf3FNjviCHkA84vRm5FbrgAP8qXYIIdW8yIt/Qemfr XnXx/WcqoqLG0OT7/GLBLzpfvEDjA9BJFjqx6vDkRBn9FEiu11B2BldAEVn4sx7kAbMxgxAPGecly k2iDJZLus2O2xCVkA2DlwxL+cd7ACdl2dD2yacRS5uO3FLF3Y+xPv6EQywr9JS4lhORiO8HkLoT1Y q0sc9nPmYGghPST9siEz1h6+y3FGEdIreLTvhBPWRp4XaYUC8GbV1VZ3zeVZcPz3dcicUqzMXg1X+ tAOqOBot7eKPSbZ5VsDBHfV2iWhn3tZYhk57fHCalBQ6IMHF8661LP/boj7xkGXLr3amsTeAwd7/D 5cYtVCmFL186oPkgKaPEzmV7u2ISAkqdfxf6UKk5By85sZ3JtyW8ZW90ufdq53XB98+rNnDFgJ+hx tipXImCEBylcXut705zmLVH1U+O34IE8AMnFd9Bpb81Sr0sw1ypqTF2a90mJIg=; Message-ID: In-Reply-To: References: From: Christian Schoenebeck Date: Fri, 29 May 2026 18:29:26 +0200 Subject: [PATCH 1/3] hw/9pfs: fix abort due to illegal name with Twstat rename To: qemu-devel@nongnu.org, qemu-stable@nongnu.org Cc: Greg Kurz , 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=ba09716828e82992f9d8cac7f00eee0bc1c43c61@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: 1780074482829158500 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") 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 e2713b9eee..88fb28b318 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3617,6 +3617,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 Sat May 30 17:43:34 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=1780074457; cv=none; d=zohomail.com; s=zohoarc; b=I6uZzufDHi6mt/J9ZEDAye3xupBUmQKDmPeayR3Fv1ma4w0h6TVksb6UIhAMfwH5JKybT8Kx4uk/PPOaUjRaGWbjUV6ovuCY+arwFk/PYhiamF3Nt7YiWRZofNvDnBPhheZ6PibIZVSkQ+6OdaIJ3ca8FX5R3YuXhdfbFssCtmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780074457; 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=VI1Vr5pQLC5ZGMOmjMtI/rZPEM24szP1EeBghlRj3pc=; b=RTsK7vh3ZxxCS32aQDHbMnza/3Sn380dC3cYJKC6NpeOFoQQPOL8zegTEmXXeTcw5wOnep7d95o/lxHGM+UEIXbsncoa3nvTBewAlIUK8UCrjgCvPyxPZORxFEnTP5Z0fsys8apmZd129bDYU8Uznyo4bI2I11Hcl60YNl69gKI= 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 1780074457007712.6496037939584; Fri, 29 May 2026 10:07:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT0g0-0006C0-W1; Fri, 29 May 2026 13:07:17 -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 <662333331d371c6c343c8091161de8eaa121880e@kylie.crudebyte.com>) id 1wT0fk-0006A6-Q3; Fri, 29 May 2026 13:07:03 -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 <662333331d371c6c343c8091161de8eaa121880e@kylie.crudebyte.com>) id 1wT0fi-0005yP-A3; Fri, 29 May 2026 13:07:00 -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=VI1Vr5pQLC5ZGMOmjMtI/rZPEM24szP1EeBghlRj3pc=; b=IO5yo izLto9gTDhetfii8fgsPvvbkd7twDbXxBQHh3UqGSxlRbstFDruWpMWsn/fiRxHj6yDDJY4fRLULF o7szGtBNSWXcKnaefKi0gXc9/Q8bnxtw0PRLLpLuMT0t0+31HDlsRJfiKyJ+zXjc27Ey5gRnLvD9h rsYcmiJpfOvpz9j4WvPSfU9elKY9OzJJk//a/Xqfn9Z/TRrc1Bnaf2RYd0oD/ob7Q3qKOl6xPIXnB 6wLGMza5A7fOkDJitvS6iCb3JxFDIwzXOETAOkEwsZshNfAty3reDmglzUqpDhMcHrduME5mC5EwP 9CYjAMrHRVRIE1OJaWvUDORPLUajlwKZEFsAlDgej4bZNGvr/21hdm0eV+4vslf0qR4Xm2Os01FUg CCrOfMM3DmXjAcaij1VtD6IJmsBzKQxUQYK9QTpkmE+f8BqUkH7fLxPv1Ct0fkVYK1Cfd8PB0Cz5N I0peRdEDmqx5Zzc6Fm/ufSmqbK8kREsYYbfMQ9NYeFgYjdqWwf9gpeXIReRX6aS2EthvuuHH88wPx ZNPolzitbX4qA8357L0cB64npFrOQkUwo74xI/4CTm5M9cQwp9XFsdeFFEaOoti56jskw/6Hfb3Rs VoT7ym55L6g2mbx2spOwo63vPQuO+gPZWMAhlvv7nx4XzhX/kyrrtjXK4gOiYs=; Message-ID: <662333331d371c6c343c8091161de8eaa121880e.1780072238.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Fri, 29 May 2026 18:29:40 +0200 Subject: [PATCH 2/3] hw/9pfs: reject . and .. in Twstat rename To: qemu-devel@nongnu.org, qemu-stable@nongnu.org Cc: Greg Kurz 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=662333331d371c6c343c8091161de8eaa121880e@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: 1780074459213158500 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") 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 88fb28b318..a09f99537d 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3621,6 +3621,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 Sat May 30 17:43:34 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=1780074456; cv=none; d=zohomail.com; s=zohoarc; b=cm5xTYaT3dAkoNTiwD5UInwYyWMiZFgGjEVdZVElG74ACJzN123Y72uzhE8z9UooQkOLCfePyMUQhFviqaV6LOdiGa7WA1HI2t89Y9f+8p6N75M4UjbJTcuJm/wdKDu33avk7bwxTmFfqvmQ15BRHWimiCCpC00sKqVhnMO4ZIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780074456; 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=gvgoP/DgFItr+dDpBQNnzHxIlewLZzV9f9f39ccdEQY=; b=bY5aIlhR1jTTM4kYY6az3I3SciPo+tFe08Kv5rpDk3pbCQylkGyV6mgYW8toTr3AR5kHA/Jx4MMHO648dUBb5hX0YoKyd+7Gsw4SrvYTGv1jXZxskdYhl336jHkpvZ0NQG9E9/HgtGmNgVq0q/nv2OtGQIXsCNYLEnbNvjeB6F8= 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 1780074456857532.9589194568044; Fri, 29 May 2026 10:07:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wT0fg-00069A-4A; Fri, 29 May 2026 13:06: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 <0573103880129eb543f07b68c77e86f2f572f6bf@kylie.crudebyte.com>) id 1wT0fZ-00068X-JD for qemu-devel@nongnu.org; Fri, 29 May 2026 13:06:50 -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 <0573103880129eb543f07b68c77e86f2f572f6bf@kylie.crudebyte.com>) id 1wT0fW-0005uz-L0 for qemu-devel@nongnu.org; Fri, 29 May 2026 13:06:49 -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=gvgoP/DgFItr+dDpBQNnzHxIlewLZzV9f9f39ccdEQY=; b=v76Kb LyynOByhW1PDlIU8cW+Q+zZwerfyd5+vu6BH4//bszPTcTDzM6WpDROchSQXtaRi/SBfY+yLTnco0 hnxAkrHqbipe82SD9D3mNcLgaYVeJXGoAc8qQKJSHpHG26eZ/ynDS29CwxxSQLdgz+YFo4fgSAljD 8j5HvUTcYUGAcIEjKy4fRUhMwhEBo3AJRijeuEhcZzYhqgXEEYrCdEV1ErdjTgUFZCrTVlVJhymbK l7Sdrt9/D9ZmH4zqSAnASMn0B2ZRbzUycgT/B4ApE/V6j8pxngyfbgEKGexGM6ewxMascTAORRPW3 dq6FPASdwC04Oudq274d0rP1f5bV9+sKYPGxZjh/DjgjMkAo6L3MTwD75U6s0gQ2LNreNUPMiFdtH uADgdqZ2nMUjyaSjSBcuIpSGx28NncLq1cpkES06UTdE5glIlEW3zL9+muqTbjvoXTqCkjdAqQwcs gb9jzfE3ucuYnYlv6CrtwzHcdj+NzWfhYk+ukDJWlFRveEVx+d8lH3Jtizspjz+WlmiXVY6JjY+Td 8QWb44kPmDR2BR+gOrawHllJKvvXXgjEYHaGyCNgP842ZTFKEOyE6CSeCG7rj9ylQUdCRSX8YbzA7 QqwDM9SvPeWThlkSAlFhA9f/jvSg9H/8Pdb94n4E60Eri4xdBR90MlJHynFsPM=; Message-ID: <0573103880129eb543f07b68c77e86f2f572f6bf.1780072238.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Fri, 29 May 2026 18:29:44 +0200 Subject: [PATCH 3/3] hw/9pfs: consolidate name validation with check_name() To: qemu-devel@nongnu.org Cc: Greg Kurz 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=0573103880129eb543f07b68c77e86f2f572f6bf@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: 1780074459274158500 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 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 a09f99537d..9b46b33ba8 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1810,6 +1810,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; @@ -2160,13 +2179,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 @@ -2848,13 +2862,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 @@ -3042,13 +3051,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 @@ -3135,13 +3139,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 @@ -3367,13 +3366,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 @@ -3505,14 +3499,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 @@ -3617,12 +3609,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 @@ -3755,13 +3743,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 @@ -3917,13 +3900,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