From nobody Sat Apr 20 07:14:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567758808; cv=none; d=zoho.com; s=zohoarc; b=dD1FenA8fbuzgmkPt4fNjLB88FgSsNkpd555LMplf93sWVLtskzWOFlDGctG8iZuQPoJhugzkebmtyjFC1AqIaLXifptvjyL/gfnWtop8dFSef0wXe5DhdGPmcQzd1sHZmyX0xJK8FzlhhVjP6hEFsq9F/joS3r5JnEpoo2qC6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567758808; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=xqNFiPnuD43m6h2DYuUQePBoHmNB9ZjPeAimJZDTIuw=; b=h/scllEAs8uNLtMCSrP+ZwWhx26nJSoyGAYAegIqPEkgvXL7Smh2btKOnpA0w2VSaLU0UGW4/QApmMR+J3Az9/UsRPv52xt5GJ5QpN+o04rP8GTrLJOlt/2+NSnxlQ/VFydAxIgPrELzDwcJCCpU0bQS6u2ytuYjpiUuI2pl94g= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567758808539383.8724345951574; Fri, 6 Sep 2019 01:33:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB42E30860A8; Fri, 6 Sep 2019 08:33:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B29BA5C1D8; Fri, 6 Sep 2019 08:33:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2B4591802217; Fri, 6 Sep 2019 08:33:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x868XIZ3004177 for ; Fri, 6 Sep 2019 04:33:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id BDE8C5C1D8; Fri, 6 Sep 2019 08:33:18 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 471865C1D4 for ; Fri, 6 Sep 2019 08:33:15 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 6 Sep 2019 10:33:15 +0200 Message-Id: <64307faba8f8ff0a611a1f621914f85ac13e2f4d.1567758795.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: qapi: Limit traversal depth for QAPI schema queries X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 06 Sep 2019 08:33:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Implicitly the query depth is limited by the length of the QAPI schema query, but 'alternate' and 'array' QAPI meta-types don't consume a part of the query string thus a loop on such types would get our traversal code stuck in an infinite loop. Prevent this from happening by limiting the nesting depth to 1000. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_qapi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c index 0226d6c659..93fcae0d44 100644 --- a/src/qemu/qemu_qapi.c +++ b/src/qemu/qemu_qapi.c @@ -74,9 +74,23 @@ struct virQEMUQAPISchemaTraverseContext { virHashTablePtr schema; char **queries; virJSONValuePtr returnType; + size_t depth; }; +static int +virQEMUQAPISchemaTraverseContextValidateDepth(struct virQEMUQAPISchemaTrav= erseContext *ctxt) +{ + if (ctxt->depth++ > 1000) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("possible loop in QMP schema")); + return -1; + } + + return 0; +} + + static void virQEMUQAPISchemaTraverseContextInit(struct virQEMUQAPISchemaTraverseConte= xt *ctxt, char **queries, @@ -329,6 +343,9 @@ virQEMUQAPISchemaTraverse(const char *baseName, const char *metatype; size_t i; + if (virQEMUQAPISchemaTraverseContextValidateDepth(ctxt) < 0) + return -2; + if (!(cur =3D virHashLookup(ctxt->schema, baseName))) return -2; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list