Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp403712imu; Fri, 25 Jan 2019 04:28:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN69x4BtsSPfYHUDtpaWRcPHjo8/Sv6auAYUH6I03cunmx8Z7dqq9p2yhv2Kv7/iWo0bbYDv X-Received: by 2002:a17:902:6b09:: with SMTP id o9mr10776277plk.208.1548419318544; Fri, 25 Jan 2019 04:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548419318; cv=none; d=google.com; s=arc-20160816; b=Y1m84DjixFCsyIhp/OV/QlmZoR3GKUWpJt2gmkVHJxmJJhSFQMY3PPkKc8jkipGtXn woZPjnu+cvXwzvD7tIIpgFvblUMew+c/wjZxD/HV2/L/v2f4i8TX+8uOJXiuOjcNrHDV uNwAONd/ExtJ+EoExWwEG3s1V1NmWsVlaab6HHoI6SaNxFZfolMp68qaV/2/SpNVM4NV mJ66E+LULaZFep4PaaPZOxBlmhgiL3BrdTZuxmPwqrUEAYWx9NyjYiarJjtu7EjLQSqD 0rvW6fkd6Cf164NXc048mfslvgEk2Xldp8OAMqSYJJ2LdM2aclZgiujx1/rLeYHqOW2E tDkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:subject:dkim-signature:dkim-filter; bh=1lPVJOJ/AfWt5Dr2dBgMtuYlLQMGEYvhjUdex851l+8=; b=rvb7ZUHy0n5q8VfJHWfaWUL8aVB21S7ub7yVNcMH/rGPSNvuSDu7LQR7Mzyn5Hcawy C24o5gEWJDLt3rQEtxcZ3VV6IA3PbTEctbqLuCbZsJBa0Y4Dcuy67/j0ycA956gCDPE0 fggwW+73dtDmWNWoDnEcUC7wzn5PsUNecid9cVdxh8bOsaQ8whQrJYB5tmCYJwSplycx TPVrkOxvtoCjngatb/5Xn0HPfuwUZe6UfBDBkyQZxvTo4hVX01DnzVATIyJeSzWyR7TS oZzFr83oPSTI65Nuv+I3YuJ23Pr8CpyP3Yx/2Ud5JQy8ooFD+kmsdsVhTGHeMp4fvzLs X1yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iTQuWVW8; 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=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si125354plm.312.2019.01.25.04.28.22; Fri, 25 Jan 2019 04:28:38 -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=@samsung.com header.s=mail20170921 header.b=iTQuWVW8; 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=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbfAYM17 (ORCPT + 99 others); Fri, 25 Jan 2019 07:27:59 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:46207 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfAYM16 (ORCPT ); Fri, 25 Jan 2019 07:27:58 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20190125122756euoutp02ecf46d571c9c6e485a54bb40ffecedfc~9FyC-WgyX0437204372euoutp02D for ; Fri, 25 Jan 2019 12:27:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20190125122756euoutp02ecf46d571c9c6e485a54bb40ffecedfc~9FyC-WgyX0437204372euoutp02D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1548419276; bh=1lPVJOJ/AfWt5Dr2dBgMtuYlLQMGEYvhjUdex851l+8=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=iTQuWVW8P6sCYgF80V9EDv9Qmzgxj8rAbKC9RQ9fojpcXwwULLMlRBw3yvtUiaz26 5p3UZm74NXlYGWaItm56kEqKCERbfoHjrBfAo6W4k4RBozSBHdbAtVXq2a/berrTMj 7wSSUvdTGupymlIsow1Qf6RYXa9lj4nYaym+pNqw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190125122755eucas1p19a117b5e5210018d02974b5820735792~9FyCWccPO2265222652eucas1p1C; Fri, 25 Jan 2019 12:27:55 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 11.CC.04294.BC00B4C5; Fri, 25 Jan 2019 12:27:55 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190125122754eucas1p22f1e8a1622f036635033984a578bc78f~9FyBaj7vb2908929089eucas1p2e; Fri, 25 Jan 2019 12:27:54 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20190125122754eusmtrp142170f398fc09ead01ade6738ea16475~9FyBMAofb3212032120eusmtrp1H; Fri, 25 Jan 2019 12:27:54 +0000 (GMT) X-AuditID: cbfec7f4-835ff700000010c6-a6-5c4b00cb3e76 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 1C.FB.04128.AC00B4C5; Fri, 25 Jan 2019 12:27:54 +0000 (GMT) Received: from [106.116.147.30] (unknown [106.116.147.30]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190125122753eusmtip16e5f2a4120fff53d3e36dc16f39e31b5~9FyAk-Eun0963109631eusmtip1H; Fri, 25 Jan 2019 12:27:53 +0000 (GMT) Subject: Re: [PATCH 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range_buggy To: Souptick Joarder 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 From: Marek Szyprowski Message-ID: Date: Fri, 25 Jan 2019 13:27:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Transfer-Encoding: 8bit Content-Language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA01SWUwTURTldabToVAcC6ZXRU2aaKIGBePHKKZi4jJuqNEvxEjVSVFoIS2I S4IFomhFoiARhwouQREaC7VFwQ2KUAlCWKQqRtwqEbVaLTFWcSuDyt8555177znJIzHpM+Ek cqcmjdVqlMlyQozXtvg6ItoCVsdH3nCOo41mE0E7e/UY3Z79XkT31BsJOq/aJqT7Tb+EtL3o FqIvWoYF9LP8GPqk2yeiGz0uIf39q5GICWZMpSbE9Di7MKaOeypirlbMYiyVRwjG8rlAxNwr /o4zr74NEky+tRIxZmsvzngtU9cHxYkX7WCTd+5mtXMVCeLEDpdZkNowZU9pzgE9soIBBZJA zYd2WxVuQGJSSlUgaLXZCZ4MIahpvi/giReB5wQn/Dty1Ptu1HUJgfV8PuLJRwTZr44hvyuU 2gJDdfW4H4dRs+FM0zfMjzHKI4Csm3I/JqgoMLgNhB9LKAW8cDWMYJyaDv16t8iASHICFQ8H e8S8ZTy0nnaNrAykNkCxtxfxK6dBjq1kdL0M+lxlI6mB+iGCvoESnE+9FDpr2kYbhMJbh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tc8tNtIrTswtLs1L10vOz93ECIzwbcd+btnB2PUu+BCjAAejEg9vxyHPGCHWxLLiytxDjBIc zEoivJ+PecUI8aYkVlalFuXHF5XmpBYfYjQFem4is5Rocj4w+eSVxBuaGppbWBqaG5sbm1ko ifOeN6iMEhJITyxJzU5NLUgtgulj4uCUamA8esXi1wEJLa+CTXyPrW6LvGxoeHjJ0itG51yH MJd5lFRFnN77/3smCE8tfZNyxrPCqKh1leQe8a6fhgejH8e1WqW1VT7eI6hfoCWVnOLAWmhY zb7ypJZnZULoVg7xzyzFTFGd0yvX3r/v/vHPHJvZHoqCkf9Ozi5v8DxRuOxnV1G26IyOq0os xRmJhlrMRcWJACVSZnwGAwAA X-CMS-MailID: 20190125122754eucas1p22f1e8a1622f036635033984a578bc78f X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20190111150806epcas2p4ecaac58547db019e7dc779349d495f4d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190111150806epcas2p4ecaac58547db019e7dc779349d495f4d References: <20190111151154.GA2819@jordon-HP-15-Notebook-PC> <241810e0-2288-c59b-6c21-6d853d9fe84a@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_pgoff by design. vm_pgoff is used as a 'cookie' to select a buffer to mmap and videobuf2-core already checks that. If userspace provides an offset, which 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 = 0; +      ret = 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 = 0; -      ret = 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. > 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