From patchwork Fri Aug 26 15:07:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 9301597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 52931601C0 for ; Fri, 26 Aug 2016 15:15:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4305B2962F for ; Fri, 26 Aug 2016 15:15:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3680F29638; Fri, 26 Aug 2016 15:15:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A1CD2962F for ; Fri, 26 Aug 2016 15:15:06 +0000 (UTC) Received: from localhost ([::1]:60958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdIqX-0007Ng-UI for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 Aug 2016 11:15:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdIjV-00026y-NG for qemu-devel@nongnu.org; Fri, 26 Aug 2016 11:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bdIjP-0002fz-OK for qemu-devel@nongnu.org; Fri, 26 Aug 2016 11:07:48 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdIjP-0002fv-Ez for qemu-devel@nongnu.org; Fri, 26 Aug 2016 11:07:43 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7QF5bWI083259 for ; Fri, 26 Aug 2016 11:07:43 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 251kn5xqkk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 26 Aug 2016 11:07:42 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 26 Aug 2016 09:07:41 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 26 Aug 2016 09:07:38 -0600 X-IBM-Helo: d03dlp02.boulder.ibm.com X-IBM-MailFrom: groug@kaod.org Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id A6BF83E40048; Fri, 26 Aug 2016 09:07:37 -0600 (MDT) Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7QF7e7718219458; Fri, 26 Aug 2016 15:07:40 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C50E2803F; Fri, 26 Aug 2016 11:07:37 -0400 (EDT) Received: from bahia.lan (unknown [9.167.235.232]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id C996B2804C; Fri, 26 Aug 2016 11:07:35 -0400 (EDT) From: Greg Kurz To: qemu-devel@nongnu.org Date: Fri, 26 Aug 2016 17:07:34 +0200 In-Reply-To: <147222401281.18925.1894824578752486297.stgit@bahia.lan> References: <147222401281.18925.1894824578752486297.stgit@bahia.lan> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16082615-0016-0000-0000-000004840F60 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00005643; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000183; SDB=6.00750026; UDB=6.00354182; IPR=6.00522663; BA=6.00004676; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00012476; XFM=3.00000011; UTC=2016-08-26 15:07:40 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16082615-0017-0000-0000-0000325CC1C4 Message-Id: <147222405454.18925.2135759955496138955.stgit@bahia.lan> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-26_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608260194 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 5/5] 9p: forbid empty extension string 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 , Felix Wilhelm , "Michael S. Tsirkin" , Greg Kurz , P J P , "Aneesh Kumar K.V" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP A buggy guest using the 9p2000.u protocol can issue a create request and pass an empty string as the extension argument. This causes QEMU to crash in the case of a hard link or a special file, and leads to undefined behavior, depending on the backend, in the case of a symbolic link. This patch causes the request to fail with EINVAL in these scenarios. Signed-off-by: Greg Kurz --- hw/9pfs/9p.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 7b1dfe4e47cb..dc65c3125006 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2150,6 +2150,11 @@ static void v9fs_create(void *opaque) } fidp->fid_type = P9_FID_DIR; } else if (perm & P9_STAT_MODE_SYMLINK) { + if (extension.data == NULL) { + err = -EINVAL; + goto out; + } + err = v9fs_co_symlink(pdu, fidp, &name, extension.data, -1 , &stbuf); if (err < 0) { @@ -2161,8 +2166,15 @@ static void v9fs_create(void *opaque) } v9fs_path_copy(&fidp->path, &path); } else if (perm & P9_STAT_MODE_LINK) { - int32_t ofid = atoi(extension.data); - V9fsFidState *ofidp = get_fid(pdu, ofid); + V9fsFidState *ofidp; + + if (extension.data == NULL) { + err = -EINVAL; + goto out; + } + + ofidp = get_fid(pdu, atoi(extension.data)); + if (ofidp == NULL) { err = -EINVAL; goto out; @@ -2188,6 +2200,11 @@ static void v9fs_create(void *opaque) uint32_t major, minor; mode_t nmode = 0; + if (extension.data == NULL) { + err = -EINVAL; + goto out; + } + if (sscanf(extension.data, "%c %u %u", &ctype, &major, &minor) != 3) { err = -errno; goto out;