From patchwork Fri Jan 11 15:11:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10758221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B35691E for ; Fri, 11 Jan 2019 15:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 269B429C71 for ; Fri, 11 Jan 2019 15:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A9BF29F93; Fri, 11 Jan 2019 15:07:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9ED729C71 for ; Fri, 11 Jan 2019 15:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0E2F8E0009; Fri, 11 Jan 2019 10:07:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9BECE8E0001; Fri, 11 Jan 2019 10:07:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AD5D8E0009; Fri, 11 Jan 2019 10:07:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 4C7708E0001 for ; Fri, 11 Jan 2019 10:07:55 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id t2so10529069pfj.15 for ; Fri, 11 Jan 2019 07:07:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=LkC55u8dQ3A0+ZLeQRdBYWJeEk/hKWoCwkYa5p9lIbiWt29hgl4WWJleiajixPDHUO fd9CgDJQi73Tcm50CeK91mmaSTbUMznx0qyn3RrsexU8asz6+2KEdBZdCblf+RnQXRBV hjKfbxRjNadt6NL7evmh1StjgF7nLKJNkMmcJwR/zl9Zur2Id7gd+U4/5NHtnMQH2VWp 5HMnPklQqJMdfAUlu62Yi4YdBabvw7X+24DkoMkSmC562Ynl+N30kdDZ+0BLjCI2hPwT 2s1jI9rrX9zzWdzpENI6VCjRh73cSHJY15UttLJWZ1aMThw0rm14biVbAhCHvfUWc6GN dQEg== X-Gm-Message-State: AJcUukfC0Bcyzm9Rn6NG7OH9gCwGtLgZ/bAqj8N79r2494UtP+FlhFJw HMpxWujIIm9CUI1gandtXScHNrlTpbVhU/C+/vN+l7Zm4bzDglwx4DkR8op8XZPgkAroJAASWgt fzpMZe4sF5tgXBrc4ogwVOSFci+HaxqcWeKUd1r7IfFsuiO9AyxIT5EeZYP9vGeIsUbvTOSl/I+ QhlLHBezxaUODo8k9LsRRR03ShDbSwh4pO/PFDdA593JX10LscRf7eccDsX0uhLs3wAkMoIKO/J bUR8mLgd6i/BQRSAdxIQocZO26YQC6bPzP3z5ir76IobuwFsV4XO36rvuplSpDHZ1wQkeDhN5Bk 8w9oyTObE1DVLM3teIRAZYc0lc2LlRfISFWD6TRc6oCoiPVg8dOYJZhsK6fh+KITnMdZE66pIMI V X-Received: by 2002:a62:4b4d:: with SMTP id y74mr14766681pfa.186.1547219274973; Fri, 11 Jan 2019 07:07:54 -0800 (PST) X-Received: by 2002:a62:4b4d:: with SMTP id y74mr14766632pfa.186.1547219274273; Fri, 11 Jan 2019 07:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547219274; cv=none; d=google.com; s=arc-20160816; b=LsPgn6cwDXP6lXDInqb6cYBFrlM0Xtg1cnKQOatpUTk3uEmJcD/HmFXNVPj5vztYgx mO5OPEeIS6CIQF9HK0W0szCNXQh60nxxTMtXmc8mFHKNoCKuQfu6PqXo+8ku7fCk98Zn HN6zDXFDspbr0uYzv8hxIaiTLnzgncCFUNla3ND5MTW48ka4YRtVl1/g2GazxJHwXBn3 0cjiQnUPJHSTlCXwKUDRtIreEZegp4pkbVd8+KnsSEiat4uBAMK2tqLoXeKaMVpPYzgW kmDxHH3qosGrUg1iujsuTZKbbnUnd4QsUVQUVnu8VOpLmaRX3rcTCP6Iz6m+Y2xbjbHd 13fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature; bh=xmLU2VoxBI1AblI7e4+GVmT5PEuDGrr9Ez3gDZemTlo=; b=WrJ4zKNVy8lC+lUqn0mjg2FFKYwvlI7ug/ziB+3Vpuh/332jIPuVoEx48Matm/7E5D pjSw8mz+220RDmLTZ9PGnJlbwG3Ee9gLUB1fWagM5/0Gj9Zh6F+LI2II83nB2Mbp5B6O 9K6qf8HezwF8rNmPzGaAFHCzvOjL4xnnx6f2i4CWw9aK0SzYBwr+oOgJHOyLcwA23bdA Un1PyeBgyyWgjSDt+5jJYWzx20ZO7VZyuOdKax2QUD5kOCH0zWAXRg0czezkltNKbN7t 0crRCR6QmOSWgRbwinTYQPdIfuBZJrWlh7p3SStsCWSwGG6GQrTzt3YP4XY1yXAxaeiS QzWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukuye4IL; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b22sor3942539pfe.48.2019.01.11.07.07.54 for (Google Transport Security); Fri, 11 Jan 2019 07:07:54 -0800 (PST) Received-SPF: pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ukuye4IL; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-Smtp-Source: ALg8bN78QYDL7o7tAWys1x+bFJlndFbFXr9PHUkCoW3OrmZHFdsg9IHHrJ+vfOFuzdNqNQM2dbbwhg== 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-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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.