From patchwork Tue Apr 5 10:35:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsh Prateek Bora X-Patchwork-Id: 89813 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6A0A0B6F83 for ; Tue, 5 Apr 2011 20:36:45 +1000 (EST) Received: from localhost ([127.0.0.1]:51124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q73co-000681-3T for incoming@patchwork.ozlabs.org; Tue, 05 Apr 2011 06:36:42 -0400 Received: from [140.186.70.92] (port=47878 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q73c0-00066k-H0 for qemu-devel@nongnu.org; Tue, 05 Apr 2011 06:36:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q73by-0004MF-W9 for qemu-devel@nongnu.org; Tue, 05 Apr 2011 06:35:51 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:34585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q73by-0004Le-Br for qemu-devel@nongnu.org; Tue, 05 Apr 2011 06:35:50 -0400 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp05.in.ibm.com (8.14.4/8.13.1) with ESMTP id p35AZhYD001950 for ; Tue, 5 Apr 2011 16:05:43 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p35AZd4Y4374666 for ; Tue, 5 Apr 2011 16:05:43 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p35AZegs010268 for ; Tue, 5 Apr 2011 16:05:40 +0530 Received: from harshbora.in.ibm.com ([9.79.188.219]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p35AZdtN010230; Tue, 5 Apr 2011 16:05:39 +0530 From: Harsh Prateek Bora To: qemu-devel@nongnu.org, stefanha@gmail.com Date: Tue, 5 Apr 2011 16:05:35 +0530 Message-Id: <1301999735-24141-1-git-send-email-harsh@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 122.248.162.5 Cc: Harsh Prateek Bora , jvrao@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v4] v9fs_walk: As per 9p2000 RFC, MAXWELEM >= nwnames >= 0. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The nwnames field in TWALK message is assumed to be >=0 and <= MAXWELEM which is defined as macro P9_MAXWELEM (16) in virtio-9p.h as per 9p2000 RFC. Appropriate changes are required in V9fsWalkState and v9fs_walk. v4: - rebased on mainline repo, else condition updated as required. v3: - Updated if-else conditions to appropriately handle nwnames = 0. v2: - Added check in v9fs_walk_complete as well. Signed-off-by: Harsh Prateek Bora Reviewed-by: Stefan Hajnoczi --- hw/virtio-9p.c | 7 +++++-- hw/virtio-9p.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 7c59988..1656862 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1482,7 +1482,7 @@ static void v9fs_walk_complete(V9fsState *s, V9fsWalkState *vs, int err) { complete_pdu(s, vs->pdu, err); - if (vs->nwnames) { + if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) { for (vs->name_idx = 0; vs->name_idx < vs->nwnames; vs->name_idx++) { v9fs_string_free(&vs->wnames[vs->name_idx]); } @@ -1578,7 +1578,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu) vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "ddw", &fid, &newfid, &vs->nwnames); - if (vs->nwnames) { + if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) { vs->wnames = qemu_mallocz(sizeof(vs->wnames[0]) * vs->nwnames); vs->qids = qemu_mallocz(sizeof(vs->qids[0]) * vs->nwnames); @@ -1587,6 +1587,9 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu) vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "s", &vs->wnames[i]); } + } else if (vs->nwnames > P9_MAXWELEM) { + err = -EINVAL; + goto out; } vs->fidp = lookup_fid(s, fid); diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h index 2ae4ce7..3c92c74 100644 --- a/hw/virtio-9p.h +++ b/hw/virtio-9p.h @@ -282,7 +282,7 @@ typedef struct V9fsStatStateDotl { typedef struct V9fsWalkState { V9fsPDU *pdu; size_t offset; - int16_t nwnames; + uint16_t nwnames; int name_idx; V9fsQID *qids; V9fsFidState *fidp;