Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp880166pxk; Thu, 17 Sep 2020 20:11:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaBPesy/n8VlwkYQHjmuqvMucarnq6T1ELSwd5XLpkF/g2Ml1Ls18I0T6miPtLAqkHYmcp X-Received: by 2002:a50:a2e6:: with SMTP id 93mr34836607edm.147.1600398660495; Thu, 17 Sep 2020 20:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398660; cv=none; d=google.com; s=arc-20160816; b=iNS0e912eni8gnepDyy8BtrtQUAVRaSyF9fqTxdXT1p0tjeXOxVq1OaWYKWQiM5yNh c2ouAnuF8HDDXwTDaM1HmLydwi9rdbb+33VJivx7vnO/lf1c54FCLPNRYr0r5jWBb5mx TSqigWyaQtq6K4NfXMwzGd3zpC7wveo/6fUst3qyem77IwpguN+LPemDFq8yOm0MPUVM afrceoHgf2dj/y28vaw+kddA4Gco+02zDao4QN7p7e38nmEoMrDHXBECwSSGc+0rz5Iy vuh6bgsgm+fxWkKZQ7bOl0S7HwTB1/VUucu+6vXrP1Nm66paZ5dN8zfUrEYQLRFsMW4Q XhQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PRXiRNtxlsU5nfAyhmArzc0obcIuX1cfnO2ociaE4gA=; b=UsNkdSDx0o9bPAE4o+gTdf50xDfcJ70dUZz6+EZcqDnnKZoQ7ILKTpCXITgDTPnXU7 Tt0PoZg+Q0ad3r7N6isDPTcjnQx6SCj97ost57sBxgpREHaQptr9Er2MIzz5EfT6UnU9 5ncYNAiH0GUYbh85rX1iwC/r9y6+fQ2AzRd93VCTFe6yIUOass66jVedm8Uf3fnL4LF3 gMZiY7j8g7nUU2cIPWilw8YQnsyepBV3H0BXI/OiYwTswbuw5S0zgkMlXX/R7ZTLnYhy bFLjmMO1J9N+WJ2YxuPTl2chcdzc/kh5KLvthUPKux9EFnbQE0qxv1uQqe9yhOofH0Kh vzJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kNnF/8rC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id k15si1313739eji.77.2020.09.17.20.10.37; Thu, 17 Sep 2020 20:11:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="kNnF/8rC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730670AbgIRDIZ (ORCPT + 99 others); Thu, 17 Sep 2020 23:08:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:49804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727094AbgIRCDa (ORCPT ); Thu, 17 Sep 2020 22:03:30 -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 6B50C21734; Fri, 18 Sep 2020 02:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394610; bh=K0Jb/HJHp6k0yVKYX+TdvC6Dq2XDis/IGQzEdz0SJ9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNnF/8rCRZjsvgFLNejdel++KyvyEyfrE1z6OYpMjNLc3nabsHeR26i4Z2L47diyH 9nqTiTYxJ61xNxGCbxtfPTFHVvaSGNiEFUTnEgjt/8yTmysjNNiunkwF8E8UVkTHcq yfasCdK3/ZfRpJRxuALyNaPTw0R2OJQqUEQl1qHk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Steven Price , Albert Ou , Alexandre Ghiti , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Benjamin Herrenschmidt , Borislav Petkov , Catalin Marinas , Christian Borntraeger , Dave Hansen , "David S . Miller" , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , James Hogan , James Morse , Jerome Glisse , "Liang, Kan" , Mark Rutland , Michael Ellerman , Paul Burton , Paul Mackerras , Paul Walmsley , Peter Zijlstra , Ralf Baechle , Russell King , Thomas Gleixner , Vasily Gorbik , Vineet Gupta , Will Deacon , Zong Li , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 5.4 113/330] mm: pagewalk: fix termination condition in walk_pte_range() Date: Thu, 17 Sep 2020 21:57:33 -0400 Message-Id: <20200918020110.2063155-113-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Price [ Upstream commit c02a98753e0a36ba65a05818626fa6adeb4e7c97 ] If walk_pte_range() is called with a 'end' argument that is beyond the last page of memory (e.g. ~0UL) then the comparison between 'addr' and 'end' will always fail and the loop will be infinite. Instead change the comparison to >= while accounting for overflow. Link: http://lkml.kernel.org/r/20191218162402.45610-15-steven.price@arm.com Signed-off-by: Steven Price Cc: Albert Ou Cc: Alexandre Ghiti Cc: Andy Lutomirski Cc: Ard Biesheuvel Cc: Arnd Bergmann Cc: Benjamin Herrenschmidt Cc: Borislav Petkov Cc: Catalin Marinas Cc: Christian Borntraeger Cc: Dave Hansen Cc: David S. Miller Cc: Heiko Carstens Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: James Hogan Cc: James Morse Cc: Jerome Glisse Cc: "Liang, Kan" Cc: Mark Rutland Cc: Michael Ellerman Cc: Paul Burton Cc: Paul Mackerras Cc: Paul Walmsley Cc: Peter Zijlstra Cc: Ralf Baechle Cc: Russell King Cc: Thomas Gleixner Cc: Vasily Gorbik Cc: Vineet Gupta Cc: Will Deacon Cc: Zong Li Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/pagewalk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index d48c2a986ea3f..4eb09e0898817 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -16,9 +16,9 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, err = ops->pte_entry(pte, addr, addr + PAGE_SIZE, walk); if (err) break; - addr += PAGE_SIZE; - if (addr == end) + if (addr >= end - PAGE_SIZE) break; + addr += PAGE_SIZE; pte++; } -- 2.25.1