Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1238969pxb; Fri, 21 Jan 2022 13:05:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZivAYDWesvu0oWeEG7FCEJ3PovlMhmWbZABNQSrPgt2g8xjFgPI/DNbev9CbkDxAlTJbH X-Received: by 2002:a17:90a:7604:: with SMTP id s4mr2412979pjk.69.1642799152455; Fri, 21 Jan 2022 13:05:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642799152; cv=none; d=google.com; s=arc-20160816; b=Z2hW+n2GAA28j67q+8rVWELDLUyXJWeS4aat2hrqadfD6m9JN4Kwx3ABDD5LZ7w1Ao U/WNqmr6oAQYs8tuDRSW8OoOnNrLbS58IBs1PG6wM+2SxMLBcg9WRyMr0/NCk2ukE8iz 5TbgbOFLzDStRe8tVHTxRmiVTfBdhGXQL77X06dFmHAEWcTPyO3A/R8x3dbvyEW0n7lP HahqVPNS4qsliEyCrRX+wssBMPAi5JJjL9ltiTLS9JEsaW9ZGTU+rFkLL4uWPGM+s+8s JXgnAwtMFA2gcrK/vtrdyHJZomlneMYUMRarZ5bCPKoip/JPklaqO6m4noT5D3Fo682c geXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AZnU5cEeFyaFBnpj/0CbEtA8JHuWrnQecXMIYCnzB/o=; b=r6oEdhv/yUU9E52tH+AloP154xv+XKdGUBEOrQ11ldHqAOl2/HhmcT8DX/ckr2BR3A CXezRQiNiCM3b7mSSvmdW2HPhyT9eIQk8KXm+A7gBA3zsK/G6u5nznacfTdfbwsGs67U FS3lPksKpnC6R4LY/MhOn1uhFP+fREFWEXFh47XcVEQVe59My7mRJ2TIYteXi6qqEUQA ahns9ELZwEAZqIoKvY/Dio6itAaIXh1eFJpGTL7VGbw7jqC6mZTn+wO38o4f1TruC0Tx sztsWdTWzvZTc+xv1VzljCdMNa1Xold8gDp5kU0c9d2awFMEYDrde/+9HdSdmqGAcwxI P4Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ErV1kJfa; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si8115254plg.202.2022.01.21.13.05.40; Fri, 21 Jan 2022 13:05:52 -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=@linaro.org header.s=google header.b=ErV1kJfa; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358397AbiATDtK (ORCPT + 99 others); Wed, 19 Jan 2022 22:49:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbiATDtJ (ORCPT ); Wed, 19 Jan 2022 22:49:09 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8C6C061574 for ; Wed, 19 Jan 2022 19:49:09 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id x22so16509714lfd.10 for ; Wed, 19 Jan 2022 19:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AZnU5cEeFyaFBnpj/0CbEtA8JHuWrnQecXMIYCnzB/o=; b=ErV1kJfadCu1b5wgD6aEviZCSAk41KIjnGh8WYn8aHbrfBmz/Z03LAGBXFW2rQaPAJ 8nUEBpkWeomoODmY334NhCZOU+o0EljJbg8u2iyiFqhQzZA+efnPNwuXwUbmf0s5v/T1 kCYeVe9Uk4rKeiAhQV0qJH3LNcIRAZLLfIB4l+8HBTpN2EbhE7OMo9MsZ1jJFtNumTI7 6nq4zktXZrLgMTkM/3rhi6H2v1j+XohmCPmuRZ67scdSpSHYsD2JZXkUmKHOEB9cL3zx lOz0lnwWIRRBoK8mzCl56IReSHCns1DzoysZ5ToPrtmXJlo7ywMjgvALaTMfHs/M01U3 VAsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AZnU5cEeFyaFBnpj/0CbEtA8JHuWrnQecXMIYCnzB/o=; b=zsx/Aov7x3LOctjn0BdaZ6p4Csmuc3u7P587+HhGfHVXGwg6ECRD2zkLrgG7WJWOIC YknFaxYigKn66pz0gN7XEBoutdGJ7MqHSfEOCX5D6Owqxlh6ckUibbi3EOEebeNe2AjZ mCBHVFCiIivwAKjNKrpu4Ge+kCJMp3kihaOlSq5o+huTeMjVLtWEevkbs0PGEmxKij0/ AuHW2ESOOmshTie3+97nBCaC8HPWQZWwUaXCWXo6csNcWnc9GDWoxPzhN/14I0J/V0WX d45bdjafM0aP4XkwRKGY92v3t5mkyhi/zj8ErgQqB4zBaEcVkjKJMiwQTadZGwgtLATt nXwA== X-Gm-Message-State: AOAM530COCRr0CF2qC8gc148rCAoFmk6hcPE1xaw2DhjDgs6IkuQpFJ6 pkcUSyrz4EZUq+BkvmnHr3vkxVfuijvrr5x4wSd6TA== X-Received: by 2002:a05:6512:3e1f:: with SMTP id i31mr25221311lfv.661.1642650547311; Wed, 19 Jan 2022 19:49:07 -0800 (PST) MIME-Version: 1.0 References: <20220120033450.90164-1-guangming.cao@mediatek.com> In-Reply-To: <20220120033450.90164-1-guangming.cao@mediatek.com> From: John Stultz Date: Wed, 19 Jan 2022 19:48:55 -0800 Message-ID: Subject: Re: [PATCH v4] dma-buf: system_heap: Add a size check for allocation To: guangming.cao@mediatek.com Cc: benjamin.gaignard@linaro.org, bo.song@mediatek.com, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, jianjiao.zeng@mediatek.com, 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, caoguangming34@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 19, 2022 at 7:34 PM wrote: > > From: Guangming > > Add a size check for allocation since the allocation size should be > always less than the total DRAM size on system heap. > And it can prevent consuming too much time for invalid allocations. > > Signed-off-by: Guangming > --- > drivers/dma-buf/heaps/system_heap.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c > index 23a7e74ef966..bd6f255620e2 100644 > --- a/drivers/dma-buf/heaps/system_heap.c > +++ b/drivers/dma-buf/heaps/system_heap.c > @@ -347,6 +347,13 @@ 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 consuming > + * too much time for invalid allocations. > + */ > + if (len >> PAGE_SHIFT > totalram_pages()) > + return -EINVAL; Thanks so much for revising and sending this along! It looks good to me. Acked-by: John Stultz thanks again -john