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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Thu, 9 Jul 2026 10:13:29 +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=/o8sTq8hzBqS17jGbJrLIxEROCwYZI7Po+zLWplBApI=; b=BVgBofyHL74skSwJg3zwGt6SD0OfEy/nJX530x1E1lqDllBMLmB9+e9bO97mpf2x2E+v0oi6hCfqNR6j0+B+rhevbu0dVEewA5yc9aLfPoU7t15SGLOaUgi/XWi3GCmjpSOqvX+taCenXEAfNLPCxeTJHwrMa3pUPqA4q5w4lmZcaE+iEF2p+9eKZm0nX8o677mncsRUVgZ1fILCOjy7XjXpR+u0kdWf5xRAaoSVZjHrKmLefaEKYQME9/yobGXSCezHgJ4BMty4HgCy0mbRTdDG6lAapR4YfQRehqc09XiZ/edQ1q2bBZ0K6IJoPK3IzJhnp9b3+Ms0wWXARVFh1A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VMxItlvQ9fLyBgbdX6wHpGTMEZUewzUIX5uMrkvXlQFtmnaGi+wNaz6eoIL98U4+efKsipCUxcVBNcpP7MZUbXAon7Fb59ROjVqIHexmn1skCN9ZfQAsomTEbxB2shJ6FHueknlbVy41ameSWm7bRDS6qRmCWn0TpfKF0KQCIKzKtdAJCa9z0ENXmzZ50lyBPffobmTeFt0BwMES21MeQlQbAIo4wl4O/nHNIWE/tXTf2JHxmd/3JYQFJ/OD/UYf9ktf+DrcvqGcuvyl0FQRjIbTDWVcf7/9N31j9TMJyPhcI1AfCYgxCZVqTTv+4hbGqwjTFzriTOhgYkwQlwGFeQ==
  • 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: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 09 Jul 2026 10:13:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdD4d7qU530mHLc0yhuTdjB7BCxbZk8ayAgAAGcAA=
  • Thread-topic: [PATCH for-4.22 v3] dom0less: Prevent division by zero in handle_passthrough_prop()


On 7/9/26 12:50, Jan Beulich wrote:
> On 09.07.2026 11:44, Dmytro Prokopchuk1 wrote:
>> 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 v3:
>>   - use Michal's idea for placing that check into other place
>>   - reword commit message
>> ---
>>   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..179a2b88aa 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/size cells combination\n");
> 
> Perhaps just for my own education: Is it really "invalid", or merely
> "unsupported" / "unrecognized"? (I can see 0 being possibly invalid, but
> it looks less clear for values above 2.)
> 
> Jan

Yeah... In DT Spec the values 0 and 3 are valid, actually.
Here it's Xen's limitation in implementation. So, "unsupported" is the 
most accurate description.

Well, also I see that this function has many silent returns. And only 
one resulting error message at the end:

     printk("Device tree generation failed (%d).\n", ret);

Maybe just drop that message?

 


Rackspace

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