Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp648197ybl; Fri, 31 Jan 2020 05:36:09 -0800 (PST) X-Google-Smtp-Source: APXvYqzNgKrNMLTov3nx7ILt1wRuYv/U5pMgxkbv6n1CCFIV+u1qI1JOh1nVkZQUru7Myq4MC9Gi X-Received: by 2002:a05:6808:a08:: with SMTP id n8mr1707631oij.38.1580477769610; Fri, 31 Jan 2020 05:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580477769; cv=none; d=google.com; s=arc-20160816; b=CNZTMZngf7W0DTXxQZi1Kz2YSNEdGuQmCtZjr2UCBrQ3iLNp1ulxzCklUC+fPb627M IzHvYz3j8uzHrcY4xU2F3rBF6945DOCJm3+Xqm3ZTUTIdzb6nh+NvsgviTWiervNv4Y7 hp+PnUxx0TLNVw29Z6ei+tRtn09ZnyYDwYeVGZEf4PEOqY3keFbPZUo9KrkhHJIDD+7E n2O//HJSCei7Qd51JPrDT2CqCn5NvJE9ik4cNcgEOa5bAinHVgKv0PED1DmGq0bb05Yp TJuZ0V1XyTPWNlGBrZnhLO78d2IWkiVeX+YP3/KCrJeJSQTlUb6RIP+mFjwCcjIDBjdX TaAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=yjeOkkdnIAVzvXbPQKtmCdezfzfrmvbeUsnidR8x8lU=; b=VT6fOBzpvLS8Wpw9K9h/8IEWri0WYqeTzF0lmG38KX5MHdqouEebk6zdbb4cjJIq3O vJLfO3hgxp9jyYNhvJmw9B8IH0RONCWTyT43t3M5o1BbeKt6PbILrQ49t6FxjqvgYp+/ muwj+00grEXb40s+FnqQuWiUFwZJN42Uuq11O88duIh8/BQk0L+mLDPrB31Ix7k2NtmV UuxKmN0BFqHQLfLz0cHNfnSzDRle70J3H5Ol1NQG983xvebo7NiGZ9rjMZiniRZnailZ 8xt3m0i8vahmfY/K7OVvKgbDTDLSEsbsATIOYzOFyvAWqtwhNht+pXL00CDXoofPxcmv ikBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=kldBf1Jq; 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 m5si4453590ote.187.2020.01.31.05.35.57; Fri, 31 Jan 2020 05:36:09 -0800 (PST) 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=@c-s.fr header.s=mail header.b=kldBf1Jq; 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 S1728804AbgAaNez (ORCPT + 99 others); Fri, 31 Jan 2020 08:34:55 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:15039 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728566AbgAaNey (ORCPT ); Fri, 31 Jan 2020 08:34:54 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 488J9k41Hxz9vCRl; Fri, 31 Jan 2020 14:34:50 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=kldBf1Jq; dkim-adsp=pass; dkim-atps=neutral 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 7Doksu1MUFue; Fri, 31 Jan 2020 14:34:50 +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 488J9k2CS5z9vCRQ; Fri, 31 Jan 2020 14:34:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580477690; bh=yjeOkkdnIAVzvXbPQKtmCdezfzfrmvbeUsnidR8x8lU=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=kldBf1Jq8brlzteB+o+MvnYVYrdIsuR/Z6QUzREWfJMhi02gAqDgie153URDEP2Aa 6MqRxIlcvHbQ/RmrFKRWR8ZSySH13TkUtkZXx0P+xZGHaRuVBCDM5LGSWYf/YYATqg /YJX8459OVGO6h2b4RI2tGFVGPJW4rICogcDTEhE= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 793B98B8AA; Fri, 31 Jan 2020 14:34:51 +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 D5Zvce7c_cPs; Fri, 31 Jan 2020 14:34:51 +0100 (CET) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.105]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 587D28B8A2; Fri, 31 Jan 2020 14:34:51 +0100 (CET) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 51EA765288; Fri, 31 Jan 2020 13:34:51 +0000 (UTC) Message-Id: <84bae382f67269837d3b68300c8cb26e8c3b9055.1580477672.git.christophe.leroy@c-s.fr> In-Reply-To: <84be5ad6a996adf5693260749dcb4d8c69182073.1580477672.git.christophe.leroy@c-s.fr> References: <84be5ad6a996adf5693260749dcb4d8c69182073.1580477672.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v2 3/7] powerpc/mm/ptdump: debugfs handler for W+X checks at runtime To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , ruscur@russell.cc Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 31 Jan 2020 13:34:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Russell Currey --- v2: no change Signed-off-by: Christophe Leroy --- 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 0b063830eea8..e37960ef68c6 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -370,7 +370,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. @@ -384,7 +384,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 206156255247..a15e19a3b14e 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. @@ -413,6 +413,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) -- 2.25.0