Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5616036img; Wed, 27 Mar 2019 11:46:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6pUxg/K3gLZZUFmG3JmipJpCCkuSHtPxpLmLFiOuDFxI1v+7CRDyLhqkiKjP/BhjTZt8e X-Received: by 2002:a63:cc03:: with SMTP id x3mr35436322pgf.121.1553712413097; Wed, 27 Mar 2019 11:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712413; cv=none; d=google.com; s=arc-20160816; b=IOvx/aW9TA5Xc4eDfKclY6QzK+x6mmSCH25oVnIcu9/VV4dK+T6C2bmmqdi9432W4G JKcbCaqcEH1boKHTiR/s+LxOGH/UkmRjtUB00bdhB2qIKhNo2BbbhN/k53eP9GQ4JhJb p3SezzWi80a+XRDZu/e3DrmdEPQfG3sDg4Y8/vLgo9n2Bz8P8v1infuXvSanaw4y3nkX /FBAdMVo378Gkg97FoYm109mqWlZlMxvNzi9WU4dARsZP7vJ576/DGQ39cMDrKeHD9aZ VlHYmGtGB8uwF5LiZpAHrjDb6/V7KLknkNxGf8pO9UGHhciok8fICJcfTrn9pjn9qlIC 4NLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LsyZcMWcLFIiH/+e+8c/BbZp6CJ/Ezs0i8f8RkqPre0=; b=ypy/+Ma29m8U1mbDmYVJ6x47thVnDboqJMnvEyv1/Coe53r+ZzH4LotNyl6589o+Jq wp7ZpAra7q3Ig173tzEzWQQwwRKo/jjsZxEVkDQ20sSWi6yv93ZVfs7skWE+2Gl7XMP+ R0B7chQ8J/j7uf4UW6p6M+eEBTy33ro4Xqv+Zsu6RGi3F2ODqqFpSQXmF8aRCAKDPf1n YuzGwFOCT6X2vwR9SjqiKrkefFuX960EyUQ5J1Bw1PmAYDhUVHXhjIaVAwpbbhgxRr0p g1nODwKqIhK4LQId+kh/SdD+pUkJGzzOC80BwqG4AbL2wFMIaDqCEtLIMoOy8UhrPxgX Ogsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F1CYIjoy; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r198si18648936pgr.519.2019.03.27.11.46.37; Wed, 27 Mar 2019 11:46:53 -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=F1CYIjoy; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391728AbfC0SpP (ORCPT + 99 others); Wed, 27 Mar 2019 14:45:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:38822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389351AbfC0SVF (ORCPT ); Wed, 27 Mar 2019 14:21:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C492E20643; Wed, 27 Mar 2019 18:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710864; bh=KopFzjyqiGzG6wk/FnitGtZe8KmXMgXBUElcH87QTQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F1CYIjoy1SpwNNZOEJrSmd/7Rr06sRebaCwL88QQ85Gp28hBFjUyPY3sbmjBnbruU j3963DFxFcz53GRlbkHfs1WuI5RVUo9xnEM+ztHihaVytImB/pzy9YhabaJrdGFrpO qJrQ5xQuIYzK3JN1oR8S2V/w97VjE2zscrMcb9JI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Uladzislau Rezki (Sony)" , Ingo Molnar , Joel Fernandes , Matthew Wilcox , Michal Hocko , Oleksiy Avramchenko , Steven Rostedt , Tejun Heo , Thomas Garnier , Thomas Gleixner , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.9 12/87] mm/vmalloc.c: fix kernel BUG at mm/vmalloc.c:512! Date: Wed, 27 Mar 2019 14:19:25 -0400 Message-Id: <20190327182040.17444-12-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Uladzislau Rezki (Sony)" [ Upstream commit afd07389d3f4933c7f7817a92fb5e053d59a3182 ] One of the vmalloc stress test case triggers the kernel BUG(): [60.562151] ------------[ cut here ]------------ [60.562154] kernel BUG at mm/vmalloc.c:512! [60.562206] invalid opcode: 0000 [#1] PREEMPT SMP PTI [60.562247] CPU: 0 PID: 430 Comm: vmalloc_test/0 Not tainted 4.20.0+ #161 [60.562293] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 [60.562351] RIP: 0010:alloc_vmap_area+0x36f/0x390 it can happen due to big align request resulting in overflowing of calculated address, i.e. it becomes 0 after ALIGN()'s fixup. Fix it by checking if calculated address is within vstart/vend range. Link: http://lkml.kernel.org/r/20190124115648.9433-2-urezki@gmail.com Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Andrew Morton Cc: Ingo Molnar Cc: Joel Fernandes Cc: Matthew Wilcox Cc: Michal Hocko Cc: Oleksiy Avramchenko Cc: Steven Rostedt Cc: Tejun Heo Cc: Thomas Garnier Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/vmalloc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e6aa073f01df..73afe460caf0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -459,7 +459,11 @@ static struct vmap_area *alloc_vmap_area(unsigned long size, } found: - if (addr + size > vend) + /* + * Check also calculated address against the vstart, + * because it can be 0 because of big align request. + */ + if (addr + size > vend || addr < vstart) goto overflow; va->va_start = addr; -- 2.19.1