From patchwork Fri Apr 3 16:32:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 11473155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D64B912 for ; Fri, 3 Apr 2020 16:33:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 43EC7206F8 for ; Fri, 3 Apr 2020 16:33:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KRyZMKFM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43EC7206F8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5C56C8E0008; Fri, 3 Apr 2020 12:33:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 575968E0007; Fri, 3 Apr 2020 12:33:07 -0400 (EDT) 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 4B1948E0008; Fri, 3 Apr 2020 12:33:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 30D6F8E0007 for ; Fri, 3 Apr 2020 12:33:07 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E1B23612E for ; Fri, 3 Apr 2020 16:33:06 +0000 (UTC) X-FDA: 76667088372.13.soap68_555e4948ab948 X-Spam-Summary: 2,0,0,157b976bc1611c8c,d41d8cd98f00b204,peterz@infradead.org,,RULES_HIT:41:334:355:368:369:379:800:960:973:988:989:1260:1261:1277:1312:1313:1314:1345:1437:1516:1518:1519:1534:1540:1593:1594:1595:1596:1711:1730:1747:1777:1792:2393:2559:2562:2903:3138:3139:3140:3141:3142:3352:3865:3866:3867:3870:3871:4250:5007:6261:6653:7903:8603:8634:10004:10400:11026:11473:11658:11914:12296:12297:12438:12517:12519:13069:13161:13229:13311:13357:13439:13895:14096:14097:14181:14394:14721:21067:21080:21433:21627:21939:21990:30054:30055:30089,0,RBL:205.233.59.134:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.55.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: soap68_555e4948ab948 X-Filterd-Recvd-Size: 3025 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 16:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=ZF+Ip9r0n6MFzf3R/fk5zen8jodRMHuqnK57s4fq5I4=; b=KRyZMKFMR2hlTriIUZmEdRae44 /wWewmvIlqZZs/O+7ipwhwHdGbXg6arMJI9AYhfjR0KJcrZbCCBvuQ+3orW4YN7ZDON/Gqj6Fzuj8 9CTth0R/yKI7M1fQu/ag+FYXZAcrvjfdIKQIXaz9MQ2U/snhW5XaF4DOQXexT7ZqJalYc+bSKwS09 Q5/yO0wY4uU1huqjRQg8/gxib12L8y5X91/2tLZLYaTuQ/GqF9JHjzN0FvrTb4V/dJVQmQRdJNN1j fOup5OyOLwQKATd/gXxTimbt8ZR2JatF6w41ggyXB9nBFKWqaahMXmQJzbvYJTi8Hvj81WBHyZfGz bCBOKL3Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jKPFX-00038Q-Sw; Fri, 03 Apr 2020 16:32:56 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4DC693056DE; Fri, 3 Apr 2020 18:32:53 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 335732B12078B; Fri, 3 Apr 2020 18:32:53 +0200 (CEST) Date: Fri, 3 Apr 2020 18:32:53 +0200 From: Peter Zijlstra To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jroedel@suse.de, vbabka@suse.cz, urezki@gmail.com, Thomas Gleixner Subject: [PATCH] mm/vmalloc: Sanitize __get_vm_area() arguments Message-ID: <20200403163253.GU20730@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline 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: __get_vm_area() is an exported symbol, make sure the callers stay in the expected memory range. When calling this function with memory ranges outside of the VMALLOC range *bad* things can happen. (I noticed this when I managed to corrupt the kernel text by accident) Signed-off-by: Peter Zijlstra (Intel) --- mm/vmalloc.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2130,6 +2130,13 @@ static struct vm_struct *__get_vm_area_n struct vm_struct *__get_vm_area(unsigned long size, unsigned long flags, unsigned long start, unsigned long end) { + /* + * Ensure callers stay in the vmalloc range. + */ + if (WARN_ON(start < VMALLOC_START || start > VMALLOC_END || + end < VMALLOC_START || end > VMALLOC_END)) + return NULL; + return __get_vm_area_node(size, 1, flags, start, end, NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0)); }