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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 3B449C433E0 for ; Tue, 16 Mar 2021 06:47:41 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 124E46522E for ; Tue, 16 Mar 2021 06:47:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 124E46522E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4F03kf3Zxhz30L3 for ; Tue, 16 Mar 2021 17:47:38 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=csgroup.eu (client-ip=93.17.236.30; helo=pegase1.c-s.fr; envelope-from=christophe.leroy@csgroup.eu; receiver=) Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4F03kG3J2sz2yhG for ; Tue, 16 Mar 2021 17:47:17 +1100 (AEDT) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4F03k93y3yz9v01q; Tue, 16 Mar 2021 07:47:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id b3u_bTioaJ4D; Tue, 16 Mar 2021 07:47:13 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4F03k9372mz9v01p; Tue, 16 Mar 2021 07:47:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 06F278B77F; Tue, 16 Mar 2021 07:47:14 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id eKQZJbYM6dcF; Tue, 16 Mar 2021 07:47:13 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 66F8B8B766; Tue, 16 Mar 2021 07:47:13 +0100 (CET) Subject: Re: [PATCH v9 4/8] powerpc/mm/ptdump: debugfs handler for W+X checks at runtime To: Jordan Niethe , linuxppc-dev@lists.ozlabs.org References: <20210316031741.1004850-1-jniethe5@gmail.com> <20210316031741.1004850-4-jniethe5@gmail.com> From: Christophe Leroy Message-ID: <6d91193f-1428-67f2-eaaa-59f41859af7c@csgroup.eu> Date: Tue, 16 Mar 2021 07:47:10 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210316031741.1004850-4-jniethe5@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: christophe.leroy@c-s.fr, ajd@linux.ibm.com, Kees Cook , npiggin@gmail.com, naveen.n.rao@linux.ibm.com, dja@axtens.net Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Le 16/03/2021 à 04:17, Jordan Niethe a écrit : > From: Russell Currey > > Very rudimentary, just > > echo 1 > [debugfs]/check_wx_pages > > and check the kernel log. Useful for testing strict module RWX. > > Updated the Kconfig entry to reflect this. > > Also fixed a typo. Why not just perform the test everytime someone dumps kernel_page_tables ? > > Reviewed-by: Kees Cook > Signed-off-by: Russell Currey > Signed-off-by: Jordan Niethe > --- > arch/powerpc/Kconfig.debug | 6 ++++-- > arch/powerpc/mm/ptdump/ptdump.c | 21 ++++++++++++++++++++- > 2 files changed, 24 insertions(+), 3 deletions(-) > > diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug > index ae084357994e..56e99e9a30d9 100644 > --- a/arch/powerpc/Kconfig.debug > +++ b/arch/powerpc/Kconfig.debug > @@ -371,7 +371,7 @@ config PPC_PTDUMP > If you are unsure, say N. > > config PPC_DEBUG_WX > - bool "Warn on W+X mappings at boot" > + bool "Warn on W+X mappings at boot & enable manual checks at runtime" > depends on PPC_PTDUMP && STRICT_KERNEL_RWX > help > Generate a warning if any W+X mappings are found at boot. > @@ -385,7 +385,9 @@ config PPC_DEBUG_WX > of other unfixed kernel bugs easier. > > There is no runtime or memory usage effect of this option > - once the kernel has booted up - it's a one time check. > + once the kernel has booted up, it only automatically checks once. > + > + Enables the "check_wx_pages" debugfs entry for checking at runtime. > > If in doubt, say "Y". > > diff --git a/arch/powerpc/mm/ptdump/ptdump.c b/arch/powerpc/mm/ptdump/ptdump.c > index aca354fb670b..78497d57b66b 100644 > --- a/arch/powerpc/mm/ptdump/ptdump.c > +++ b/arch/powerpc/mm/ptdump/ptdump.c > @@ -4,7 +4,7 @@ > * > * This traverses the kernel pagetables and dumps the > * information about the used sections of memory to > - * /sys/kernel/debug/kernel_pagetables. > + * /sys/kernel/debug/kernel_page_tables. > * > * Derived from the arm64 implementation: > * Copyright (c) 2014, The Linux Foundation, Laura Abbott. > @@ -459,6 +459,25 @@ void ptdump_check_wx(void) > else > pr_info("Checked W+X mappings: passed, no W+X pages found\n"); > } > + > +static int check_wx_debugfs_set(void *data, u64 val) > +{ > + if (val != 1ULL) > + return -EINVAL; > + > + ptdump_check_wx(); > + > + return 0; > +} > + > +DEFINE_SIMPLE_ATTRIBUTE(check_wx_fops, NULL, check_wx_debugfs_set, "%llu\n"); > + > +static int ptdump_check_wx_init(void) > +{ > + return debugfs_create_file("check_wx_pages", 0200, NULL, > + NULL, &check_wx_fops) ? 0 : -ENOMEM; > +} > +device_initcall(ptdump_check_wx_init); > #endif > > static int ptdump_init(void) >