Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3473967ybl; Mon, 3 Feb 2020 00:42:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwCfk0VbduBGgfJneP7OL7mhRXguzq6Nrn7693A8j+Ydb52JP2pnUhrbV4Pfns6SI/AKrSQ X-Received: by 2002:aca:5f87:: with SMTP id t129mr14177108oib.36.1580719370239; Mon, 03 Feb 2020 00:42:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580719370; cv=none; d=google.com; s=arc-20160816; b=O+wT0Qj2zHEOgKL9SpXkfAT3CLr2bHiLXGPnzbXreWw1jZuD/9VXufbNtOGJd+szHL Ow7BWi60PLz0ozPji4vrfPywtlyNuNM/cEYG5jGfYMKpfP9ufPqMdIhdhHIw8T1fry26 dwGwvq9U4CYRv33P9Pk69lySVPuwbajzvlIJfVKbRyQgdUo5/l1gY6MPSvHe24TkibMt +CATdbt7GeDm9JBb1nruZZfMGOhD5/Sepn8m8SRfd8LigeEpFQleR+Go/44yskD0cxGs 10jkk2Mf8avWaMIE3nYKo9sc++tImWnU7yxAHfUSE+6N9s+xrjI8ApRp3NN5hfFmCu3N 8iJg== 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=FHgn4N4ltdsIlD1Z5OweivJ/s7UtylttunSmicjjwIM=; b=KKJVnRwqXJDDGFLHOJ92w4+QY8VU+pXClJ9M4mjqTFHl6bkkSg81srfPGlF2B+vV0y KnpP/1GQVQZWJnDtJ+9uRjfatoKC3mXHySgxce8O8CKyvUgvXCxaTd4AbxrVY7WaZ/JO 69JYGFBIGt/+tt6SmAIL4o7gaj5Yshw0zM7QGxFY2/t5l8tR97Eti8j9Xp20NlxuaL89 bfw7hD8yu/KbjPOqYiffYFJnS81a0n5ba1/bgwdpXyK+hqgO0+H2Ifv1aFp30Rhr4N1c IHUTgEWJuly9FH+6mc7iPh60HTIfz/jT5b6I2nN+1wFinqU8xWqbd5ZCOOVJsps5AD+K 7GXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=YLIlJEBL; 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 x19si8459073otk.89.2020.02.03.00.42.37; Mon, 03 Feb 2020 00:42:50 -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=YLIlJEBL; 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 S1727639AbgBCHMB (ORCPT + 99 others); Mon, 3 Feb 2020 02:12:01 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:50438 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbgBCHMA (ORCPT ); Mon, 3 Feb 2020 02:12:00 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 489zXV0ZwJz9tyK3; Mon, 3 Feb 2020 08:11:54 +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=YLIlJEBL; 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 il0wKvoJYDtG; Mon, 3 Feb 2020 08:11:54 +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 489zXT6XVQz9tyK0; Mon, 3 Feb 2020 08:11:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1580713913; bh=FHgn4N4ltdsIlD1Z5OweivJ/s7UtylttunSmicjjwIM=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=YLIlJEBL3oI/trwY4x5U3NcBJHlx9iCBRuPFVW+88kRXJEOwob7AgRz3B0+n2KSqM YSdQ4l5+eCLIj+tUoXjcDJf0Xl3jg1TJxyuNaGS/TwW/zZjcHfL7r9OWkPyLPJfOm+ 757ZAYq/mdkjaZkceRTVSPqfPoCXat3lQj7m62M8= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 786618B792; Mon, 3 Feb 2020 08:11:58 +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 XN44-1NcEM59; Mon, 3 Feb 2020 08:11:58 +0100 (CET) Received: from po14934vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.102]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4A0628B752; Mon, 3 Feb 2020 08:11:58 +0100 (CET) Received: by po14934vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 3943F652AD; Mon, 3 Feb 2020 07:11:58 +0000 (UTC) Message-Id: In-Reply-To: <80ebd9075cd7c8b412c6d5d05f7542f9026642ef.1580713729.git.christophe.leroy@c-s.fr> References: <80ebd9075cd7c8b412c6d5d05f7542f9026642ef.1580713729.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH v3 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: Mon, 3 Feb 2020 07:11:58 +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 --- v3: no change v2: no change --- 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