From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F0AAC43458 for ; Thu, 9 Jul 2026 06:57:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.1357556.1611931 (Exim 4.92) (envelope-from ) id 1whihO-00072s-A4; Thu, 09 Jul 2026 06:57:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1357556.1611931; Thu, 09 Jul 2026 06:57:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1whihO-00072l-7P; Thu, 09 Jul 2026 06:57:30 +0000 Received: by outflank-mailman (input) for mailman id 1357556; Thu, 09 Jul 2026 06:57:29 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1whihM-00072c-Qh for xen-devel@lists.xenproject.org; Thu, 09 Jul 2026 06:57:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1whihK-00DjDB-Gl for xen-devel@lists.xenproject.org; Thu, 09 Jul 2026 08:57:26 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a4f4642-5cb7-0a2a0a5109dd-0a2a4508c0bc-48 for ; Thu, 09 Jul 2026 08:57:26 +0200 Received: from [209.85.221.45] (helo=mail-wr1-f45.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6a4f4656-edec-0a2a45080019-d155dd2db8d4-3 for ; Thu, 09 Jul 2026 08:57:26 +0200 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-47362928f65so444885f8f.2 for ; Wed, 08 Jul 2026 23:57:26 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0f21328sm49655932f8f.32.2026.07.08.23.57.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jul 2026 23:57:25 -0700 (PDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:From:Content-Language:References:Cc:To:Subject:User-Agent:MIME-Version:Date:Message-ID" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1783580246; x=1784185046; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+k0C3q49/KKBZ0MnIjWWzf2c4PRxgP3HEjn68PXLNqs=; b=VMFGMOXB2/FCyIF8ThnYyHkN4Uj6vj759dPoWwCf/EeCSzOinbnwoqK2m8x2fTUqCM DFkgakVvSO+ZLOB2omU8uLD71R06qlq5HuHPrWxHULlNN8kLRd2p235YqCaGZvQTRwEA kbRMaKA1zaLn6wQgeNWNhhNvJTKapeFTwhSHG3v7BupSdMPDBX3kLGCXmSlabuayzjLU hf/HgE0ktbQMjAXIpJekaxTa3h/Cmfe8Rqs9/x9vS7oJyqZGhB+oN5rb51CbaSnLgBtb xvwU5ZTLO9kAleHHHtb9dG3WLnRBSxfbxAH2ca7IiNI5K0Q7FlSLZ7aS2DVlpWTH0KZ+ U8kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783580246; x=1784185046; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+k0C3q49/KKBZ0MnIjWWzf2c4PRxgP3HEjn68PXLNqs=; b=p351tEBBOd7UIPvi9abXoN95uDK2E++BM66M+I66wYYZ+/zCl18BgDzEWtR7XrDPTG /LzuuDq4zpUpfJMFkWVsokM+kr6dKYpoNJ1TZCcSUjMu9AHIZ/u/OdBsEfkcNVT10Zet WxCJWkzkP1lCRtt44LWzvthvLe3+s8MSaH+VRuhwnxh4LLItWPNtWIwWzpjv5VB16UZd DiQ+ZGf7+H2KRbcl3HauJwKvRksa5TD5uB7A77B6hKqK9iQaEuxHSHF2tFPKm1mFMBne 9OvNEN3T9qDXZCn+I1kfO92zPa3HE/JcNrdXuRlCmmOhG4l5WSBx1oC1ajT6PF1n4GhB rjlA== X-Forwarded-Encrypted: i=1; AHgh+RpitZA8ExqipRORKq5zXS8BuMOI3/e8lYvBv0F4PfgD6kt8z+8WdWswewV395Uzvbh1wYHm1bf+xmg=@lists.xenproject.org X-Gm-Message-State: AOJu0YyScCe00kqouBkw2c9jFjM+m6xlWfM50oy4moIJHMOgF4VUnrkk RyBR0gDNbhcJjUHURVmLSjjJGa2/uqLFYEDGX8linGaxhv8SedGpDemS6MYFiVn//w== X-Gm-Gg: AfdE7clxKfGtqvBN1n70FSzlB8F5YM7EWpDMOc7roplYRRJfiCgHfLvnC4P3+u2N30N emWh2ZWkkrLw2LMaPr1Za+Q7QCtqOYn6U/CV9s+v3agAMkl4H/vdXv8FXxymlqQ2662rXDbvV6h TCHRJBWbiyPHRdBipEgEWfuYfMlgXtpXe82pt+Trhj3O/jMkVQU5TAHqlTwOtni+eNP4hQsvklP hclTGdLsOgj/m8Fj6ayVARC3m6vGjEnSnSjJyzBOv+jIUnx9dFwIWJAR1jboK44SsHOBbY8+QLE KnPeo4dr573ivfjNWVxpvqr3opArMBcezxrwNwgaQ2Oqw/k2UDDTMJhoiGQhxtqGyfr5+6Kgc7w ULgizMGJEcCfbMFPnUH+29Oi2bMikmU368n7AOMNwbm6PyjnjFoTkNFRYXKNIiiV/Q/7h8hxF5p 1IKobiBfz2t/778GB/7yjKNpzscOlr2kddizYF4WkXzDtnlRXUzD6g1nxJcNqRh4bG1w5Ajs2WW f4I X-Received: by 2002:a05:6000:4709:b0:475:f0d1:eb69 with SMTP id ffacd0b85a97d-47df07c5accmr6149484f8f.54.1783580245776; Wed, 08 Jul 2026 23:57:25 -0700 (PDT) Message-ID: Date: Thu, 9 Jul 2026 08:57:24 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH for-4.22] dom0less: Prevent division by zero in handle_passthrough_prop() To: Dmytro Prokopchuk1 Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "xen-devel@lists.xenproject.org" , Oleksii Kurochko References: <21ec0511-bf7e-44fa-b6f6-99d9c4085eda@suse.com> Content-Language: en-US From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqS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kFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-purgate-ID: tlsNG-c1860d/1783580246-423203FC-6A1B0FFC/0/0 X-purgate-type: clean X-purgate-size: 2574 On 08.07.2026 19:04, Dmytro Prokopchuk1 wrote: > Hello Jan, > > On 7/8/26 09:15, Jan Beulich wrote: >> On 07.07.2026 18:08, Oleksii Kurochko wrote: >>> On 7/7/26 5:16 PM, Dmytro Prokopchuk1 wrote: >>>> --- 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. >> >> Hmm, originally I meant to simply stay silent here. But now that you say this, >> I'd like to express that I find this 2nd calculation of the same expression >> bogus. If the goal is to deal with both values being zero at the same time, >> check that (and nothing else). If instead the goal is to truly prevent the >> divisor expression from ending up 0, that (and not a shorter surrogate) would >> need checking. In particular, the multiplication by sizeof(uint32_t) can >> convert non-zero to zero. > Yes, you are right. Need to check whole expression. >> >> At that point the question then would be whether overflow (and hence >> truncation) in any of the involved expressions shouldn't also be detected / >> rejected. > Testing zero is useful, but not enough - the expression (address_cells * > 2 + size_cells) * sizeof(*cell) can overflow and wrap around to a small, > non-zero number. Source code analyze showed that Xen only supports cell > sizes of 1 or 2, and there is a ASSERT_UNREACHABLE() in dt_read_number() > which prevents from using wrong cell values in DEBUG builds. > > I would propose the next checking: > > if ( address_cells < 1 || address_cells > 2 || > size_cells < 1 || size_cells > 2 ) > { > printk(XENLOG_ERR "Invalid address/size cells combination\n"); > return -EINVAL; > } > > This will cover zero check, and overflows. It'll need to be the maintainers of this code to judge whether this is appropriate here. Jan