Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp761648ybl; Fri, 6 Dec 2019 05:55:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzncsDS+qj2+09njFCufSwm4OZuuHG6bYx7OI7WskLKtPeosqtUop5iIQ4yk86E9c+rTVgf X-Received: by 2002:a9d:191f:: with SMTP id j31mr10532362ota.163.1575640527026; Fri, 06 Dec 2019 05:55:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575640527; cv=none; d=google.com; s=arc-20160816; b=rOJWClM7pmp1K+qHpcBUjTvpfrWaEyfCYfeC+XFhcKCVO1cSs/TWM57YhwfB72P+UZ oyeUScR7QL79h3DHgd0+Tnb3xdY2iFh0QR1neKAGSNX0+Zof4Bc8qhQPJ8vC+Wy+bvvH UN9PCqCjgUdngRUwP3LQxdwXq9wUA0rtY+JvvW3mn7jGtaZkUHtPymET7FPoIMysc1Lf RiMnC+TQ3r1lauiz350AyLMMALWRJcQMrTkBpOPIEd9wBQN87bYdj74IxlNPY7HlodhD UJ3RqTAuXOjfSdKyKZzTX16fz6y3lHLtRHH4ObnKrbOmMJjRxvSC1I0dzefZTnh8KUff bqrQ== 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; bh=kwaxMRSFA23jFKGkwr9WiJmfUCkNJuQIY9yqh7PIv58=; b=xqBtys2C9drGVI3x5HaNMGbzSjZPSTq/PpYoGntiZgCgYL4DPSDTgLAo7jmwCsIYu8 5AziKo1y3q+Eo+RunaBLZ8nkjURiM+laxKy4OhuvobNm1GeqQcZ4ohqc9QRDtokY8Pc8 m0EMIof1gNwls5jJ0GyqhmH/58Ks5r1kTMv3xYR4/+LXyoA+sMc8LqVKBThFWWeNcYLz JCNrbORH250SZReVyOce+cITC1vykD08KrTRwxpvfxntAcToSVeBbPEkIvFcQjXIdcjv my0MEyEsPTWePtqPN/R9/8dMgDBulifl2Z8uEDv+icm9MX5ZnyTh8pNW0QQ28Yhf9L+m 07JA== ARC-Authentication-Results: i=1; mx.google.com; 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 s18si6986473otq.131.2019.12.06.05.55.14; Fri, 06 Dec 2019 05:55:27 -0800 (PST) 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; 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 S1726816AbfLFNy2 (ORCPT + 99 others); Fri, 6 Dec 2019 08:54:28 -0500 Received: from foss.arm.com ([217.140.110.172]:44816 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726809AbfLFNyZ (ORCPT ); Fri, 6 Dec 2019 08:54:25 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 951F3113E; Fri, 6 Dec 2019 05:54:24 -0800 (PST) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 157723F718; Fri, 6 Dec 2019 05:54:21 -0800 (PST) From: Steven Price To: Andrew Morton , linux-mm@kvack.org Cc: Steven Price , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Dave Hansen , Ingo Molnar , James Morse , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Peter Zijlstra , Thomas Gleixner , Will Deacon , x86@kernel.org, "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , "Liang, Kan" Subject: [PATCH v16 14/25] mm: pagewalk: fix termination condition in walk_pte_range() Date: Fri, 6 Dec 2019 13:53:05 +0000 Message-Id: <20191206135316.47703-15-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191206135316.47703-1-steven.price@arm.com> References: <20191206135316.47703-1-steven.price@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Steven Price --- mm/pagewalk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 1b9a3ba24c51..88104ab00a97 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -18,9 +18,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.20.1