[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.22 v4] dom0less: Prevent division by zero in handle_passthrough_prop()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Thu, 9 Jul 2026 11:47:58 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lhXS+HC0sNwJXbPKhcfnfjlNmOwyK7UUE/S0KoD6FdE=; b=xPLczhyTCcuvQpv9kWG8zwO0vpfVFm3jFY0szwJQoYcFAf8Lsu1OjrsvyorPmQeWUpJAjnLWsfQjmlwk5FJMVJaWlUkC8HWFpHDxI8Wk13zml0GOKn/xlIxC0qYioojPnr4ho37MK3S2uu/Oc2WkVPyWLfdAMDXlJU2UbihfHa8nHg5TzeaOegW8O4OTgzY7dXMdWqjGNTEBbycZ6zzaFLJ2IEBzWBLJl2Q1KPb8u5wWs7XPZJ9T8QsqdElbYaQiJAbRfmWkn08DSQ8GKoQHoHVeLjDEY8TQ35Jo06A2zA5FEtIXSTyfF6AsjeKRyoeXays0NviYHr8HXYRzKaQRVg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lQA75k9Sk/h1nHVHOD6S+YSUzaxNt6G41OGFeXDyCCYqK550PG5WNVXmdK1nqvL1IF6PkXJbPbG3CY3MpezYlhFrEdTzYglXWJZjeyu50pRgeEm5aFJcImeq7AARE8S4Vr9s3+tgCxt1XEH9DEFTQL2mbKfIQSWbW09CVrMWC3wpB3JK1x5DxPUjMVBryggUwFiYvqFwzNjJqATtEIxys9KQU8i8YTPykMLj4oKWk178o0aDPSomAO1tgKuqTHVOW9LqH13reNWoRlTCsiaIUiwssrmDlB3/jjebIfJGGkzb6+b+1Kj28U3d1lkVONJe3q624AOMhpQQx3lTHX0zZQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Thu, 09 Jul 2026 11:48:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdD5jJCDOEjONIbkmZhLZ5uEYFYw==
  • Thread-topic: [PATCH for-4.22 v4] dom0less: Prevent division by zero in handle_passthrough_prop()

A malformed partial DTB specifying both '#address-cells = <0>' and
'#size-cells = <0>' causes '(address_cells * 2 + size_cells)' to
evaluate to 0. This sum is subsequently used as a divisor when
calculating the number of regions in the 'xen,reg' property inside
handle_passthrough_prop():

    len = fdt32_to_cpu(xen_reg->len) / ((address_cells * 2 + size_cells) *
                                        sizeof(uint32_t));

This leads to a division by zero exception in the Xen hypervisor during
boot, causing a hypervisor panic/crash.

Fix this by validating that both 'address_cells' and 'size_cells'
are within the valid range of [1, 2] at the read side in scan_pfdt_node()
immediately after they are parsed. Any invalid cell size combination is
safely rejected early with an error message and return -EINVAL.

Fixes: 9ce974c47588 ("xen/arm: assign devices to boot domains")
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Changes in v4:
- put the expressions in brackets
- improve the message as Andrew suggested
---
 xen/common/device-tree/dom0less-build.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/xen/common/device-tree/dom0less-build.c 
b/xen/common/device-tree/dom0less-build.c
index eacfd93087..47465a3609 100644
--- a/xen/common/device-tree/dom0less-build.c
+++ b/xen/common/device-tree/dom0less-build.c
@@ -341,6 +341,13 @@ static int __init scan_pfdt_node(struct kernel_info 
*kinfo, const void *pfdt,
     size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells",
                                      DT_ROOT_NODE_SIZE_CELLS_DEFAULT);
 
+    if ( (address_cells < 1) || (address_cells > 2) ||
+         (size_cells < 1) || (size_cells > 2) )
+    {
+        dprintk(XENLOG_ERR "Invalid address_cells %u or size_cells %u\n");
+        return -EINVAL;
+    }
+
     node_next = fdt_first_subnode(pfdt, nodeoff);
     while ( node_next > 0 )
     {
-- 
2.43.0



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.