From nobody Wed Jan 15 10:02:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) 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 172492096708048.40965862097937; Thu, 29 Aug 2024 01:42:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E7BE212D6; Thu, 29 Aug 2024 04:42:45 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1270B1294; Thu, 29 Aug 2024 04:42:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1F7B9E97; Thu, 29 Aug 2024 04:42:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B1F44E97 for ; Thu, 29 Aug 2024 04:42:17 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-xVPpp92YOmmLwLKTTfvIDA-1; Thu, 29 Aug 2024 04:42:16 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6413A1955F6A for ; Thu, 29 Aug 2024 08:42:15 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.24]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4638F1956052 for ; Thu, 29 Aug 2024 08:42:14 +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.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724920937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0R3UxdFpA1yCH/mQgfEhN0DyeDvbF9CLPIwSzZ0icy8=; b=cfZm8o8NhpkatWMf9eZxVa6iBMUGOmzlstqIx2z1/V6Ccw6JDu9ZyxDbuLLBg+FgMcFvNr MDsnFyaNrPHiWrAqyMBdu6u4eb03I0nfMy56wiblyrMiEl2u/he+fdwqGf0gMYwx7Jefr7 Qi+4tKLsclGk3p0W7+QCLFZdgswQx2A= X-MC-Unique: xVPpp92YOmmLwLKTTfvIDA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH (pushed)] udevListInterfaces: Honour array length for zero-length NULL arrays (CVE-2024-8235) Date: Thu, 29 Aug 2024 10:42:12 +0200 Message-ID: <8dfb12cb77996519901b8d52c754ab564ebd10e8.1724920886.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UM3N4G3NBS52TOYIV7K7Q34EM5CXZ3KH X-Message-ID-Hash: UM3N4G3NBS52TOYIV7K7Q34EM5CXZ3KH X-MailFrom: pkrempa@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 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724920968348116600 Content-Type: text/plain; charset="utf-8" The refactor of 'udevListInterfacesByStatus()' which attempted to make it usable as backend for 'udevNumOfInterfacesByStatus()' neglected to consider the corner case of 'g_new0(..., 0)' returning NULL if the user actually requests 0 elements. As the code was modified to report the full number of interfaces in the system when the list of names is NULL, the RPC code would be asked to serialize a NULL-list of interface names with declared lenth of 1+ causing a crash. To fix this corner case we make callers pass '-1' as @names_len (it's conveniently an 'int' due to RPC type usage) if they don't wish to fetch the actual list and convert all decisions to be done on @names_len being non-negative instead of @names being non-NULL. CVE-2024-8235 Fixes: bc596f275129bc11b2c4bcf737d380c9e8aeb72d Resolves: https://issues.redhat.com/browse/RHEL-55373 Reported-by: Yanqiu Zhang Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/interface/interface_backend_udev.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interfa= ce_backend_udev.c index e1a50389c9..48eacdcdc2 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -143,12 +143,13 @@ udevGetDevices(struct udev *udev, virUdevStatus statu= s) * * @conn: connection object * @names: optional pointer to array to be filled with interface names - * @names_len: size of @names + * @names_len: size of @names, -1 if only number of interfaces is required= (@names is then ignored) * @status: status of interfaces to be listed * @filter: ACL filter function * * Lists interfaces with status matching @status filling them into @names = (if - * non-NULL) and returns the number of such interfaces. + * @names_len is positive, caller is expected to pass a properly sized arr= ay) + * and returns the number of such interfaces. * * In case of an error -1 is returned and no interfaces are filled into @n= ames. */ @@ -189,7 +190,7 @@ udevListInterfacesByStatus(virConnectPtr conn, g_autoptr(virInterfaceDef) def =3D NULL; /* Ensure we won't exceed the size of our array */ - if (names && count >=3D names_len) + if (names_len >=3D 0 && count >=3D names_len) break; path =3D udev_list_entry_get_name(dev_entry); @@ -204,7 +205,8 @@ udevListInterfacesByStatus(virConnectPtr conn, def =3D udevGetMinimalDefForDevice(dev); if (filter(conn, def)) { - if (names) + /* Fill the array only if caller want's it */ + if (names_len >=3D 0) names[count] =3D g_strdup(name); count++; } @@ -224,7 +226,7 @@ udevConnectNumOfInterfaces(virConnectPtr conn) if (virConnectNumOfInterfacesEnsureACL(conn) < 0) return -1; - return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_ACTIVE, + return udevListInterfacesByStatus(conn, NULL, -1, VIR_UDEV_IFACE_ACTIV= E, virConnectNumOfInterfacesCheckACL); } @@ -247,7 +249,7 @@ udevConnectNumOfDefinedInterfaces(virConnectPtr conn) if (virConnectNumOfDefinedInterfacesEnsureACL(conn) < 0) return -1; - return udevListInterfacesByStatus(conn, NULL, 0, VIR_UDEV_IFACE_INACTI= VE, + return udevListInterfacesByStatus(conn, NULL, -1, VIR_UDEV_IFACE_INACT= IVE, virConnectNumOfDefinedInterfacesChec= kACL); } --=20 2.46.0