From patchwork Mon Dec 16 14:43:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11299143 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B7CC138C for ; Wed, 18 Dec 2019 00:31:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2135C2176D for ; Wed, 18 Dec 2019 00:31:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="C1m+U13L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2135C2176D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47646 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihNFO-00085Y-8r for patchwork-qemu-devel@patchwork.kernel.org; Tue, 17 Dec 2019 19:31:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36258) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihNEP-0007Jc-8T for qemu-devel@nongnu.org; Tue, 17 Dec 2019 19:30:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihNEN-0006PV-Sb for qemu-devel@nongnu.org; Tue, 17 Dec 2019 19:30:25 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:39153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihNEN-0005Ph-9l for qemu-devel@nongnu.org; Tue, 17 Dec 2019 19:30:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Message-Id:Subject:Date:Cc:To:From:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Content-ID: Content-Description; bh=GgiXB8p8Xd/QoPlYaJiPVPesefRwdQros/8Qb85D0+4=; b=C1m+U 13LUJaLnInujhKDG80CG/9j/tsX37UtqVvC7futfXH63kfcxzTFYzjWQ9t+eLsO21C8xG3p3RCN/P sz+qnK8UjbJSC/vczDg/Rl8oUMzZdfMyLtb1HU2AD/7VMVvvYBunVIeGa1bIr0H/VnbISjTAYvjef 0FtZHQTsHdtj+PizxnpUuCZFtMQlx9Sf9ysaosEkBCyOQuQ4boSrkVd5712Y6RK6xlsLrnug92Vpe qhDGeUOFxaKpVdorbovrI9L0yqicfNJ97b0uG9A1A+bV/B/uxyyKDqWCOLYkhv39zU56/XFjDP2C1 94j9WXsoXncSo8cCIq+W9Ei3hGqNA==; From: Christian Schoenebeck To: qemu-devel@nongnu.org Cc: Greg Kurz Date: Mon, 16 Dec 2019 15:43:39 +0100 Subject: [PATCH 2/9] 9pfs: validate count sent by client with T_readdir Message-Id: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 91.194.90.13 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" A good 9p client sends T_readdir with "count" parameter that's sufficiently smaller than client's initially negotiated msize (maximum message size). We perform a check for that though to avoid the server to be interrupted with a "Failed to encode VirtFS reply type 41" error message by bad clients. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 520177f40c..30e33b6573 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2414,6 +2414,7 @@ static void coroutine_fn v9fs_readdir(void *opaque) int32_t count; uint32_t max_count; V9fsPDU *pdu = opaque; + V9fsState *s = pdu->s; retval = pdu_unmarshal(pdu, offset, "dqd", &fid, &initial_offset, &max_count); @@ -2422,6 +2423,13 @@ static void coroutine_fn v9fs_readdir(void *opaque) } trace_v9fs_readdir(pdu->tag, pdu->id, fid, initial_offset, max_count); + if (max_count > s->msize - P9_IOHDRSZ) { + max_count = s->msize - P9_IOHDRSZ; + warn_report_once( + "9p: bad client: T_readdir with count > msize - P9_IOHDRSZ" + ); + } + fidp = get_fid(pdu, fid); if (fidp == NULL) { retval = -EINVAL;