From nobody Sat Sep 28 20:48:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1681407530; cv=pass; d=zohomail.com; s=zohoarc; b=IQo/84SAnI+2HAQjdF+U1WElv3uVKa/U0s/LHhRyDh96Hp10cdO2FBT0sOIs6aUvkR8esG9niOEeZ4xKUL3gPOc9HS1sp8NHw/o1XQ/rcNyb2qifgz6H+LjyATf8OF6UbEVgxwqGYI0NtOekuGVPtgop3dnThWjYWK99kCLqqj0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681407530; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8DOUnV1l7YFE+Fgge1cDptrXAMS0Z5E0PBq8a/I6OGs=; b=EMDemGMI7v2R/ZHPCiq4gB+QPtnKH2PPiamO23radrLOJ9bM6zYiHDk/2RCokQiCQr/lhYoizikZXPKkiLIGtMwkSgq9JCgihEGDSWsgP+DlLX3WehISQOVXCWFlXdlXK8abzFnlpQcT+SRug8Ppkw5Lss0F/ltkk5MPXHVXC94= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1681407530780454.2505987377324; Thu, 13 Apr 2023 10:38:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.520870.808986 (Exim 4.92) (envelope-from ) id 1pn0u2-0003xL-15; Thu, 13 Apr 2023 17:38:34 +0000 Received: by outflank-mailman (output) from mailman id 520870.808986; Thu, 13 Apr 2023 17:38:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pn0u1-0003x8-Sx; Thu, 13 Apr 2023 17:38:33 +0000 Received: by outflank-mailman (input) for mailman id 520870; Thu, 13 Apr 2023 17:38:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pn0u0-0000rf-43 for xen-devel@lists.xenproject.org; Thu, 13 Apr 2023 17:38:32 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20616.outbound.protection.outlook.com [2a01:111:f400:fe5b::616]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 00b15c15-da22-11ed-8611-37d641c3527e; Thu, 13 Apr 2023 19:38:30 +0200 (CEST) Received: from BN9PR03CA0464.namprd03.prod.outlook.com (2603:10b6:408:139::19) by CH0PR12MB5106.namprd12.prod.outlook.com (2603:10b6:610:bd::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.30; Thu, 13 Apr 2023 17:38:27 +0000 Received: from BN8NAM11FT104.eop-nam11.prod.protection.outlook.com (2603:10b6:408:139:cafe::75) by BN9PR03CA0464.outlook.office365.com (2603:10b6:408:139::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.32 via Frontend Transport; Thu, 13 Apr 2023 17:38:27 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT104.mail.protection.outlook.com (10.13.177.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.32 via Frontend Transport; Thu, 13 Apr 2023 17:38:27 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 13 Apr 2023 12:38:26 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 13 Apr 2023 10:38:26 -0700 Received: from xcbayankuma41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Thu, 13 Apr 2023 12:38:25 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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" X-Inumbo-ID: 00b15c15-da22-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aH+Zr849Fo64fg+pXGsVYf5EHX5ceYm9v4BSa/xIJEgJySUpm/TpwUvcclB6UglPqEbI2T9x28+ki+kzBGxtG+hLW7e0oshtjWcOVlNt2XPxpBAgrFaM8s+wQlVNwQeU67sX13QgtJz1xqEB01dY+FKyhkZKOOiXuHBPye3I0Z77y1dA6za2TvBbqmvwRQgwuB/SNaW97xKacVXXiVQ1/Xk/4OBqkivCV3EgZSNPE2hEDu+0XUM9xFnNZopUefD8hghPBDpsXVBgtUZHCacJMEVoDsuaP9Jr7BVlojoPGtpWMLoqIiNYVRMCDK6JjqFDapz00N7PI0jX5i3aXm8yjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=8DOUnV1l7YFE+Fgge1cDptrXAMS0Z5E0PBq8a/I6OGs=; b=JdS3NgRtL+UpNBoW+sWqzDwtV9iViFx/ZYPAmtqpfFF4SokOHjj4wbTt+7YuGlJ7SdE7b/Vo5m6x7Ws2YsqpPdof+ekcrbb1p9i+4+xx3TlhvH8EYrF/2Wlx6eokrx4fu1SrNP46EXn5aXwHwAjet21IrEbLyX5VkoFy8kUmddVJ3RAg/oJEgUObHN5L3zbL1dnALhHQ8aBj5rpQasIjRDgTL1b0F+7Ie3rIcmF6+UTThd3PZweliXboJBZednVP5eZGQhanyXaTnst6PdIzIDyFxnD1eCcoFCnoqy89Pzy25pBXiI5KSzKzHt7qmAfAH4tliDQAGlL9GzVd9hTHRg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8DOUnV1l7YFE+Fgge1cDptrXAMS0Z5E0PBq8a/I6OGs=; b=MsdUC9FOjQo0KMvXQ8Yj50daQlpRrKzCmyMX4QbJhGKuw3uc/STM+JVy1JKdTKzvhO/L0770htzBZkOaReYSg956Gah8r8mgIgidudSw0Wsb+fVVY7dUkipXilMQtjoAx0rFHR6MuKyBkYH6HkseYSu3z3vyHWp6J4dDIH+UV/E= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Ayan Kumar Halder To: CC: , , , , , , , , , , Ayan Kumar Halder Subject: [XEN v5 08/10] xen/arm: domain_build: Check if the address fits the range of physical address Date: Thu, 13 Apr 2023 18:37:33 +0100 Message-ID: <20230413173735.48387-9-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230413173735.48387-1-ayan.kumar.halder@amd.com> References: <20230413173735.48387-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT104:EE_|CH0PR12MB5106:EE_ X-MS-Office365-Filtering-Correlation-Id: 94e40bd9-7988-4fb9-219f-08db3c45e389 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vaf4P9OhiNSluRFPCbbs7OSxO7iGI4TRH6O1mrpYku5q1HrBOkngH2ehaCCyjBEOjy/+E5I+zHN01gSTLz911cDtkQFw6PXLnF0ofZH/fjXysb7OqyPs3hcEEt3onqgffjqMfDIvn1xOf9XDh4U06ZqxB0ieUl2hAXCcFI8PEZuboZhgTWTXn/Q1XnPomNTiftSlFiP/vxDLRaj7qULQun1+7js0ffSkp5miloQQhGUtTYX/8AWIELNINdiuGMDU9WSly53NKyK4kntAtHASS2mnc977t7SyE9WBYne9b8aDdu0cl0UtiumfrmwN1V1ffW8G7zmNgCfNOC2PB4dyML7IqaWmtX3TfKsYqjJPk0E1I/P9+/zMG5fEafAnHVTrRazQ9KWfW0mEn++Whr7zqElqfrTQY4y/lB9BMIKNwOvCoHXLgvwaDVNefgR+j3YeDlEy7d3oheBVXRTl6rxEjt8d7IjQdlUxjOnF25cD9qkjAWxuSCjM6AXCKHJGEG+VqK2UOw5U/Ss+S0/3KzWNq1wSpyZa1Q+56FAEZrATgok8SvuLrmYJy9+CZe7vKVZ+ojyKmO3Y62CVUJ5yxj0LUzjpqvGzY1ZgjH9zGa1RMRYWObzZEkePVvhRBHKuCWz0sVBIa0YVedIQYeGx/sdik6nsG3juUJSk0o5uZbo819u+rxDppwUXD8TR6jsuwShJO9xzmEgzkcG82AwfZt8qYxqvgQusO61W7UbhOl0XEXY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(39860400002)(136003)(396003)(376002)(451199021)(46966006)(40470700004)(36840700001)(103116003)(36756003)(86362001)(41300700001)(316002)(4326008)(478600001)(8676002)(70206006)(6916009)(54906003)(70586007)(82310400005)(6666004)(7416002)(40480700001)(5660300002)(82740400003)(8936002)(2906002)(356005)(36860700001)(186003)(81166007)(83380400001)(1076003)(336012)(426003)(2616005)(26005)(47076005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2023 17:38:27.0413 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94e40bd9-7988-4fb9-219f-08db3c45e389 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT104.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5106 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1681407532784100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" handle_pci_range() and map_range_to_domain() take addr and len as uint64_t parameters. Then frame numbers are obtained from addr and len by right shif= ting with PAGE_SHIFT. The page frame numbers are saved using unsigned long. Now if 64-bit >> PAGE_SHIFT, the result will have 52-bits as valid. On a 32= -bit system, 'unsigned long' is 32-bits. Thus, there is a potential loss of value when the result is stored as 'unsigned long'. To mitigate this issue, we check if the starting and end address can be contained within the range of physical address supported on the system. If = not, then an appropriate error is returned. Also, the end address is computed once and used when required. And replaced= u64 with uint64_t. Signed-off-by: Ayan Kumar Halder --- Changes from :- v1...v4 - NA. New patch introduced in v5. xen/arch/arm/domain_build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 7d28b75517..b98ee506a8 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1637,15 +1637,23 @@ out: } =20 static int __init handle_pci_range(const struct dt_device_node *dev, - u64 addr, u64 len, void *data) + uint64_t addr, uint64_t len, void *data) { struct rangeset *mem_holes =3D data; paddr_t start, end; int res; + uint64_t end_addr =3D addr + len - 1; + + if ( addr !=3D (paddr_t)addr || end_addr !=3D (paddr_t)end_addr ) + { + printk(XENLOG_ERR "addr (0x%"PRIx64") or end_addr (0x%"PRIx64") ex= ceeds the maximum allowed width (%d bits) for physical address\n", + addr, end_addr, CONFIG_PADDR_BITS); + return -ERANGE; + } =20 start =3D addr & PAGE_MASK; - end =3D PAGE_ALIGN(addr + len); - res =3D rangeset_remove_range(mem_holes, PFN_DOWN(start), PFN_DOWN(end= - 1)); + end =3D PAGE_ALIGN(end_addr); + res =3D rangeset_remove_range(mem_holes, PFN_DOWN(start), PFN_DOWN(end= )); if ( res ) { printk(XENLOG_ERR "Failed to remove: %#"PRIpaddr"->%#"PRIpaddr"\n", @@ -2330,11 +2338,19 @@ static int __init map_dt_irq_to_domain(const struct= dt_device_node *dev, } =20 int __init map_range_to_domain(const struct dt_device_node *dev, - u64 addr, u64 len, void *data) + uint64_t addr, uint64_t len, void *data) { struct map_range_data *mr_data =3D data; struct domain *d =3D mr_data->d; int res; + uint64_t end_addr =3D addr + len - 1; + + if ( addr !=3D (paddr_t)addr || end_addr !=3D (paddr_t)end_addr ) + { + printk(XENLOG_ERR "addr (0x%"PRIx64") or end_addr (0x%"PRIx64") ex= ceeds the maximum allowed width (%d bits) for physical address\n", + addr, end_addr, CONFIG_PADDR_BITS); + return -ERANGE; + } =20 /* * reserved-memory regions are RAM carved out for a special purpose. @@ -2345,13 +2361,13 @@ int __init map_range_to_domain(const struct dt_devi= ce_node *dev, strlen("/reserved-memory/")) !=3D 0 ) { res =3D iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + paddr_to_pfn(PAGE_ALIGN(end_addr))); if ( res ) { printk(XENLOG_ERR "Unable to permit to dom%d access to" " 0x%"PRIx64" - 0x%"PRIx64"\n", d->domain_id, - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); + addr & PAGE_MASK, PAGE_ALIGN(end_addr) - 1); return res; } } @@ -2368,7 +2384,7 @@ int __init map_range_to_domain(const struct dt_device= _node *dev, { printk(XENLOG_ERR "Unable to map 0x%"PRIx64 " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, + addr & PAGE_MASK, PAGE_ALIGN(end_addr) - 1, d->domain_id); return res; } --=20 2.17.1