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 DBD2CC433F5 for ; Fri, 17 Dec 2021 09:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234087AbhLQJQX (ORCPT ); Fri, 17 Dec 2021 04:16:23 -0500 Received: from foss.arm.com ([217.140.110.172]:53702 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbhLQJQW (ORCPT ); Fri, 17 Dec 2021 04:16:22 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BBD491435; Fri, 17 Dec 2021 01:16:21 -0800 (PST) Received: from [10.57.6.245] (unknown [10.57.6.245]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 760A93F774; Fri, 17 Dec 2021 01:16:20 -0800 (PST) Subject: Re: [PATCH] drm/panfrost: Avoid user size passed to kvmalloc() To: Dan Carpenter Cc: Rob Herring , Daniel Vetter , David Airlie , Tomeu Vizoso , Alyssa Rosenzweig , Boris Brezillon , dri-devel , "linux-kernel@vger.kernel.org" References: <20211216161603.983711-1-steven.price@arm.com> <4c564c0d-7702-9dfe-910f-969fe130aba8@arm.com> <20211217091046.GG1978@kadam> From: Steven Price Message-ID: <4e56a7a8-c48c-49dc-6535-730ad871d1e1@arm.com> Date: Fri, 17 Dec 2021 09:16:19 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20211217091046.GG1978@kadam> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/12/2021 09:10, Dan Carpenter wrote: > On Fri, Dec 17, 2021 at 08:55:50AM +0000, Steven Price wrote: >> However this one is harder to fix without setting an arbitrary cap on >> the number of BOs during a sumbit. I'm not sure how other drivers handle >> this - the ones I've looked at so far all have the same issue. There's >> obviously the list that Dan already sent, but e.g. msm has the same bug >> in msm_gem_submit.c:submit_create() with an amusing bug where the check >> for (sz > SIZE_MAX) will never hit, although the call is to kzalloc() so >> large allocations are going to fail anyway. > > sz is u64 and SIZE_MAX is ULONG_MAX so the (sz > SIZE_MAX) condition > does work to prevent an integer overflow on 32bit systems. But it's not > beautiful. sz is the result of struct_size() which returns a size_t, and SIZE_MAX in case of an overflow. However the check is *greater than* SIZE_MAX which will never occur even on 32 bit systems. However the chances of kzalloc() allocating SIZE_MAX are 0 so I don't see it's an exploitable bug. Steve