Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp20878ybp; Thu, 3 Oct 2019 09:36:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/AT2eVR5bvipxCml4vbbj6xcyZQh00aAaVy/qlG+4zWm3AbBvdW44IuKUgSCIaNvCGjRi X-Received: by 2002:a17:906:134b:: with SMTP id x11mr8397113ejb.272.1570120585625; Thu, 03 Oct 2019 09:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570120585; cv=none; d=google.com; s=arc-20160816; b=zcYjqTgwhxbIMslJBloavXHqXimueb/W7u90M8pU5/h+HX4Va5lsMmFWdo+++osKm/ xvp7iyI654HnHe/Wq/xU8HYg5qJqNsOJHY5BVN/e4cHEXEBVdHhxKpQePojwEP8k7+MH rMTDdy6iDCBa6fr31AqWaUc36x3iZOxQ3THYEF8EtqswWY346daScwY5LYHfQojAEeK8 W7xWF7XK8wJPl5dB1nMku8ZidtLMfOV0N3N8MsJhJJx5jYKSxCZBShe9prq8dcI0qiZh G9NVsFbp36R+5/GA/oQU1MPIY8//6408maC4Fz8j21Ir6tllY1pyT8pGSIoNIvD/BokC Ynlw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N8ibk3dOl5NxWu23JcKbxXfZoXBwGSVGBIafZAb8pkY=; b=gXj9kxLlrLzld5X5Hw57CQpHTjomniwIi2Yy13CmphGavusgPhJjjA9dimjO4sO5sB gH7jTg09FN/9ShMaLR7k5DszL7uQc8FglyC8MZbMkTGJvmSJ7jksY6U+YNh65IPLaXZe 66lhznbFl/p3iBVxaPKOAk8wLPM9HywPbTRqM5NaKYcZS0JI5cgbmlWfOD/Z3h3pqdoD k/RX0CdvhiWTvsuKvs13CmlbeURlv3++3q1BnChevKtYxs4yFxyrDH4ZuZ/MtRkMesKO XED9w+1jMhe/ybL9M1skdLxaYsKY+3b+CP+7y71QPRsZPBYL/NwnsC8ZiAEGr59nNyNQ 23Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=00wKocBB; 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 k7si1858493edb.238.2019.10.03.09.36.00; Thu, 03 Oct 2019 09:36:25 -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=00wKocBB; 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 S2404047AbfJCQdW (ORCPT + 99 others); Thu, 3 Oct 2019 12:33:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:41228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404124AbfJCQdS (ORCPT ); Thu, 3 Oct 2019 12:33:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 42A89215EA; Thu, 3 Oct 2019 16:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570120397; bh=YdtB9ERDjqPMpLb1hhSKMnEGtL5LAfOBUuAxVN22O04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=00wKocBBWNasNksPFmij14hafSI7lurfI5WALS/DKyy4noYBFn8Djx/cytniRSynM JjkYrvV62P/TEvj1KdWhrfJYG2UhsRUaAU5AEjCIcAgKgMfISG+Xg8/5Kv5+/5iywP EENE6VyPsOh4nThdJcqQ+m98ZaeN7KRDdMkyiv2s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Song Liu , Thomas Gleixner , Ingo Molnar , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.2 159/313] x86/mm/pti: Handle unaligned address gracefully in pti_clone_pagetable() Date: Thu, 3 Oct 2019 17:52:17 +0200 Message-Id: <20191003154548.602201222@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Song Liu [ Upstream commit 825d0b73cd7526b0bb186798583fae810091cbac ] pti_clone_pmds() assumes that the supplied address is either: - properly PUD/PMD aligned or - the address is actually mapped which means that independently of the mapping level (PUD/PMD/PTE) the next higher mapping exists. If that's not the case the unaligned address can be incremented by PUD or PMD size incorrectly. All callers supply mapped and/or aligned addresses, but for the sake of robustness it's better to handle that case properly and to emit a warning. [ tglx: Rewrote changelog and added WARN_ON_ONCE() ] Signed-off-by: Song Liu Signed-off-by: Thomas Gleixner Reviewed-by: Ingo Molnar Acked-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1908282352470.1938@nanos.tec.linutronix.de Signed-off-by: Sasha Levin --- arch/x86/mm/pti.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index ba22b50f4eca2..7f2140414440d 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -330,13 +330,15 @@ pti_clone_pgtable(unsigned long start, unsigned long end, pud = pud_offset(p4d, addr); if (pud_none(*pud)) { - addr += PUD_SIZE; + WARN_ON_ONCE(addr & ~PUD_MASK); + addr = round_up(addr + 1, PUD_SIZE); continue; } pmd = pmd_offset(pud, addr); if (pmd_none(*pmd)) { - addr += PMD_SIZE; + WARN_ON_ONCE(addr & ~PMD_MASK); + addr = round_up(addr + 1, PMD_SIZE); continue; } -- 2.20.1