From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>
Subject: Re: [PATCH for-4.22] dom0less: Prevent division by zero in handle_passthrough_prop()
Date: Tue, 7 Jul 2026 18:08:14 +0200 [thread overview]
Message-ID: <e494980c-485e-4dc6-ba84-e40fd53442d6@gmail.com> (raw)
In-Reply-To: <cce2493855ce3b610a2d36cbcd149292254170aa.1783436517.git.dmytro_prokopchuk1@epam.com>
On 7/7/26 5:16 PM, Dmytro Prokopchuk1 wrote:
> A malformed provided 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:
>
> 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 '(address_cells * 2 + size_cells)' is greater
> than zero before performing the division. If it is zero, log an error
> message and return -EINVAL.
>
Fix tag is missed.
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
> ---
> 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..6796851844 100644
> --- a/xen/common/device-tree/dom0less-build.c
> +++ b/xen/common/device-tree/dom0less-build.c
> @@ -154,6 +154,13 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo,
>
> /* xen,reg specifies where to map the MMIO region */
> cell = (const __be32 *)xen_reg->data;
> +
> + if ( (address_cells * 2 + size_cells) == 0 )
Considering that this calculation happens second time here ...
> + {
> + printk(XENLOG_ERR "Invalid address/size cells combination (both 0)\n");
> + return -EINVAL;
> + }
> +
> len = fdt32_to_cpu(xen_reg->len) / ((address_cells * 2 + size_cells) *
> sizeof(uint32_t));
... I think it would be nice to calculate that once.
Generally I am okay to not declare local separate variable for these
calculations.
With adding Fix tag:
Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Thanks.
~ Oleksii
next prev parent reply other threads:[~2026-07-07 16:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 15:16 [PATCH for-4.22] dom0less: Prevent division by zero in handle_passthrough_prop() Dmytro Prokopchuk1
2026-07-07 16:08 ` Oleksii Kurochko [this message]
2026-07-08 6:15 ` Jan Beulich
2026-07-08 17:04 ` Dmytro Prokopchuk1
2026-07-09 6:57 ` Jan Beulich
2026-07-09 7:51 ` Orzel, Michal
2026-07-09 9:39 ` Dmytro Prokopchuk1
2026-07-09 9:43 ` Orzel, Michal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e494980c-485e-4dc6-ba84-e40fd53442d6@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=bertrand.marquis@arm.com \
--cc=dmytro_prokopchuk1@epam.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.