From nobody Tue Apr 30 07:03:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489792867434376.03853053175294; Fri, 17 Mar 2017 16:21:07 -0700 (PDT) Received: from localhost ([::1]:51190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cp1BC-0003hE-0C for importer@patchew.org; Fri, 17 Mar 2017 19:21:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cp1Ah-0003gx-KD for qemu-devel@nongnu.org; Fri, 17 Mar 2017 19:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cp1Ac-0004pn-KG for qemu-devel@nongnu.org; Fri, 17 Mar 2017 19:20:35 -0400 Received: from 10.mo69.mail-out.ovh.net ([46.105.73.241]:48694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cp1Ac-0004pd-DN for qemu-devel@nongnu.org; Fri, 17 Mar 2017 19:20:30 -0400 Received: from player738.ha.ovh.net (b7.ovh.net [213.186.33.57]) by mo69.mail-out.ovh.net (Postfix) with ESMTP id 874171C870 for ; Sat, 18 Mar 2017 00:20:27 +0100 (CET) Received: from bahia.lan (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player738.ha.ovh.net (Postfix) with ESMTPA id 51F11545; Sat, 18 Mar 2017 00:20:25 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Sat, 18 Mar 2017 00:20:19 +0100 Message-ID: <148979281961.4342.6047114276763582872.stgit@bahia.lan> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 8014999965180991940 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrieefgdduvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecu X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.73.241 Subject: [Qemu-devel] [PATCH v3] 9pfs: proxy: assert if unmarshal fails 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: Greg Kurz , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Replies from the virtfs proxy are made up of a fixed-size header (8 bytes) and a payload of variable size (maximum 64kb). When receiving a reply, the proxy backend first reads the whole header and then unmarshals it. If the header is okay, it then does the same operation with the payload. Since the proxy backend uses a pre-allocated buffer which has enough room for a header and the maximum payload size, marshalling should never fail with fixed size arguments. Any error here is likely to result from a more serious corruption in QEMU and we'd better dump core right away. This patch adds error checks where they are missing and converts the associated error paths into assertions. This should also address Coverity's complaints CID 1348519 and CID 1348520, about not always checking the return value of proxy_unmarshal(). Signed-off-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v3: - completely get rid of sizeof() and QEMU_BUILD_BUG_ON() as it was confusing. Only use literal values in checks finally. --- hw/9pfs/9p-proxy.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index f4aa7a9d70f8..28b20a7c3dfa 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -165,7 +165,8 @@ static int v9fs_receive_response(V9fsProxy *proxy, int = type, return retval; } reply->iov_len =3D PROXY_HDR_SZ; - proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); + retval =3D proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); + assert(retval =3D=3D 4 * 2); /* * if response size > PROXY_MAX_IO_SZ, read the response but ignore it= and * return -ENOBUFS @@ -194,9 +195,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int = type, if (header.type =3D=3D T_ERROR) { int ret; ret =3D proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status); - if (ret < 0) { - *status =3D ret; - } + assert(ret =3D=3D 4); return 0; } =20 @@ -213,6 +212,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int = type, &prstat.st_atim_sec, &prstat.st_atim_nsec, &prstat.st_mtim_sec, &prstat.st_mtim_nsec, &prstat.st_ctim_sec, &prstat.st_ctim_nsec= ); + assert(retval =3D=3D 8 * 3 + 4 * 3 + 8 * 10); prstat_to_stat(response, &prstat); break; } @@ -225,6 +225,7 @@ static int v9fs_receive_response(V9fsProxy *proxy, int = type, &prstfs.f_files, &prstfs.f_ffree, &prstfs.f_fsid[0], &prstfs.f_fsid[1], &prstfs.f_namelen, &prstfs.f_frsize); + assert(retval =3D=3D 8 * 11); prstatfs_to_statfs(response, &prstfs); break; } @@ -246,7 +247,8 @@ static int v9fs_receive_response(V9fsProxy *proxy, int = type, break; } case T_GETVERSION: - proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response); + retval =3D proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response); + assert(retval =3D=3D 8); break; default: return -1; @@ -274,18 +276,16 @@ static int v9fs_receive_status(V9fsProxy *proxy, return retval; } reply->iov_len =3D PROXY_HDR_SZ; - proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); - if (header.size !=3D sizeof(int)) { - *status =3D -ENOBUFS; - return 0; - } + retval =3D proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); + assert(retval =3D=3D 4 * 2); retval =3D socket_read(proxy->sockfd, reply->iov_base + PROXY_HDR_SZ, header.size); if (retval < 0) { return retval; } reply->iov_len +=3D header.size; - proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status); + retval =3D proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status); + assert(retval =3D=3D 4); return 0; } =20