Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2596919imu; Sun, 27 Jan 2019 08:34:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN6PU1AfbOsfrtFDAIrOsEenJXsn851R7MRYCpN0fpdzdIRM9SZMegOZoh7X3izu632ZCb6k X-Received: by 2002:a17:902:e290:: with SMTP id cf16mr19038711plb.81.1548606881552; Sun, 27 Jan 2019 08:34:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548606881; cv=none; d=google.com; s=arc-20160816; b=vevhj3rBbRjgz6XFhti+HeTHBM26kYfZeYu6uYp7b3O6BNfvmPjf/25paUij9Q3gZk KfsitBUWbhcJi5yLrRGChQWeC9JO6dsRruCZbTu9/Nm/bumrOdWcAAi9MQ6/fgrnxuwf Cj824y90qPdVred1VRTx9n+8JQ6EcIL2q8N+9VCuaymErQO8CGsvoz/WAiY86AqIz156 WrzagJrOg4JuaMhHHfnBvRKmGHW/arc94O7dL5bD+JZ59T6/wCsXquZe/X6nuGCdgYYm cIYum2Z0SrnsEdbJpHojLFo8cFeqSsLp1CLOHUQdjjnWq1R54aqrNxr9/ao3t3QqnYld UXUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TNuGZKsr/Se4zO4haJyYSCDu8sTtvIigBOVsFMaS83U=; b=N3iGxtqlrpcPgxLWa4XYg7EevXfrmDZcGCNHjz7DdQZYo10o+L9xu4rmQ1LtEG1a5p FbYR/7SCMfOvSgmL5+TAW4TjCKDq2Yztqh4vtllw+FhvmDOyJLOSbxFDim/uAoaUfe4y X5OQNf+QzNFLxPubzhA7QrZDGdDUKh9ubw/Eeaq4nQP38zeKVgo7sOWx4fjEQbaJwvTN +7i3LiL6dYvqyPV5jJ6dQ6pxQj4KN8z6hY+cbnTV3g74MdGCZmBCXLXKmBtJ/8e0QTvO jwFSe5n/HS8Gt4vyItLVq2c6xcfZ057Wil5t/1wvrWubBl9kFlbdXRG8jo4tVTHPLVfC iIdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pdCaRJSi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p75si23152110pfa.34.2019.01.27.08.34.26; Sun, 27 Jan 2019 08:34:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pdCaRJSi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726589AbfA0QcE (ORCPT + 99 others); Sun, 27 Jan 2019 11:32:04 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:43206 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbfA0QcE (ORCPT ); Sun, 27 Jan 2019 11:32:04 -0500 Received: by mail-lj1-f193.google.com with SMTP id q2-v6so12163410lji.10; Sun, 27 Jan 2019 08:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TNuGZKsr/Se4zO4haJyYSCDu8sTtvIigBOVsFMaS83U=; b=pdCaRJSia8DH9oSIN3SDMxF1xjzfXW5xVT//whl6ChyJ7hnqQdYLNq5CYvfcrQKVTZ IDD+LY6ZH0ZRF+BoLM5iRDuh0n2vQeczc7YBvBv+zOHLj19wrH05KalWqBet6FzZqexl spoeAbFK69P7/8qfvw1tQ0U8cSPZmV4bgfWUgLgW1GkQDOX4TjdkQxiBI6kRkxU/MAQs wNjzZRNdOv8IWMurMCVNqZwwL0O/xFNLq7DWD5RIvKRbVEF6ZOXbhvND9CeqzhEphXKt E3a1cCqUXWquXaNel4QAx4gLkXLUxdayXMf/16dinv1pFV5MKll+M0o5K5RoCxm8cXym JC1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TNuGZKsr/Se4zO4haJyYSCDu8sTtvIigBOVsFMaS83U=; b=FNkVoXXaTuO4x2cmvVnUda/MlQgg1zzkpwJPqR6kiC0LVCfqzQCqG/BagfLM/Xrnpt 2M5vlPU7PXQlCa9yJW24bJrOw2xtlpT+0klDSQ1+HtSjHDcfmv8R0RmB+N8FVSQg8J0w xLe+mWA+FFgckkqm9+CWUpduv5cV2NTfPLTiyuyCyW6Qyks9OBSERqaTRlX4wSuAb7uF +wGASoxqSmRcu5LaNN9aQgK8EqHmkhzz98Gux2O5/TciXD58+jf4CMZHALG5VS1nmQVe BelQyhSYuCtOWlCOcgtrTXBYCPIlvYdmuWJDFeuPl7ArGf6YP+AKFrChinIoIhFU52qF XGvg== X-Gm-Message-State: AJcUukfKaCUCbVTiT3GQxdsQubfUSpuZ2S6/ToK2/9EFL8rj2RG3BNJ3 nXDeZdaGXp7rsmoEPg2XvVnLKJxEURG9GcdS/AY= X-Received: by 2002:a2e:5703:: with SMTP id l3-v6mr3295856ljb.106.1548606721227; Sun, 27 Jan 2019 08:32:01 -0800 (PST) MIME-Version: 1.0 References: <20190111151154.GA2819@jordon-HP-15-Notebook-PC> <241810e0-2288-c59b-6c21-6d853d9fe84a@samsung.com> In-Reply-To: From: Souptick Joarder Date: Sun, 27 Jan 2019 22:01:52 +0530 Message-ID: Subject: Re: [PATCH 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range_buggy To: Marek Szyprowski Cc: Andrew Morton , Matthew Wilcox , Michal Hocko , pawel@osciak.com, Kyungmin Park , mchehab@kernel.org, Russell King - ARM Linux , robin.murphy@arm.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Linux-MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marek, On Fri, Jan 25, 2019 at 5:58 PM Marek Szyprowski wrote: > > Hi Souptick, > > On 2019-01-25 05:55, Souptick Joarder wrote: > > On Tue, Jan 22, 2019 at 8:37 PM Marek Szyprowski > > wrote: > >> On 2019-01-11 16:11, Souptick Joarder wrote: > >>> Convert to use vm_insert_range_buggy to map range of kernel memory > >>> to user vma. > >>> > >>> This driver has ignored vm_pgoff. We could later "fix" these drivers > >>> to behave according to the normal vm_pgoff offsetting simply by > >>> removing the _buggy suffix on the function name and if that causes > >>> regressions, it gives us an easy way to revert. > >> Just a generic note about videobuf2: videobuf2-dma-sg is ignoring vm_p= goff by design. vm_pgoff is used as a 'cookie' to select a buffer to mmap a= nd videobuf2-core already checks that. If userspace provides an offset, whi= ch doesn't match any of the registered 'cookies' (reported to userspace via= separate v4l2 ioctl), an error is returned. > > Ok, it means once the buf is selected, videobuf2-dma-sg should always > > mapped buf->pages[i] > > from index 0 ( irrespective of vm_pgoff value). So although we are > > replacing the code with > > vm_insert_range_buggy(), *_buggy* suffix will mislead others and > > should not be used. > > And if we replace this code with vm_insert_range(), this will > > introduce bug for *non zero* > > value of vm_pgoff. > > > > Please correct me if my understanding is wrong. > > You are correct. IMHO the best solution in this case would be to add > following fix: > > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c > b/drivers/media/common/videobuf2/videobuf2-core.c > index 70e8c3366f9c..ca4577a7d28a 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -2175,6 +2175,13 @@ int vb2_mmap(struct vb2_queue *q, struct > vm_area_struct *vma) > goto unlock; > } > > + /* > + * vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer, > + * not as a in-buffer offset. We always want to mmap a whole buffer > + * from its beginning. > + */ > + vma->vm_pgoff =3D 0; > + > ret =3D call_memop(vb, mmap, vb->planes[plane].mem_priv, vma); > > unlock: > diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c > b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > index aff0ab7bf83d..46245c598a18 100644 > --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c > +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > @@ -186,12 +186,6 @@ static int vb2_dc_mmap(void *buf_priv, struct > vm_area_struct *vma) > return -EINVAL; > } > > - /* > - * dma_mmap_* uses vm_pgoff as in-buffer offset, but we want to > - * map whole buffer > - */ > - vma->vm_pgoff =3D 0; > - > ret =3D dma_mmap_attrs(buf->dev, vma, buf->cookie, > buf->dma_addr, buf->size, buf->attrs); > > -- > > Then you can simply use non-buggy version of your function in > drivers/media/common/videobuf2/videobuf2-dma-sg.c. > > I can send above as a formal patch if you want. Thanks for the patch. I will fold this changes along with current patch in v2. > > > So what your opinion about this patch ? Shall I drop this patch from > > current series ? > > or, > > There is any better way to handle this scenario ? > > > > > >>> There is an existing bug inside gem_mmap_obj(), where user passed > >>> length is not checked against buf->num_pages. For any value of > >>> length > buf->num_pages it will end up overrun buf->pages[i], > >>> which could lead to a potential bug. > > It is not gem_mmap_obj(), it should be vb2_dma_sg_mmap(). > > Sorry about it. > > > > What about this issue ? Does it looks like a valid issue ? > > It is already handled in vb2_mmap(). Such call will be rejected. > > > > ... > > Best regards > -- > Marek Szyprowski, PhD > Samsung R&D Institute Poland >