From patchwork Wed Sep 20 13:50:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 816273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy2fY21nqz9s4q for ; Thu, 21 Sep 2017 00:48:05 +1000 (AEST) Received: from localhost ([::1]:48587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dugIF-0008Oc-9b for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:48:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufP2-0006U5-M5 for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufOz-0004Fe-JS for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:00 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:42394 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 1dufOz-0004FO-EM for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:50:57 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8KDn10g117724 for ; Wed, 20 Sep 2017 09:50:57 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2d3r0pq40n-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 20 Sep 2017 09:50:56 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Sep 2017 14:50:54 +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; Wed, 20 Sep 2017 14:50:51 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8KDopM821233754; Wed, 20 Sep 2017 13:50:51 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F6A742042; Wed, 20 Sep 2017 14:47:02 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F095542041; Wed, 20 Sep 2017 14:47:01 +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; Wed, 20 Sep 2017 14:47:01 +0100 (BST) Received: from bahia.lan (icon-9-167-240-87.megacenter.de.ibm.com [9.167.240.87]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 3BD1D220154; Wed, 20 Sep 2017 15:50:50 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 20 Sep 2017 15:50:36 +0200 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170920135038.21058-1-groug@kaod.org> References: <20170920135038.21058-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17092013-0040-0000-0000-000003FBAD18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092013-0041-0000-0000-0000209CE3F0 Message-Id: <20170920135038.21058-2-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-20_04:, , 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-1707230000 definitions=main-1709200189 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 1/3] 9pfs: fix readdir() for 9p2000.u 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 , Jan Dakinevich , Greg Kurz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jan Dakinevich If the client is using 9p2000.u, the following occurs: $ cd ${virtfs_shared_dir} $ mkdir -p a/b/c $ ls a/b ls: cannot access 'a/b/a': No such file or directory ls: cannot access 'a/b/b': No such file or directory a b c instead of the expected: $ ls a/b c This is a regression introduced by commit f57f5878578a; local_name_to_path() now resolves ".." and "." in paths, and v9fs_do_readdir_with_stat()->stat_to_v9stat() then copies the basename of the resulting path to the response. With the example above, this means that "." and ".." are turned into "b" and "a" respectively... stat_to_v9stat() currently assumes it is passed a full canonicalized path and uses it to do two different things: 1) to pass it to v9fs_co_readlink() in case the file is a symbolic link 2) to set the name field of the V9fsStat structure to the basename part of the given path It only has two users: v9fs_stat() and v9fs_do_readdir_with_stat(). v9fs_stat() really needs 1) and 2) to be performed since it starts with the full canonicalized path stored in the fid. It is different for v9fs_do_readdir_with_stat() though because the name we want to put into the V9fsStat structure is the d_name field of the dirent actually (ie, we want to keep the "." and ".." special names). So, we only need 1) in this case. This patch hence adds a basename argument to stat_to_v9stat(), to be used to set the name field of the V9fsStat structure, and moves the basename logic to v9fs_stat(). Signed-off-by: Jan Dakinevich (groug, renamed old name argument to path and updated changelog) Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 0a37c8bd1361..1078cfdaa4af 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -803,12 +803,12 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf) return mode; } -static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, +static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path, + const char *basename, const struct stat *stbuf, V9fsStat *v9stat) { int err; - const char *str; memset(v9stat, 0, sizeof(*v9stat)); @@ -829,7 +829,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, v9fs_string_free(&v9stat->extension); if (v9stat->mode & P9_STAT_MODE_SYMLINK) { - err = v9fs_co_readlink(pdu, name, &v9stat->extension); + err = v9fs_co_readlink(pdu, path, &v9stat->extension); if (err < 0) { return err; } @@ -842,14 +842,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, "HARDLINKCOUNT", (unsigned long)stbuf->st_nlink); } - str = strrchr(name->data, '/'); - if (str) { - str += 1; - } else { - str = name->data; - } - - v9fs_string_sprintf(&v9stat->name, "%s", str); + v9fs_string_sprintf(&v9stat->name, "%s", basename); v9stat->size = 61 + v9fs_string_size(&v9stat->name) + @@ -1056,6 +1049,7 @@ static void coroutine_fn v9fs_stat(void *opaque) struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu = opaque; + char *basename; err = pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { @@ -1072,7 +1066,9 @@ static void coroutine_fn v9fs_stat(void *opaque) if (err < 0) { goto out; } - err = stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat); + basename = g_path_get_basename(fidp->path.data); + err = stat_to_v9stat(pdu, &fidp->path, basename, &stbuf, &v9stat); + g_free(basename); if (err < 0) { goto out; } @@ -1748,7 +1744,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, if (err < 0) { break; } - err = stat_to_v9stat(pdu, &path, &stbuf, &v9stat); + err = stat_to_v9stat(pdu, &path, dent->d_name, &stbuf, &v9stat); if (err < 0) { break; } From patchwork Wed Sep 20 13:50:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 816274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy2jq6Qf9z9s4q for ; Thu, 21 Sep 2017 00:50:54 +1000 (AEST) Received: from localhost ([::1]:48604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dugKy-0002cf-Km for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:50:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufP5-0006Wb-9B for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufP2-0004GR-7U for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49336) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dufP1-0004GB-Vd for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:00 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8KDol22059526 for ; Wed, 20 Sep 2017 09:50:58 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2d3r0pf813-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 20 Sep 2017 09:50:58 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Sep 2017 14:50:56 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 20 Sep 2017 14:50:53 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v8KDorwp19267630; Wed, 20 Sep 2017 13:50:53 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A3CCCAE053; Wed, 20 Sep 2017 14:45:45 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 90413AE04D; Wed, 20 Sep 2017 14:45:45 +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; Wed, 20 Sep 2017 14:45:45 +0100 (BST) Received: from bahia.lan (icon-9-167-240-87.megacenter.de.ibm.com [9.167.240.87]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 3C056220154; Wed, 20 Sep 2017 15:50:52 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 20 Sep 2017 15:50:37 +0200 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170920135038.21058-1-groug@kaod.org> References: <20170920135038.21058-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17092013-0008-0000-0000-00000498AE30 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092013-0009-0000-0000-00001E29E506 Message-Id: <20170920135038.21058-3-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-20_04:, , 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-1707230000 definitions=main-1709200189 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 2/3] 9pfs: fix name_to_path assertion in v9fs_complete_rename() 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 , Jan Dakinevich , Greg Kurz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jan Dakinevich The third parameter of v9fs_co_name_to_path() must not contain `/' character. The issue is most likely related to 9p2000.u protocol only. Signed-off-by: Jan Dakinevich [groug, regression caused by commit f57f5878578a # 2.10] Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 1078cfdaa4af..cdd44bdc82ef 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2553,13 +2553,11 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp, int32_t newdirfid, V9fsString *name) { - char *end; int err = 0; V9fsPath new_path; V9fsFidState *tfidp; V9fsState *s = pdu->s; V9fsFidState *dirfidp = NULL; - char *old_name, *new_name; v9fs_path_init(&new_path); if (newdirfid != -1) { @@ -2577,18 +2575,15 @@ static int coroutine_fn v9fs_complete_rename(V9fsPDU *pdu, V9fsFidState *fidp, goto out; } } else { - old_name = fidp->path.data; - end = strrchr(old_name, '/'); - if (end) { - end++; - } else { - end = old_name; - } - new_name = 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); - err = v9fs_co_name_to_path(pdu, NULL, new_name, &new_path); - g_free(new_name); + char *dir_name = g_path_get_dirname(fidp->path.data); + V9fsPath dir_path; + + v9fs_path_init(&dir_path); + v9fs_path_sprintf(&dir_path, "%s", dir_name); + g_free(dir_name); + + err = v9fs_co_name_to_path(pdu, &dir_path, name->data, &new_path); + v9fs_path_free(&dir_path); if (err < 0) { goto out; } From patchwork Wed Sep 20 13:50:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 816279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xy2p225Ltz9sPt for ; Thu, 21 Sep 2017 00:54:34 +1000 (AEST) Received: from localhost ([::1]:48622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dugOW-0006n6-Be for incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 10:54:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dufP5-0006Wm-Ew for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dufP2-0004Ga-Cr for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43329 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 1dufP2-0004GH-75 for qemu-devel@nongnu.org; Wed, 20 Sep 2017 09:51:00 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v8KDn9NB071904 for ; Wed, 20 Sep 2017 09:50:59 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2d3nqrgdf3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 20 Sep 2017 09:50:59 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Sep 2017 14:50:57 +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; Wed, 20 Sep 2017 14:50:55 +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 v8KDosCm20316374; Wed, 20 Sep 2017 13:50:54 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 93F4EA4051; Wed, 20 Sep 2017 14:46:55 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 81A1EA404D; Wed, 20 Sep 2017 14:46:55 +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; Wed, 20 Sep 2017 14:46:55 +0100 (BST) Received: from bahia.lan (icon-9-167-240-87.megacenter.de.ibm.com [9.167.240.87]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id E5BBB220154; Wed, 20 Sep 2017 15:50:53 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Wed, 20 Sep 2017 15:50:38 +0200 X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170920135038.21058-1-groug@kaod.org> References: <20170920135038.21058-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 17092013-0040-0000-0000-000003FBAD1B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17092013-0041-0000-0000-0000209CE3F4 Message-Id: <20170920135038.21058-4-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-20_04:, , 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-1707230000 definitions=main-1709200189 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 3/3] 9pfs: check the size of transport buffer before marshaling 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 , Jan Dakinevich , Greg Kurz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jan Dakinevich v9fs_do_readdir_with_stat() should check for a maximum buffer size before an attempt to marshal gathered data. Otherwise, buffers assumed as misconfigured and the transport would be broken. The patch brings v9fs_do_readdir_with_stat() in conformity with v9fs_do_readdir() behavior. Signed-off-by: Jan Dakinevich [groug, regression caused my commit 8d37de41cab1 # 2.10] Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index cdd44bdc82ef..23ac7bb532f0 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1748,17 +1748,26 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, if (err < 0) { break; } + if ((count + v9stat.size + 2) > max_count) { + v9fs_readdir_unlock(&fidp->fs.dir); + + /* Ran out of buffer. Set dir back to old position and return */ + v9fs_co_seekdir(pdu, fidp, saved_dir_pos); + v9fs_stat_free(&v9stat); + v9fs_path_free(&path); + return count; + } + /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len = pdu_marshal(pdu, 11 + count, "S", &v9stat); v9fs_readdir_unlock(&fidp->fs.dir); - if ((len != (v9stat.size + 2)) || ((count + len) > max_count)) { - /* Ran out of buffer. Set dir back to old position and return */ + if (len < 0) { v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); v9fs_path_free(&path); - return count; + return len; } count += len; v9fs_stat_free(&v9stat);