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

Re: [PATCH v6] dom0less: Prevent division by zero in handle_passthrough_prop()


  • To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Mon, 13 Jul 2026 09:21:33 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=epam.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=FW5Q+q2Sz41w6qLWwrXDZpRQBA2Xo1Udr7mE4Mmtqf8=; b=i/ur0t2Q0AFA0mtkAdqlYKYhNXxgyNLUcxpHsTu4qB6WJ1DzMeVdqy5NsNMyxJalAMYN7qtE+TKU7EBgN8o8LY3ny3OINAChCcNLAwKcOUfw2ptc0IOfm/fD2TmIjNykki23OkyVNClOgLBPukdVH/cg11qkkd+X2BR04kOeXLlSnFKg2aw3zdUq7GbBGmQhLRkVrengZ44qKt9rjgb1ZX5tBGod7zyYk26ax6o/wFUDRYuLTAd8HMGDNB5ZXV3aBCN6bdq6Jq7+drw09QeC9KRiupG++AUojRbuAOuWpvJttqRoRPrFu4owguZJFraQjgGWhCl/GxkIN0fOjRUvYA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f+GF8xJ9UWbIwDPH/gt2dv/b3igvaOU9OsqQ1WYezntk7i+b4zqKmqwiXEZYSk9G/T571j5vReajAbvCcY4Ce329XOGBzqO+UF/IXKN6ylqMo47nTu5f9D3RxEUvlnBdHh2ysCxiWSroVofSkuOGnr4QlfJqGZctlVzK/GvUkUje8/9xkGsVpgkwlX1R7CPQpC0HDqjiSDJuJg11l4NzQrpuU1kgsZb839THRLFuJBtVmbj8lRiInb25aQ7k/6TUwLskfLqVNKTi7C6AO5uIHRzaOyBbW25T9YUGetFQ7NHOShDHInyMJ+BHHULh2WtMWxz7Ez7Zqjl3+adPMp+ylw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=amd.com header.i="@amd.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, "Oleksii Kurochko" <oleksii.kurochko@xxxxxxxxx>
  • Delivery-date: Mon, 13 Jul 2026 07:22:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 12-Jul-26 13:56, 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 range of [1, 2] at the top of handle_passthrough_prop().
> Any invalid cell size combination is safely rejected early with an error
> message and return -EINVAL.
> 
> Furthermore, update handle_passthrough_prop() to use the sizeof(*cell)
> instead of sizeof(uint32_t).
> 
> Fixes: 9ce974c47588 ("xen/arm: assign devices to boot domains")
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

You dropped "for-4.22" subject prefix. Was that intentional (you had it until
now)?. If not, please provide pros/cons for taking it into 4.22 and don't forget
to CC Oleksii (doing so now). It is not a critical bug and it's been with us for
a while now. That said, the fix is very simple and unharmful.

~Michal

> ---
> Changes in v6:
> - move cells check at the top of handle_passthrough_prop() with a comment
> - reword commit message
> - replace sizeof(uint32_t) with sizeof(*cell) (use expression instead of type)
> Test CI pipeline:
> https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2667596761
> ---
>  xen/common/device-tree/dom0less-build.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/common/device-tree/dom0less-build.c 
> b/xen/common/device-tree/dom0less-build.c
> index eacfd93087..9513c1c837 100644
> --- a/xen/common/device-tree/dom0less-build.c
> +++ b/xen/common/device-tree/dom0less-build.c
> @@ -152,10 +152,23 @@ static int __init handle_passthrough_prop(struct 
> kernel_info *kinfo,
>              return -ENOMEM;
>      }
>  
> +    /*
> +     * xen,reg holds flat host/guest physical addresses and sizes, so the
> +     * inherited #address-cells/#size-cells must each be 1 or 2. This also
> +     * guards the len division below against a zero or wrapped divisor.
> +     */
> +    if ( (address_cells < 1) || (address_cells > 2) ||
> +         (size_cells < 1) || (size_cells > 2) )
> +    {
> +        printk(XENLOG_ERR "Invalid address_cells %u or size_cells %u\n",
> +               address_cells, size_cells);
> +        return -EINVAL;
> +    }
> +
>      /* xen,reg specifies where to map the MMIO region */
>      cell = (const __be32 *)xen_reg->data;
>      len = fdt32_to_cpu(xen_reg->len) / ((address_cells * 2 + size_cells) *
> -                                        sizeof(uint32_t));
> +                                        sizeof(*cell));
>  
>      for ( i = 0; i < len; i++ )
>      {




 


Rackspace

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