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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40D36C636D3 for ; Mon, 6 Feb 2023 16:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229588AbjBFQvf (ORCPT ); Mon, 6 Feb 2023 11:51:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjBFQvc (ORCPT ); Mon, 6 Feb 2023 11:51:32 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930572A16D; Mon, 6 Feb 2023 08:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675702275; x=1707238275; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=gc1RiiisLLIHoU8Vp6PWUdegZGo7AQSj8h8EARNwiN4=; b=BfgEg5xZvbc0XBolTpWtj4IUPqJoHb+1VbPkQqkH/sqkk8P5l2cDhbf2 Itdmq6FzYy3SJk4CaRH8/ZdztkeAhnH/tZz92GeQIQEZ6TXbVP6vJ1FfM SaUuOxSKA0cjAMEkOHgAcjasf5E9SE9r+otqOcnrzqcdUHeELTaYJtAME hxndaR12mys46AJLdBYtsv0WqZPFmkHgbhXccMvvCJxYsgYtI3zLKczbJ 79nZ4FeXCnGlAvBixPyBhRzYg7zwapp4yIm3CR0YHNZ9IjNZzEPOHbCA+ NZgK3Om29dYG+k4aeyKGpo5BtngIXbulD456kXxTU9JKGyVuJ9x0X/V2r Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="393851725" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="393851725" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:50:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="698896470" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="698896470" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga001.jf.intel.com with ESMTP; 06 Feb 2023 08:50:40 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 6 Feb 2023 08:50:39 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Mon, 6 Feb 2023 08:50:39 -0800 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.47) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Mon, 6 Feb 2023 08:50:39 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MfLCWlPFUbJPFWjlcU3n4qvH2vQdjXh5+3LvbzfJ+xggPr78AdA3HzoxABnbX8D0qKgY6J8+3ESj3ua498lkFhN7cRjlibD0w5KOdFEG7lNWI1P9BwJfxxutnoPjK24IUKiPbNvGY6aFsPgXbvi0hA00+FJ0hviM0oiEqwyhWsH5LQ/vPXHyOg3LyLL46ILCl17SKuOTmrlYkJQI6/irmgeZFWHyjmBOMT6QneUFV5zIu8R0xXXZ5FtG+POeug0ySh3cU1MI9tdL1ydpQFvzJyFPDqJpak29zheIC9nrir+sJ0TvVafPoIHu/ZzUiE8Bn283RWFnm2ic4H1itT0OxQ== 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=5GTURChVqvyqluWyn/G7fxcX/RahDfm0Eh+8VH08sL4=; b=dJ6XORGe+iXr86nbChiO/bJ5u/eRK0UdAmEBOGvjiQ2hE8rJjk6T0xnksF7pE1QVFHcvKRsQXhcVdPwhA757wwzUGTkkjyF1k6xDsG3x11equww6msn8eQXE+wefXa4SYG7reWMnK0nO0logRxZ6Du4s/olTjmqw2vnAkt0WJRCDFGA3jUjR0ZlxKaSEub8T9Wxzv9G8JGzUgVovaT8XWkujA8zVNfDjogxUKRqbIaH4ADXMHGSCPkB0hXeuvIE5UrLhE/f8WVYzo7rCLMpnYYFCuQmYz/M6xxFiyW/bJX7+L7MDX1NdE+d1tYB/bn/PBZ70b57aviU+2v9yT1Jakw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM5PR11MB1899.namprd11.prod.outlook.com (2603:10b6:3:10b::14) by CH0PR11MB5491.namprd11.prod.outlook.com (2603:10b6:610:d6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Mon, 6 Feb 2023 16:50:36 +0000 Received: from DM5PR11MB1899.namprd11.prod.outlook.com ([fe80::d151:74c0:20d6:d5fc]) by DM5PR11MB1899.namprd11.prod.outlook.com ([fe80::d151:74c0:20d6:d5fc%6]) with mapi id 15.20.6064.034; Mon, 6 Feb 2023 16:50:36 +0000 Message-ID: <777498f0-9a0f-6ff7-ecc6-9fc53e8c558d@intel.com> Date: Mon, 6 Feb 2023 08:50:31 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.4.2 Subject: Re: [PATCH] fpga: dfl-afu-region: Add overflow checks for region size and offset Content-Language: en-US To: , Wu Hao CC: Tom Rix , Moritz Fischer , Xu Yilun , , References: <20230206054326.89323-1-k1rh4.lee@gmail.com> From: Russ Weight In-Reply-To: <20230206054326.89323-1-k1rh4.lee@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MW4PR04CA0125.namprd04.prod.outlook.com (2603:10b6:303:84::10) To DM5PR11MB1899.namprd11.prod.outlook.com (2603:10b6:3:10b::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR11MB1899:EE_|CH0PR11MB5491:EE_ X-MS-Office365-Filtering-Correlation-Id: 311fe19e-39c4-4152-aa3f-08db08624518 X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +YI109zP7LfHfBpdEJLYl1JnklO2jmie8p1SzL+WaLwfW6OLEr1DEDZXIZozn4UEozir4WpTNYBacb+ABA4+pfS/uM/VJgEs2+f/IwEPofH3T0qFU2p3DxdKaPr0TuI3upzlQIMDATdXzJka1lGYghAsbAVUdFxVb2WUGqqd4NfDTAdYMN6btAfV+FewloiK7M0R3KgUohtjwJ6MeBG0LdS0KbjBzFuOjAZ4JJNLEoffQJra8cyDDEEAfANKa9DuWx4vdcLkxkaRqxAaOfQ8m+pVEXmSTYhGuvpQkrLvXnN/EGkyZZVUEC6mMyqmH1RJoLl+MFESqm8+p8RDmg6j00obiO3LnUVQVzxaOfpFVYth7dAklW/KDc/ibzFNTQwHxeqBgK79S3FPRFMfoxvhJ8BGadWtxbKnssaUg4LgH+cHmZuW3sAWEFfK5fg753zSE8JN/27ZIPhAA345tvPmJKCnbZxsvjyqEDKPDqQC+732CExwO8dRhBN6gRw9fS6S4cnXFbpLeIrTXsVlzr9a5qFGD+8qoOgMBWNz5hieQCMyu4Zsy77ki8VBrbr+cMX7MpIJO4q1nGG+4l3WDO3eZOz/rsKkwB+JTTb08GxHXio+/+H1cDEC1qU3n7E2Z49iNpOGqmCM+VRvgWT1blCTFMkJs1B8WAb8Si33gzYFSvf8YgzEKCjM8JYhmCVBY7T6oYbbkUpvrKITaa/wATVxFJ74eeT1VkWuQ7cbFfhPh9s= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1899.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(39860400002)(366004)(396003)(136003)(346002)(376002)(451199018)(66476007)(82960400001)(83380400001)(66946007)(38100700002)(5660300002)(6862004)(8936002)(478600001)(66556008)(4326008)(41300700001)(8676002)(6486002)(2906002)(6666004)(6506007)(53546011)(2616005)(186003)(54906003)(6512007)(26005)(31696002)(37006003)(316002)(6636002)(36756003)(86362001)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?enROekV3eXpZdmZNYVBhbzZzdWcxTVBrbXdkNHNIRjVqelRYSDV1aWlrSlY3?= =?utf-8?B?Q2NlV3lTa056LzVCRlFadlc0cnF4TUlvOFd5Rnp3ZmhxOGtYQ2FvdU5rbnJv?= =?utf-8?B?cnd0V0hRNFBqQmhzSW5McWhXNTZ1VHNhU3JGVDJMdVBCMC8zcjY3R1NxMlNn?= =?utf-8?B?UWhIVVJEN3Y5Vj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NoVEp0ekpaQXJWNTl0?= =?utf-8?B?czI5M1FCZ01RMThiZHlCNXlRZDZqcnVURjN2UnNMS2hHczhUNHBEeSt1SmJT?= =?utf-8?B?QitWUThKeUxqaE5RT3BpcnBWbWxoYTk2RXNGMG8xWEo0eDB2ckRpbUVNNHY1?= =?utf-8?B?MGUxRlBnb0lIeXIwekk0T2kzM0hqTU5WRVlhdVJPTGlaM2E5VSsyUnhKSjJ1?= =?utf-8?B?dFE9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: 311fe19e-39c4-4152-aa3f-08db08624518 X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1899.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2023 16:50:36.5243 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qHgGqbtwxXRF1I3jhoNP/9yFikKAewiTHXiovADnl4bF7J1Ns+pL8uYEH9lxQDVA+1Ixwvezeo5m6LCeBpTj6Pv6vNsUf32VW9eg+q13sjI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5491 X-OriginatorOrg: intel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/5/23 21:43, k1rh4.lee@gmail.com wrote: > From: Sangsup Lee > > The size + offset is able to be integer overflow value and it lead to mis-allocate region. Reviewed-by: Russ Weight > Signed-off-by: Sangsup Lee > --- > drivers/fpga/dfl-afu-region.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/fpga/dfl-afu-region.c b/drivers/fpga/dfl-afu-region.c > index 2e7b41629406..82b530111601 100644 > --- a/drivers/fpga/dfl-afu-region.c > +++ b/drivers/fpga/dfl-afu-region.c > @@ -151,12 +151,17 @@ int afu_mmio_region_get_by_offset(struct dfl_feature_platform_data *pdata, > struct dfl_afu_mmio_region *region; > struct dfl_afu *afu; > int ret = 0; > + u64 region_size = 0; > > mutex_lock(&pdata->lock); > + if (check_add_overflow(offset, size, ®ion_size)) { > + ret = -EINVAL; > + goto exit; > + } > afu = dfl_fpga_pdata_get_private(pdata); > for_each_region(region, afu) > if (region->offset <= offset && > - region->offset + region->size >= offset + size) { > + region->offset + region->size >= region_size) { > *pregion = *region; > goto exit; > }