Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp990070imu; Fri, 11 Jan 2019 12:50:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN5m8vGQzyNT6EU45pRo22Ry+Ae8dGaD4IHABTgGX7/4LhC/38ASo/rC/m27GVM3mQQHGbgr X-Received: by 2002:a17:902:e290:: with SMTP id cf16mr16503767plb.81.1547239808862; Fri, 11 Jan 2019 12:50:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547239808; cv=none; d=google.com; s=arc-20160816; b=mIwRM12I2X7RSlkuKloqCj+DYme2Wt5RLfla1uq+bfiwMFQAdc51HbeTVdDyg05GPI drPFV+dH437/LZgL0ipFMfxJILhTeK92Wt1vAfk8qdSXmKp/gcq3YCz3y9nfGgHQEKi4 j5qtTLCQqzalAXdqG6UGyJDeD1nfIg89jDwcg4bvGCNKcIIBhKcUnw3LIkQ9mXcULuU+ EDm5ahbyZ0QI89MQvAtqnLvdX4vwsabc1zhEHGCa+KEKQf9YRATyYjqtPyEPqoPBBB8L OkmmcUS1x9WHqt4fpfzDoW38HLFko98Beiierfj/iyLHQw/CB50P6wm3lq9i6WkJ4y/s J4TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=f+tqwuN0gEDE9lXuQYpwY4uxComezYZtGYmjxDGe8Px6MbpVN+Dq4a1s2c2czw6VVI gA6mYmYaBJhpcPXp2Dj8LoW4mnnIvQMhX+xOMwGFgGdNmJh1K4fEeqIhx7QJ7kO89+dt 0p32M6euhiMK3lnvV6pmwrlXdnINDhUgjP/hHq+wQHGg8MaOLNVExXdJ6ZcFFlfmaQKa DVl2aJzUPMoF4lC/uCCKtWLX3Tyao330zxPpFqOoNmIpmtqaNrmUR22QD3B/iuYmPPS/ PLqSu2hLkcKKU1V4FWVg0ciL939giBoEDAh70Yu6CAWRx/161T0S3UkAg9QoVfQOfLZ/ 9lQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukuye4IL; 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 g8si9621900pli.50.2019.01.11.12.49.53; Fri, 11 Jan 2019 12:50:08 -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=ukuye4IL; 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 S2391972AbfAKPHz (ORCPT + 99 others); Fri, 11 Jan 2019 10:07:55 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:43077 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbfAKPHy (ORCPT ); Fri, 11 Jan 2019 10:07:54 -0500 Received: by mail-pg1-f193.google.com with SMTP id v28so6415498pgk.10; Fri, 11 Jan 2019 07:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=ukuye4ILBghvl/ea98/Ja45KGMhw2LJ9JaPBDDpqgt2y9VBAhCkwXx/XCC1BJBLszm j/RFMHQI1vnQZm2S/durahGZ3fABpMUNvQNZKd2mWCd1b0seaQ1HdjW0BjizObBP/e+S 7mMLpf4vsXaJ9HXyxFoviwshTVxHZpfMU6FgoF1sktEarBm8ClO7PCkxUkcJ/BwNxnZL yBl4z8N8OTasKmGS9Usrz+JXD5rBahLAWvbEMuQYtCd2+Q9qOk9vKmSlfa499/WHZ/oa C9rO4vYI+xLVeQMZgqOYNUmpDt6leBfFn8bwAdgRC1xdcK18dvi1UirqW/G0uJ8Y+Kpe 4A1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=TFAP3oRa2FPyVVN8gthZa/yQchM3o/blWpILdGZGnicvrIsnlAbwZDDPRqDDdvHd9m J4ApUIkAe6S94NJz6IhBs1EhLqmbltzrXZhLAcFzbX0efc31+8ZROEufI2CO1NvDw+hS n8ORIfSAQSx/7Yrd5QMrsFUSu2Hdsr+HgCTShLB9TXYEcHNY8cvpepCLx/KBH8x2sIwN hIhM1f9I33bzGwhS6DGv/rw8BCmsQN6+/CVskdBrLlt8+SenvEIhzctR4fbjBaX73PGp qwK5skGhAaDQy/yMZxXgP1TfYk7mQ09x66ec1wBTAMR+hjTmYBhVwss+FBcOEzjcPHzT egCQ== X-Gm-Message-State: AJcUukdPW2a979VDfrwkbHRDoUEN14D57Drl/edKL1KNd2oYCyC3iukc +XnRKv+sCgNzvB1TZ0FWF8k= X-Received: by 2002:a62:5486:: with SMTP id i128mr14545894pfb.215.1547219273447; Fri, 11 Jan 2019 07:07:53 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([49.207.52.190]) by smtp.gmail.com with ESMTPSA id m3sm137912153pff.173.2019.01.11.07.07.51 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 07:07:52 -0800 (PST) Date: Fri, 11 Jan 2019 20:41:54 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, pawel@osciak.com, m.szyprowski@samsung.com, kyungmin.park@samsung.com, mchehab@kernel.org, linux@armlinux.org.uk, robin.murphy@arm.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/9] videobuf2/videobuf2-dma-sg.c: Convert to use vm_insert_range_buggy Message-ID: <20190111151154.GA2819@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. This has been addressed by passing buf->num_pages as input to vm_insert_range_buggy() and inside this API error condition is checked which will avoid overrun the page boundary. Signed-off-by: Souptick Joarder --- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 015e737..ef046b4 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -328,28 +328,18 @@ static unsigned int vb2_dma_sg_num_users(void *buf_priv) static int vb2_dma_sg_mmap(void *buf_priv, struct vm_area_struct *vma) { struct vb2_dma_sg_buf *buf = buf_priv; - unsigned long uaddr = vma->vm_start; - unsigned long usize = vma->vm_end - vma->vm_start; - int i = 0; + int err; if (!buf) { printk(KERN_ERR "No memory to map\n"); return -EINVAL; } - do { - int ret; - - ret = vm_insert_page(vma, uaddr, buf->pages[i++]); - if (ret) { - printk(KERN_ERR "Remapping memory, error: %d\n", ret); - return ret; - } - - uaddr += PAGE_SIZE; - usize -= PAGE_SIZE; - } while (usize > 0); - + err = vm_insert_range_buggy(vma, buf->pages, buf->num_pages); + if (err) { + printk(KERN_ERR "Remapping memory, error: %d\n", err); + return err; + } /* * Use common vm_area operations to track buffer refcount. -- 1.9.1