Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp672281img; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGOlRd8ahlCMM7cmZMB6mxo1pU83eIU8ObSq/iBUmH1WMNw2JEoFVb7nbN6jEXctuu39PM X-Received: by 2002:a17:902:290b:: with SMTP id g11mr9503233plb.269.1553260743264; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553260743; cv=none; d=google.com; s=arc-20160816; b=Geqj6NMTh0JRlWHP3g8oTTj+NLoH80lMiawnmqGkFSu7N0IBqnIFMbxOfGoXG6FAWs rrvCqvlVL259AsTrlAzTNy9PFkh4Y45SKX5VEqCxDuNMCWmAR1T4qmhM/HM+1SlKcg7P +H5fEknjy31IbuDQXH3t9wRRiNrCVE9M9MTTXbCsmuKup3goQW5doPurYCBPnkTyEFWG hunMGGenkcgdX6/NulGbrrTagYqvO9i22Asb4XiFUCx0bWfneGaTx7RljJ2mVo5XhgkX BspgycTtYzCl/18JY0gbhBB/vqK0XTAmi1GqODiVw0qjCjWpJk+XBuy8Y1dspvnwF4Wt ROqQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6KuzlZmOZ4B4vzhnuida/fLKz83KxnWfe3gEHORKPeM=; b=APX4vhvNbzB8ZbDZCVix7qv4wCaa3Gu8y2nelCCSEZWFuPoGu8e4jQ7uJTV8UNHah4 amCX0qOEWdzuwdKo886yjln2XsU4qOzqWUFJ1jUobLJHQ59zY+s97fvrspRC6xuPifKN kKFc8J3VydTybRtz5HOxcKqfa5/kaCvYT4RzIuVOvzTMLX9+1ClgOwcnB58QJJSBZYxY MD4lHlhnhRQ7xtGHG3zHrfCpoREqGHBAZYRcQ5tnCbWRsg0vvKUjnmNoOWFSyRCI/WxV CFkmjSvdkqquAPIxLRw66eFLaCf0Lw/W7TuIdcPacv9+5LBPAuAmbdwKzKMpi1yl3qyG A1Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="iVHP/1ew"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11si6712968pls.237.2019.03.22.06.18.45; Fri, 22 Mar 2019 06:19:03 -0700 (PDT) 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=@kernel.org header.s=default header.b="iVHP/1ew"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbfCVNQh (ORCPT + 99 others); Fri, 22 Mar 2019 09:16:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:54350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728510AbfCVL0i (ORCPT ); Fri, 22 Mar 2019 07:26:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E3A2D218A2; Fri, 22 Mar 2019 11:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553253997; bh=HAyCZq/oIuQ67uR5cIbDu8hncq4VM9MZDnW9YQMf6gQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iVHP/1ewIPc+xlLTR1tBLPJBXc7dNDha8kXyU3rAtu7WS+oGIzooInHBU4eZOanGf 89h9cPH/YOrM0n6eUePCzdmCGka27aZ0ytZRRIgcRIfrooohySzWM8VQM2lj9chWr3 pKip61teDOHo68TecqWrhy/sv7Yr45DNUQqhk8aM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Roman Penyaev , Michal Hocko , Andrey Ryabinin , Joe Perches , "Luis R. Rodriguez" , Andrew Morton , Linus Torvalds Subject: [PATCH 3.18 120/134] mm/vmalloc: fix size check for remap_vmalloc_range_partial() Date: Fri, 22 Mar 2019 12:15:33 +0100 Message-Id: <20190322111219.063712948@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Roman Penyaev commit 401592d2e095947344e10ec0623adbcd58934dd4 upstream. When VM_NO_GUARD is not set area->size includes adjacent guard page, thus for correct size checking get_vm_area_size() should be used, but not area->size. This fixes possible kernel oops when userspace tries to mmap an area on 1 page bigger than was allocated by vmalloc_user() call: the size check inside remap_vmalloc_range_partial() accounts non-existing guard page also, so check successfully passes but vmalloc_to_page() returns NULL (guard page does not physically exist). The following code pattern example should trigger an oops: static int oops_mmap(struct file *file, struct vm_area_struct *vma) { void *mem; mem = vmalloc_user(4096); BUG_ON(!mem); /* Do not care about mem leak */ return remap_vmalloc_range(vma, mem, 0); } And userspace simply mmaps size + PAGE_SIZE: mmap(NULL, 8192, PROT_WRITE|PROT_READ, MAP_PRIVATE, fd, 0); Possible candidates for oops which do not have any explicit size checks: *** drivers/media/usb/stkwebcam/stk-webcam.c: v4l_stk_mmap[789] ret = remap_vmalloc_range(vma, sbuf->buffer, 0); Or the following one: *** drivers/video/fbdev/core/fbmem.c static int fb_mmap(struct file *file, struct vm_area_struct * vma) ... res = fb->fb_mmap(info, vma); Where fb_mmap callback calls remap_vmalloc_range() directly without any explicit checks: *** drivers/video/fbdev/vfb.c static int vfb_mmap(struct fb_info *info, struct vm_area_struct *vma) { return remap_vmalloc_range(vma, (void *)info->fix.smem_start, vma->vm_pgoff); } Link: http://lkml.kernel.org/r/20190103145954.16942-2-rpenyaev@suse.de Signed-off-by: Roman Penyaev Acked-by: Michal Hocko Cc: Andrey Ryabinin Cc: Joe Perches Cc: "Luis R. Rodriguez" Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2140,7 +2140,7 @@ int remap_vmalloc_range_partial(struct v if (!(area->flags & VM_USERMAP)) return -EINVAL; - if (kaddr + size > area->addr + area->size) + if (kaddr + size > area->addr + get_vm_area_size(area)) return -EINVAL; do {