From patchwork Tue Mar 19 02:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10858749 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 E34B115AC for ; Tue, 19 Mar 2019 02:27:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C642729470 for ; Tue, 19 Mar 2019 02:27:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B817A29500; Tue, 19 Mar 2019 02:27:13 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6618C29470 for ; Tue, 19 Mar 2019 02:27:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h64Rc-0006xi-7m; Tue, 19 Mar 2019 02:25:36 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h64Ra-0006xb-Sn for xen-devel@lists.xenproject.org; Tue, 19 Mar 2019 02:25:34 +0000 X-Inumbo-ID: 45b964d1-49ee-11e9-bc90-bc764e045a96 Received: from mail-pf1-x441.google.com (unknown [2607:f8b0:4864:20::441]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 45b964d1-49ee-11e9-bc90-bc764e045a96; Tue, 19 Mar 2019 02:25:33 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id a3so12591199pff.11 for ; Mon, 18 Mar 2019 19:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n/NDS47nz9uuNytg4LeJJ+li959uQqsTwzm1mhrxiWA=; b=jiBtkKMLnhknyJBqO0pykSJ1rbddZqUTZxiCQSo/SQdWsCg6rLr0Cy1/XcNb01JLUe arpg6kvnCyN5mQVoBrYIXH3jjsPbg038amLqb/8cOmOdXYXMUoJGico4viaD0NRc4vzS tqNZi/bzEiId0TsLouzvEpgHrIloi0yxX3b5HKTc68Ot8AOc22832Bwi6kZpXbWljicc Z6NmfIIGCh7KJixA06QsQBncUA/fr0iFgC3sIQ2960zrQ/E63Zzk79r1DAeIZ/RVs56o Z92k7Ksf6tDBHwMo12HW/o2rx8yQUNX35Sfm4tjZIIcRXJ2dzt3xtZBPd9C4QamrFLr+ ZhPw== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n/NDS47nz9uuNytg4LeJJ+li959uQqsTwzm1mhrxiWA=; b=bzeiXHkJJ47WymirQE+ShY8SMpj+ufJz4N6FedaeUD1/bDsb2DSEvLTRD4o0/pq1Nc QsnR80DZUtzFi9X+RoaBhylff/0n92OhevkYGy315VWjW6KvKwRAz6AnZcHL8TQX7Vad JoqGf5lqZwLNbNE5Ptzo6lvYMWXu5s4DS3/CM8FC85EZ+iTHyv3d/ROT06x2QHQFJXoW ePxUZ8im9t4ooV+Prh6/1ynBVNx5Y7Y3PeAA8VooPBi2vTtYtzq9qduxdsVCCewjTfNn DJEYNBHI4JpNAwzOGxcIuJrabmOQKGv+klB6mxH2Z/aecDnYElv9rCtQEadkfQOMVdwl 8YtA== X-Gm-Message-State: APjAAAV6eryIY+BrmeOKImNtV8vgrK5KUzWHuUtY4byPKdokIdsn6Ddb UwN1nW6tRIz8Fs1n7X613oc= X-Google-Smtp-Source: APXvYqw25r5MaAPOEBNu+onH2jr/m6hG8lprEL1PtpTxaPWtjQk1ZzP3VFv20URyYkFjUUqJo+9YQg== X-Received: by 2002:a63:ff0f:: with SMTP id k15mr7714pgi.301.1552962332881; Mon, 18 Mar 2019 19:25:32 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC ([106.51.22.39]) by smtp.gmail.com with ESMTPSA id b17sm3327180pgj.79.2019.03.18.19.25.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Mar 2019 19:25:32 -0700 (PDT) Date: Tue, 19 Mar 2019 08:00:07 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org, mhocko@suse.com, boris.ostrovsky@oracle.com, jgross@suse.com, linux@armlinux.org.uk, robin.murphy@arm.com Message-ID: <88e56e82d2db98705c2d842e9c9806c00b366d67.1552921225.git.jrdr.linux@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [Xen-devel] [RESEND PATCH v4 8/9] xen/gntdev.c: Convert to use vm_map_pages() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Convert to use vm_map_pages() to map range of kernel memory to user vma. map->count is passed to vm_map_pages() and internal API verify map->count against count ( count = vma_pages(vma)) for page array boundary overrun condition. Signed-off-by: Souptick Joarder Reviewed-by: Boris Ostrovsky --- drivers/xen/gntdev.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index 5efc5ee..5d64262 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -1084,7 +1084,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) int index = vma->vm_pgoff; int count = vma_pages(vma); struct gntdev_grant_map *map; - int i, err = -EINVAL; + int err = -EINVAL; if ((vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_SHARED)) return -EINVAL; @@ -1145,12 +1145,9 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) goto out_put_map; if (!use_ptemod) { - for (i = 0; i < count; i++) { - err = vm_insert_page(vma, vma->vm_start + i*PAGE_SIZE, - map->pages[i]); - if (err) - goto out_put_map; - } + err = vm_map_pages(vma, map->pages, map->count); + if (err) + goto out_put_map; } else { #ifdef CONFIG_X86 /*