Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp945064ybl; Wed, 28 Aug 2019 07:32:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMbxF6EQ90QE6xxtOmlEnepYfEoIecDfF27Kz68kwZb3o8GrmaBGfdMa3nYss3w/YUL88e X-Received: by 2002:a17:902:9686:: with SMTP id n6mr4511584plp.113.1567002771802; Wed, 28 Aug 2019 07:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567002771; cv=none; d=google.com; s=arc-20160816; b=mDblpH0kCODQDid49KOFjx/DdjTxEkSR5TmMkxtzNsJIDOX0BZvOzzIZ3u8NeA7ZTA R86kw4S7QWl8ek0zJulCXEU10BuGgMHPvs2fJIPq0d1I4wZ8To1mJ7/uNg6VDfhrZKJm honI060e0Ywim0ZKBX3aiB2lQ6dEYUprX0avLyfebOYhUKw+vnmorphI8hZ3BRIkXEY2 1g5hzIopXzlwUPvhiJU0lXUl/ngcoeriWWjndASWszdO0mjO2KxE76fY4zUlG47BXGet 5uKeqEvU9oRApRB6bdeN0yDEilqTx2LQKR0voFqNXiD4gFsYP7TADHS3K3YFLL1yq/O+ BqSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id; bh=ua2k0hgE9lXAaP2pjKAh2jfFFAW9nOHWzUbNCF4dHiM=; b=jSeRdBOkZzopAqFcwM43fcKSqLBvq2vuEjjaHye4ybeKp2bBx1PuyDhyGes9M0u0ZH QN4EdqbI/xsfIe+M611jstB4/6ROy0xo7HBtuF1ydrbCCHsPcRSI7ugzRpvFagPB2N+M PhRdvRyt9bY5USj60ScKrQGKgOXR9c2wnrIRLvNBaeqN2xALxm4CiuIDt6hluvRmiZem 96WTZ4pZoQjNutvItr/2zXqWFWSZPpY6GDjguW+DX5RwGBegRkYplKcq5x5KFWq50ZtN nGRlx2r/5TTwlM5xy/6S5UyVncaJwa3yG9pJmt41LR8xZpTIt1I3fKQYJTlNGjA4K1Ks pjvw== 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 r139si2724083pfc.276.2019.08.28.07.32.34; Wed, 28 Aug 2019 07:32:51 -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; 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 S1726796AbfH1Obm (ORCPT + 99 others); Wed, 28 Aug 2019 10:31:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:47535 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726513AbfH1Obm (ORCPT ); Wed, 28 Aug 2019 10:31:42 -0400 Received: from localhost ([127.0.0.1] helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1i2yz6-00061v-5d; Wed, 28 Aug 2019 16:31:40 +0200 Message-Id: <20190828143123.971884723@linutronix.de> User-Agent: quilt/0.65 Date: Wed, 28 Aug 2019 16:24:46 +0200 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Song Liu , Joerg Roedel , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Rik van Riel Subject: [patch 1/2] x86/mm/pti: Handle unaligned address gracefully in pti_clone_pagetable() References: <20190828142445.454151604@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Song Liu pti_clone_pmds() assumes that the supplied address is either: - properly PUD/PMD aligned or - the address is actually mapped which means that independent of the mapping level (PUD/PMD/PTE) the next higher mapping exist. If that's not the case the unaligned address can be incremented by PUD or PMD size wrongly. All callers supply mapped and/or aligned addresses, but for robustness sake, it's better to handle that case proper and to emit a warning. Signed-off-by: Song Liu Signed-off-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20190820202314.1083149-1-songliubraving@fb.com --- arch/x86/mm/pti.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -330,13 +330,15 @@ pti_clone_pgtable(unsigned long start, u 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; }