Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5654755img; Wed, 27 Mar 2019 12:32:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSNcoF/oICcfbmQt6mKJHcSUxH1OIWAggplW0N3HMgb9vas6xMjV3n0/a+D+HQqFyj3Aqs X-Received: by 2002:a63:5d04:: with SMTP id r4mr26346617pgb.117.1553715136010; Wed, 27 Mar 2019 12:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715136; cv=none; d=google.com; s=arc-20160816; b=0WVG0uDe6e1SCrlwaWaqTtYqBWF3rIBKxKbkTmCeHbdUY/x0eEYXuBn5wb71SVbLXi eJchuuLSx0oGqDCm4UQhI2qxULDYyfyF2U+3mFqm2RxPCMN1GZR8EeQBdFMnBgNGOmUy WRo7gKD18phWSdqJyD44eaEDcwB+Ku1mHkjufq4FXMkzvEXm21ybFhlwa74vPwUaED2L WaI7+G2IOfgnmuwihWjHbz9dMcB6nIKhz+SAW43rmO6Jf1kSWcJUjslj4E/yOK9leOmV OpEerGvJ2yCMu51nADOS791ciccyzZvtfOTvkRwyNHbsQh2dtEUUMZOmgwvz1YYnCNIo 1fGw== 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=HxZQCMfQMuUqXY9wAy0wjCaaLxZqg540IGKWFOCtCIg=; b=bI+c5y1PV79ula7dloiyy8ZJuZGzEKHt9/XUqSJ36H8s9bODmO/ZfAvYI7+9QJYK4k Qsk4+uGJoA9fDBRq8uaW+qJn7IlJ2fbLlScCgEFeZ40OYk9/cMaMMZDf7ByDKN27Lm/r K+wS0sVXQJevBIj3X/lRtAQ6JGblQtYBEZFf3ISccHiq+0nuYfaZfLhhPxTqzpG0pfm2 08YXNT4pEyV3D9MWSWcu/fzdtod0VBTyBonchFXBi8rimvIOykRF8N1vM345Bk538gsX ictSh0R5y2SDkfdWUWEdL76epYRzj1t0d9jt8Kf3dJrwOgAslxOiYEW9KEBYyRJEWN7c OjhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q2zq7sZo; 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 d9si21334711pln.403.2019.03.27.12.32.00; Wed, 27 Mar 2019 12:32:15 -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=Q2zq7sZo; 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 S1732186AbfC0SDP (ORCPT + 99 others); Wed, 27 Mar 2019 14:03:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43252 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732010AbfC0SDK (ORCPT ); Wed, 27 Mar 2019 14:03:10 -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 5488821738; Wed, 27 Mar 2019 18:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709790; bh=VcSMi5SB+nqATDrzE4hHwpKxihfdy2+RbrKYIW5+tgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2zq7sZo+ckE2vgUwf/aehALzfjSzL0AvyErXKlTJZVQYqy7v2vjvgv5v5IKIjYkO jBwMe2x8l8Gd+DGgw2s9pbAltoLlPVKkEy+CwTr2h/lvbD9PJ9yxO1LS1oRVGgjRSP sitfc4bL+JhzGD86V5zGtORL05ohI4M9W/zOhSK0= 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 5.0 038/262] mm/vmalloc.c: fix kernel BUG at mm/vmalloc.c:512! Date: Wed, 27 Mar 2019 13:58:13 -0400 Message-Id: <20190327180158.10245-38-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-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 2cd24186ba84..583630bf247d 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -498,7 +498,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