From nobody Sat May 11 18:11:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1710982493752215.06817047910033; Wed, 20 Mar 2024 17:54:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E7C041DE3; Wed, 20 Mar 2024 20:54:51 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7F2141CFF; Wed, 20 Mar 2024 20:53:39 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 828951D18; Wed, 20 Mar 2024 20:53:35 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A10851CFF for ; Wed, 20 Mar 2024 20:53:33 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-_GFwwQ2APfSsHvqvnFT7Eg-1; Wed, 20 Mar 2024 20:53:29 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53BFE3800C30; Thu, 21 Mar 2024 00:53:29 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AD21492BD4; Thu, 21 Mar 2024 00:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: _GFwwQ2APfSsHvqvnFT7Eg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Subject: [PATCH] remote: check for negative array lengths before allocation Date: Thu, 21 Mar 2024 00:53:23 +0000 Message-ID: <20240321005323.329683-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: BKRQXPLPC6B7FLHJXSBQYW7HNDEBW6RJ X-Message-ID-Hash: BKRQXPLPC6B7FLHJXSBQYW7HNDEBW6RJ X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Alexandr Shashkin , Alexander Kuznetsov X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1710982495591100001 While the C API entry points will validate non-negative lengths for various parameters, the RPC server de-serialization code will need to allocate memory for arrays before entering the C API. These allocations will thus happen before the non-negative length check is performed. Passing a negative length to the g_new0 function will usually result in a crash due to the negative length being treated as a huge positive number. This was found and diagnosed by ALT Linux Team with AFLplusplus. CVE-2024-2494 Found-by: Alexandr Shashkin Co-developed-by: Alexander Kuznetsov Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- src/remote/remote_daemon_dispatch.c | 65 +++++++++++++++++++++++++++++ src/rpc/gendispatch.pl | 5 +++ 2 files changed, 70 insertions(+) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index aaabd1e56c..01dcac4b12 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -2291,6 +2291,10 @@ remoteDispatchDomainGetSchedulerParameters(virNetSer= ver *server G_GNUC_UNUSED, if (!conn) goto cleanup; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -2339,6 +2343,10 @@ remoteDispatchDomainGetSchedulerParametersFlags(virN= etServer *server G_GNUC_UNUS if (!conn) goto cleanup; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -2497,6 +2505,10 @@ remoteDispatchDomainBlockStatsFlags(virNetServer *se= rver G_GNUC_UNUSED, goto cleanup; flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_BLOCK_STATS_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -2717,6 +2729,14 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServer *ser= ver G_GNUC_UNUSED, if (!(dom =3D get_nonnull_domain(conn, args->dom))) goto cleanup; =20 + if (args->ncpumaps < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("ncpumaps must be n= on-negative")); + goto cleanup; + } + if (args->maplen < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maplen must be non= -negative")); + goto cleanup; + } if (args->ncpumaps > REMOTE_VCPUINFO_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("ncpumaps > REMOTE_= VCPUINFO_MAX")); goto cleanup; @@ -2811,6 +2831,11 @@ remoteDispatchDomainGetEmulatorPinInfo(virNetServer = *server G_GNUC_UNUSED, if (!(dom =3D get_nonnull_domain(conn, args->dom))) goto cleanup; =20 + if (args->maplen < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maplen must be non= -negative")); + goto cleanup; + } + /* Allocate buffers to take the results */ if (args->maplen > 0) cpumaps =3D g_new0(unsigned char, args->maplen); @@ -2858,6 +2883,14 @@ remoteDispatchDomainGetVcpus(virNetServer *server G_= GNUC_UNUSED, if (!(dom =3D get_nonnull_domain(conn, args->dom))) goto cleanup; =20 + if (args->maxinfo < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo must be no= n-negative")); + goto cleanup; + } + if (args->maplen < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo must be no= n-negative")); + goto cleanup; + } if (args->maxinfo > REMOTE_VCPUINFO_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo > REMOTE_V= CPUINFO_MAX")); goto cleanup; @@ -3096,6 +3129,10 @@ remoteDispatchDomainGetMemoryParameters(virNetServer= *server G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -3156,6 +3193,10 @@ remoteDispatchDomainGetNumaParameters(virNetServer *= server G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_NUMA_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -3216,6 +3257,10 @@ remoteDispatchDomainGetBlkioParameters(virNetServer = *server G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -3277,6 +3322,10 @@ remoteDispatchNodeGetCPUStats(virNetServer *server G= _GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_NODE_CPU_STATS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -3339,6 +3388,10 @@ remoteDispatchNodeGetMemoryStats(virNetServer *serve= r G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_NODE_MEMORY_STATS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -3514,6 +3567,10 @@ remoteDispatchDomainGetBlockIoTune(virNetServer *ser= ver G_GNUC_UNUSED, if (!conn) goto cleanup; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_BLOCK_IO_TUNE_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -5081,6 +5138,10 @@ remoteDispatchDomainGetInterfaceParameters(virNetSer= ver *server G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_DOMAIN_INTERFACE_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; @@ -5301,6 +5362,10 @@ remoteDispatchNodeGetMemoryParameters(virNetServer *= server G_GNUC_UNUSED, =20 flags =3D args->flags; =20 + if (args->nparams < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams must be no= n-negative")); + goto cleanup; + } if (args->nparams > REMOTE_NODE_MEMORY_PARAMETERS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"= )); goto cleanup; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 5ce988c5ae..c5842dc796 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1070,6 +1070,11 @@ elsif ($mode eq "server") { print "\n"; =20 if ($single_ret_as_list) { + print " if (args->$single_ret_list_max_var < 0) {\n"; + print " virReportError(VIR_ERR_RPC,\n"; + print " \"%s\", _(\"max$single_ret_list_= name must be non-negative\"));\n"; + print " goto cleanup;\n"; + print " }\n"; print " if (args->$single_ret_list_max_var > $single_ret_li= st_max_define) {\n"; print " virReportError(VIR_ERR_RPC,\n"; print " \"%s\", _(\"max$single_ret_list_= name > $single_ret_list_max_define\"));\n"; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org