From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89C55C3A5A1 for ; Wed, 28 Aug 2019 14:31:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 662C62080F for ; Wed, 28 Aug 2019 14:31:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbfH1Obm (ORCPT ); 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; }