Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1247096pxb; Fri, 21 Jan 2022 13:16:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpqQEcvDzQaIPOdWlpAEUll+TUVIQG0M2SIUgi+JUDlCBw19/FKZyErtRzwvTIuMQhi2NQ X-Received: by 2002:a63:1d5:: with SMTP id 204mr4169715pgb.623.1642799813616; Fri, 21 Jan 2022 13:16:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1642799813; cv=pass; d=google.com; s=arc-20160816; b=RS5gtHz6e2rkMe3PfblTCohFBPJVj6N09/Ct0po2kb/9SMVJ/+BvkjS79IP+ZixfR7 zpK+PUAWA2rnwhO2kK1crtlgKhwqfIB/hZhgK3dyFKCS1YFL6J+q5RvWxRpFskfusa0n mfQwOpln1B/F+vyB7E6u/BBiF4Yl2ha5D1O5Ki0Detw/+oEkSg9N1a32/hjLFi+FOPAF Uw2wuUvPTty+XbZpTgf51h11VuxcssEdU1UcqaAC6BuZi1kcuHTKVnu9ViAsAR7+oq4+ LfPAMwvT6Qh3jSGe7cQggWKyXqtIqbF+4CshNtgglOrQd4qEewucMWzWUnupIs8W0SHu RODQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-language :content-transfer-encoding:in-reply-to:user-agent:date:message-id :from:references:cc:to:subject:dkim-signature; bh=Bj8Thr5BLOakDAxlIyQ5Y7HrJw/O7mA+mFWOJl8AowY=; b=Ejd5jCNPu6moVP/QqqkWdpEqAZWYNFCHoLnyr2DtxQQOxHJTixYsUn7wlDWrIJdsXg 2o9kRkaSseMVAnPV+HhAD3o7HQKhxfmkuwYB8kOpPw5u+/cstc22IXntbQAIgOJmU5eZ E+jcTAmUW5D5Jket1hvKUskRon8BrRTAIKFnl8555EIl9JtSxIbnFmrcB5Gc76alrha2 DB0yshamIU7soTPb2wYpsh3/GtwkrCtyIOfsTGoahgXVVirMxpM3SZWCCN3fEjtDDIes KpWACTqZAbpsPxTLlI0LeMFsw7TioidlFj7OYgPW7cl3kUZ/l2G10B/Ccm8FYi00jvM7 Kb0Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LkXINhJO; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si5365967pgj.28.2022.01.21.13.16.41; Fri, 21 Jan 2022 13:16:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=LkXINhJO; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359819AbiATKWW (ORCPT + 99 others); Thu, 20 Jan 2022 05:22:22 -0500 Received: from mail-bn8nam12on2085.outbound.protection.outlook.com ([40.107.237.85]:53408 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232937AbiATKWU (ORCPT ); Thu, 20 Jan 2022 05:22:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LuUJqUO+SkkiFrJ5UmJbTIwLkFy0qWa93/MbwxjKSwDLRllH74BdGxy426sF7moI7fZAiUCU9NOlhR/aW75vy7z6U9zQvj+O1V9H9fFXsl+098xk3MDVYRh2EO/SA3GRN8U7goOm0azKfmhNN1+VKhJh/hfyS5j3C0MZYUU3e1oRPSNyTn6R9GMMSHNvg8cu2fpn/EbfJWXUXbI1/meaQD4emWSPhru/A56gskewwwCEBHFaFZnnUTZokmELtPiNDf7rGljSX+8JiOPRRjz86OEwNs4WZgk7pNLTEHM0dlowAn+Bkro/4vhhgM73KF7cygQAsyD1UlSmQUwakEGEQA== 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=Bj8Thr5BLOakDAxlIyQ5Y7HrJw/O7mA+mFWOJl8AowY=; b=L7DksRZb/prQqS1Mhp6tK7k/z56wH7sk6cso5WH2f11zVG7msSqXl/ezFdo714Du5ohR0wAv04qKqONQ0cFZlRt1Ktak1tGL1iKlgGpiluGAP5mxRXuLcKdLTpuUPESo/lg+Z4/bQq8mfWvlHRjwEgRjtMnss1obViVd0cwpFBXr9ZCJp0RFlaOsCytYKQbnQKwwvAZaHmzudndyEwsxMjx6m+vlJOSCoM3wworZ9vhfmtK3nmCON33K3nsB1iuPi/ngi5+cSqtp7snQWj5vmNev6YYbHYIAPKfH/3z9ynF/rJo+yNVGxPzgO5pVhNJUAAm2AZIIEK9ERV6hpSXiGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=Bj8Thr5BLOakDAxlIyQ5Y7HrJw/O7mA+mFWOJl8AowY=; b=LkXINhJOtpBdlSsI2NJtVZCXmkTiuo891Pjq0inh1NRoeb1sLkdnRX6jpQuaZU2+gavNESK/YvdtkYqUoS81o7HqocpbBob+9DM2zUxCngZAuHABJCdD04GlB1KZoZmSuw5liMw1T8Fo6LDwUx/BG8uEzhOObJPI1CznLf15Bzs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by SN6PR12MB4672.namprd12.prod.outlook.com (2603:10b6:805:12::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.12; Thu, 20 Jan 2022 10:22:18 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::b03b:7df9:d733:13b2]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::b03b:7df9:d733:13b2%5]) with mapi id 15.20.4888.014; Thu, 20 Jan 2022 10:22:18 +0000 Subject: Re: [PATCH v6 RESEND] dma-buf: system_heap: Add a size check for allocation To: guangming.cao@mediatek.com Cc: benjamin.gaignard@linaro.org, bo.song@mediatek.com, caoguangming34@gmail.com, dri-devel@lists.freedesktop.org, jianjiao.zeng@mediatek.com, john.stultz@linaro.org, labbott@redhat.com, libo.kang@mediatek.com, linaro-mm-sig@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org, lmark@codeaurora.org, matthias.bgg@gmail.com, michael.j.ruhl@intel.com, mingyuan.ma@mediatek.com, sumit.semwal@linaro.org, wsd_upstream@mediatek.com, yf.wang@mediatek.com References: <20220120085259.98147-1-guangming.cao@mediatek.com> <20220120100036.99867-1-guangming.cao@mediatek.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: <90bf495d-dbf6-cb0d-f54f-e0080b810f8d@amd.com> Date: Thu, 20 Jan 2022 11:22:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <20220120100036.99867-1-guangming.cao@mediatek.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-ClientProxiedBy: AM6P192CA0078.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::19) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32982818-4275-453d-e497-08d9dbfebc61 X-MS-TrafficTypeDiagnostic: SN6PR12MB4672:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3383; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lqxzcFZc476bU/RzM/BjtPOlIDIBWCUtU+iJi6+8sZO7usmEOTHcbW3xWD9DDoJ+d3WeOeimtSAQSMEtUw369cspHMsZykpTTdd7WTMK7zJ2rvI5RSSSHdSAuB6LJSVDReQW9Ub9zGWD59B01riA8LUrn+bPvBsRhpjnuR3zo5gEtWqDsXFq44CrFvolQjfo9Go52r8Tu80hasv9xu6kRD6x9oi0+sG0dLDMdPZ/mVOHR8RjFK2x7epJopLDcEQjpELNlI4fOkApB1xG6bHQIfYJyjuBtlvxBCJUkg80/+CWIXzQ9ifEb6NfvNgNJRx7uruB9H7Srw67TbFGLNCz+wKys1tzJRIy7gXl2NnY2NN4H73jyU7gTV2LMkV9r8Zidht6xV3XFgkinkuMUM8Bl2eU6/ZILruujtcRhsQ463RKutLpLsVU0LAht9cvsOdCgNfin6+7ayrFLdqQDlKYTXKCwuM1/NbcS/k1YS2WjBEc6RMmB68KFB5PUbwzIcgbSP8QjILU5nL3Dy7REKYij7w07Nuo2mEW5R1SHTdLlcrHk6huO3aMn868/EGRmmat1cxKRc3UBeiyBRk48U4bv0fuZfZQe3IBbHlFYPDQZK/J0J2VG6DLfSVr3mEnOgj7TUAox/IoUPeUANknMWxtjbfkDmkKFPLDhkaMsHOeW3Or/+wvs0rOzQx8f7LTFpLYdbD77zJqOLyqiIsex/fXl2U7I51XMNktnalY3Qxaf3pbyrk7/1Th5lXwrWxhxBCf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(6916009)(36756003)(6506007)(6486002)(6512007)(8936002)(316002)(8676002)(508600001)(4326008)(186003)(7416002)(86362001)(31696002)(26005)(38100700002)(6666004)(66556008)(5660300002)(31686004)(66946007)(2906002)(2616005)(66476007)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Y0J2ZGdEZHhOb0dLaVhlTkJ3c0M0NzRMNTNKZ3JkSktUK2ppemV3MktURVVK?= =?utf-8?B?cW14VDZYVmt1eXYveW55TGpTR2Qvb0JkWWZySWdtK3lEdHh6ekVqSm5WM2or?= =?utf-8?B?Q3FhL2VQampxb1BqRVdkT0N1Z25OVktsZmwzWmpEemZqVGsrNk9MLzlic1dI?= =?utf-8?B?L3ZnUUdnR0U2TU1EUzljVUxiNnVWOEdFemNheXFodkZQTCsrRWhLS1dkTnB5?= =?utf-8?B?VTFVUGdXeVUrbjhmZk5YaHM1YlZjWWJCYW1pUUs0U2J3ZW1NcFBYRlhjcVZk?= =?utf-8?B?R0NLNkFFNHl6a3BrMDNuTjN5bUtEcWduOVp0SGJxRkhkQ1cvcEFwLysxQ01F?= =?utf-8?B?cldPdzdJSlRTTUw1Z2hOakVSblI1S2pDMW84Q2QwUjd2WHdWSm9pOXZ0Z3ls?= =?utf-8?B?dHNPdTYwR0RWa3BHQ3Q3VHpJeUFIZENueGNWTWhHZEVLTjc3bUJyeUZrNWt3?= =?utf-8?B?dzd4Q29KTlhONW0zc211Y1MwNkd1L0hmZEFFVmVXOFhVSEJRVGZvOHNvVHhh?=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S1lXQTB3OUZBMWw3aTlnUXNhZW9iWlEy?= =?utf-8?B?N2JmdWoxTHFxZ1c2ZklOUE9pb2FBUy9ZTmZVVmllM1o4QVpNT0J5VHNVcEVL?= =?utf-8?B?ZFlzUUNESVF6WEhYUUJoUWxpMHZVbXFGTHNEcWRQRkZ6Z01ZNkx3bTRXRzFN?= =?utf-8?B?RjNlNkU1WGVDbjlVcjRyRDQzZVBndjFnZW5RWmxvYU5VNnRBa2xhMnkvaHRH?= =?utf-8?B?a2RnSCtLNjFxdGp4T3hqLzV6WFJ1YitnQ2tGZGVuREFtMEk3Yk55Yys3aWY5?= =?utf-8?B?TzRUeklWeUhaeGFFeHZrK0FhZjZtcDRIc0ZqblVpQzJhNk1ydEZkU2VlQ0xN?= =?utf-8?B?QTFibTAwZzBuNHZ1V1pEb0hsR0pQZWR2MkcyU0JFZllmTGdOc0NOMU1ya240?= =?utf-8?B?bTlXT1A0NmhrMUNQYitMWklEVkJmdnNxc0hjeU1DZHc5eUlKUTdaV3VOZzZo?= =?utf-8?B?T2pET3VnYzUzaEJCVlFvOEk1S2RjdkpuOHVWVXZSamtkNTFxS0VZeE5WOTdm?= =?utf-8?B?TjVSOU5vWG52Zk9IWEhBYmZTZTRCeXcwZ2YwSmgxajdOaWlmTjBRc2lYelN4?= =?utf-8?B?YW42bTBRM3gxclFGdmRNa0RKUE5CUGl6ckg0UjZ4d3BhalRSVnNuUjEzUFlV?= =?utf-8?B?T2dnV3hhL3FaYXM5T2lLM05MaUJtU3FjcWtYaGlaRHJtaUJVNkpHbzVlb2do?= =?utf-8?Q?BSNE=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32982818-4275-453d-e497-08d9dbfebc61 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2022 10:22:18.2093 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ms1hohte1qwfdHRYIOA6Iws6bP6AlOhJ7XcIFzZvCTHivIJlR/u5fxriQARp5LfW X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4672 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 20.01.22 um 11:00 schrieb guangming.cao@mediatek.com: > From: Guangming > > Add a size check for allocation since the allocation size should be > always less than the total DRAM size on system heap. > Adding this check can prevent comsuming too much time for invalid allocations. > > Signed-off-by: Guangming > Acked-by: John Stultz Acked-by: Christian König > --- > drivers/dma-buf/heaps/system_heap.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c > index 23a7e74ef966..b65e597a742f 100644 > --- a/drivers/dma-buf/heaps/system_heap.c > +++ b/drivers/dma-buf/heaps/system_heap.c > @@ -347,6 +347,14 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap, > struct page *page, *tmp_page; > int i, ret = -ENOMEM; > > + /* > + * Size check. The "len" should be less than totalram since system_heap > + * memory is comes from system. Adding check here can prevent comsuming > + * too much time for invalid allocations. > + */ > + if (PFN_DOWN(len) > totalram_pages()) > + return ERR_PTR(-EINVAL); > + > buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); > if (!buffer) > return ERR_PTR(-ENOMEM);