From patchwork Wed Aug 8 11:16:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10559771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D30414E2 for ; Wed, 8 Aug 2018 11:22:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59E992A8AA for ; Wed, 8 Aug 2018 11:22:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C4EB2A8B4; Wed, 8 Aug 2018 11:22:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3D5D2A8AA for ; Wed, 8 Aug 2018 11:21:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1BB46B000A; Wed, 8 Aug 2018 07:21:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BCBCA6B000C; Wed, 8 Aug 2018 07:21:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A925C6B000D; Wed, 8 Aug 2018 07:21:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 4A43F6B000A for ; Wed, 8 Aug 2018 07:21:53 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id t10-v6so796124eds.7 for ; Wed, 08 Aug 2018 04:21:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=N8B4DQ3yEXqtFsPVQCsaZjzkUQZe9C3dif3AU9U2DZk=; b=AJj7E9jXruGUFmW0mZpYnCx/HUF9CnTKD99R5Umkn5m8uLlVTmPXdNQjk1ONOIgB7o hvRJFbhVmRi9AFUAvg1776+oWWBKTobQJyZHJFtupufIjPxPuyGYxTLmWG3xRz7MxgDk i75xbCXYYYvTHlWk0I8aHKcQBcFRR28GahAdSCZvJs8V70w7E2vd673aZN21x78Adyo1 qJmwfBi9G+ovZWdfvkIKPBtEefKG4K7cgErAvjHqXpTatp0dRhz3I9GtnwsHzW/fPZ1i dNv4oRXBtyFnAR7pFHdNh+y00YbX6x3w5SX+u5FOh162b9ww5EFzpiORIdp17NmSb1fU xtUQ== X-Gm-Message-State: AOUpUlF7UunYw1FGUGEFJ0owx3rR+a1GFPHh9un6+ibcF1rC87pPODpQ zV+PIVorCY4zUE4Rso+Q8voZcZEoo051dysZFm62dJgJCaLnuL1Gqd1+Is7RT91VMwiyojf0/b6 8ywQXCkLJzhU+zlseOiOQxYUpK/Q28LEJ1uCF6xsaTzA8oPI/HfWNsxSG/Q3bpI6Lgg== X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr2704261edb.111.1533727312735; Wed, 08 Aug 2018 04:21:52 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzPHLrIY95t7blpxnUJ8MKyqS6dj0HyrZ5otNp9SmDq8xpLOBu7h4R/e3Bd58rYrOtUueqZ X-Received: by 2002:a50:99db:: with SMTP id n27-v6mr2704192edb.111.1533727311593; Wed, 08 Aug 2018 04:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533727311; cv=none; d=google.com; s=arc-20160816; b=iLbpMN/bJX+RzwyHkGCEVIhktskBSWrLO9ZPuI6/OhfXYEMUaX7eFor6S178gwFr3g 4na+btmRaOfxByZv/XQ5xI3cF3SKOsPmDWE+VHyf/XauQKL20tDSrFfU9+Ail+Xh9rJh 7+2PMyIeBqbtog26fbpPXukKhu4N58w9JPsXNfzwhOdFmckP6Zec9en1IQ6N8AzuJwL5 CYguLfMOwMsHVhjPZSA/jZLNTFZO+svyaXqOjvV/i1vhs1RRAh8AK6FkZVzQajYALohF X19DQ/gEM5YUUIZdf4e5bttelo/WaiZ/chZZDn2YytBUR3UqWVlBjZqqCymdt88BZKq1 gaew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=N8B4DQ3yEXqtFsPVQCsaZjzkUQZe9C3dif3AU9U2DZk=; b=eYYg9FrWfumh/7Msgy5BOp85nxR0I+zyFXzUjYL2jrP7/rep2nUGM4crFslNJuQDMF GVq/bsuqQmG5tGGc6jhlzOEBkmqKkgNILr1RocSSzB4VeKoSlnJ0AMVReDVSucdZd+PY noaFQMX5N0obkprNWj9qVDwSOWXHv9MY1OIKCsJA3FpSBh1UGjzFiBIOPQtrnOV5c1VE AHx+itQ4aBarp5BAdulciXMd5gD1K0fjKJl6sKxxpm7TB5FuoOJWqTXoQ2AUMpOyhtzL jRzaul0wdW8xccl8pRWLciN8qxCNRFhLCqcBw19iVGdYevk9mbFXzv/l294wD/mFu+4/ hsTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=q5BHcFZG; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: from theia.8bytes.org (8bytes.org. [81.169.241.247]) by mx.google.com with ESMTPS id u24-v6si3909123edi.415.2018.08.08.04.21.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 04:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) client-ip=81.169.241.247; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=q5BHcFZG; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: by theia.8bytes.org (Postfix, from userid 1000) id D1E642EA; Wed, 8 Aug 2018 13:21:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1533727310; bh=5bv0qSO6zUgvBLoIEiLfGAXfUu5gCSUL3booLj+Fs20=; h=From:To:Cc:Subject:Date:From; b=q5BHcFZGK/IQ5TP31Sl8jWfWuH1q8tutPt+RA5JVQIyviJfq6+JEIDlADJvyzovvd jbJRtPcGcVjyed7t3qFq1QXVedRsTXF9w05zRQ4IIbUtNpPskiBQad1JzAd8EYKNId wAXTib2kYvHx+VhrVIOnh3U52BfOCS1KWMz464hdPpkVJvgoytJN2hVc+RgmRQZTAo bMzyE6FhNOajXiGxe+NpWTVdTl9leY1ZTvb2ZIL93z360j4n/uoGdS+QgeqYhipTkr BidwSo6yPZdkbuqBgSi/LFZy8O3wLYUws1/9p2L/j3smvBJtvsJ2eMnua3vlCvrxWB CgB90afcGlc9A== From: Joerg Roedel To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" , jroedel@suse.de, joro@8bytes.org Subject: [PATCH] x86/mm/pti: Move user W+X check into pti_finalize() Date: Wed, 8 Aug 2018 13:16:40 +0200 Message-Id: <1533727000-9172-1-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Joerg Roedel The user page-table gets the updated kernel mappings in pti_finalize(), which runs after the RO+X permissions got applied to the kernel page-table in mark_readonly(). But with CONFIG_DEBUG_WX enabled, the user page-table is already checked in mark_readonly() for insecure mappings. This causes false-positive warnings, because the user page-table did not get the updated mappings yet. Move the W+X check for the user page-table into pti_finalize() after it updated all required mappings. Signed-off-by: Joerg Roedel Tested-by: David H. Gutteridge --- arch/x86/include/asm/pgtable.h | 7 +++++-- arch/x86/mm/dump_pagetables.c | 3 +-- arch/x86/mm/pti.c | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index e39088cb..a1cb333 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -30,11 +30,14 @@ int __init __early_make_pgtable(unsigned long address, pmdval_t pmd); void ptdump_walk_pgd_level(struct seq_file *m, pgd_t *pgd); void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd, bool user); void ptdump_walk_pgd_level_checkwx(void); +void ptdump_walk_user_pgd_level_checkwx(void); #ifdef CONFIG_DEBUG_WX -#define debug_checkwx() ptdump_walk_pgd_level_checkwx() +#define debug_checkwx() ptdump_walk_pgd_level_checkwx() +#define debug_checkwx_user() ptdump_walk_user_pgd_level_checkwx() #else -#define debug_checkwx() do { } while (0) +#define debug_checkwx() do { } while (0) +#define debug_checkwx_user() do { } while (0) #endif /* diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index ccd92c4..b8ab901 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -569,7 +569,7 @@ void ptdump_walk_pgd_level_debugfs(struct seq_file *m, pgd_t *pgd, bool user) } EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level_debugfs); -static void ptdump_walk_user_pgd_level_checkwx(void) +void ptdump_walk_user_pgd_level_checkwx(void) { #ifdef CONFIG_PAGE_TABLE_ISOLATION pgd_t *pgd = INIT_PGD; @@ -586,7 +586,6 @@ static void ptdump_walk_user_pgd_level_checkwx(void) void ptdump_walk_pgd_level_checkwx(void) { ptdump_walk_pgd_level_core(NULL, NULL, true, false); - ptdump_walk_user_pgd_level_checkwx(); } static int __init pt_dump_init(void) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 69a9d60..026a89a 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -628,4 +628,6 @@ void pti_finalize(void) */ pti_clone_entry_text(); pti_clone_kernel_text(); + + debug_checkwx_user(); }