Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2317649ybh; Mon, 9 Mar 2020 03:33:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvhNMmpsElBqoFL8zx2dwP9SbjoElSMfijLSHTTmRBnCwMUSMzpDxqLl0Nti7U6DgtO9OKJ X-Received: by 2002:a05:6830:168d:: with SMTP id k13mr12574938otr.208.1583750016397; Mon, 09 Mar 2020 03:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583750016; cv=none; d=google.com; s=arc-20160816; b=EeOPifOinHpLJnleFYB+8cjM3mNT0UJQ8DAAHLzSoXxxQo18GpkzJ/s0bXFT/Z21OE swQcTtCr4GfbW5DSkBHrl1Z28XFephNWY5KrnBopjEakfUZJkC5vA8B8Jo3A1YvoLPSI NX21vVeRpJuQ+uwbD9E/2ihycqBEseKc09XIE198sG9T2t6OOcm7GkqPox4ssw+vsX9c 3/ID+PZ5RtDrEV4ixcBybptbGBBKxXoKtyBZ+8NYK5c5oGYrS0cdpi5g3VwGboPg1oT2 yrgpBmLp6gKFTs8irv/Sl7MIAa+FzaOg8JNsKEz9fQYnDbcMjrdT1SJlFc5NqF605tlP lhIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=5KMSK/XRKJw9TsSuJYjz97h3xjWFFHJFson9aVSIdsA=; b=A25Z7wsVDSHReExyxnLyMJyyQg12+TcrSMl9JT2PMndGhUeg8j0be/ly1Ktx9eXStY M+xOGaPsNOcgukS/G7CcNPkkrL8OzxlfajbsgIGD7Jqjp30FR3e0Drhnw4/T7FOqAZF5 VHco9SC+3Sx2POGQuSkewPx+KPfX6zW/IK/EBalH1j8iRKNapjlhsXgkiSgb7JJmd+Xe YhePEjvK5IIHaVghQ0O1gAtOTVQpF2e2EKOMdWuD1lH/mOq+/zA2e6oxszEnX9GrboU2 PnLcHNZT5m6haVMOBP1KQZ6DVQy9ZNEZ5jUlkTd/UGFxH/inHhGCBcCWxEJuYhkiBA1J QHlA== ARC-Authentication-Results: i=1; mx.google.com; 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 i131si3921009oib.6.2020.03.09.03.33.25; Mon, 09 Mar 2020 03:33:36 -0700 (PDT) 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; 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 S1726814AbgCIKcc (ORCPT + 99 others); Mon, 9 Mar 2020 06:32:32 -0400 Received: from foss.arm.com ([217.140.110.172]:50242 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgCIKcb (ORCPT ); Mon, 9 Mar 2020 06:32:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 08E7D1FB; Mon, 9 Mar 2020 03:32:31 -0700 (PDT) Received: from [10.1.195.32] (e112269-lin.cambridge.arm.com [10.1.195.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 75E5F3F67D; Mon, 9 Mar 2020 03:32:29 -0700 (PDT) Subject: Re: [PATCH] arm64: add check_wx_pages debugfs for CHECK_WX To: Phong Tran , Catalin Marinas , "will@kernel.org" , "alexios.zavras@intel.com" , "tglx@linutronix.de" , "akpm@linux-foundation.org" , Steve Capper , Mark Rutland , "broonie@kernel.org" , "keescook@chromium.org" Cc: "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "kernel-hardening@lists.openwall.com" References: <20200307093926.27145-1-tranmanphong@gmail.com> From: Steven Price Message-ID: <34739c99-3436-e88f-769b-43c48caa8817@arm.com> Date: Mon, 9 Mar 2020 10:32:27 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200307093926.27145-1-tranmanphong@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/03/2020 09:39, Phong Tran wrote: > follow the suggestion from > https://github.com/KSPP/linux/issues/35 > > Signed-off-by: Phong Tran > --- > arch/arm64/Kconfig.debug | 3 ++- > arch/arm64/include/asm/ptdump.h | 2 ++ > arch/arm64/mm/dump.c | 1 + > arch/arm64/mm/ptdump_debugfs.c | 18 ++++++++++++++++++ > 4 files changed, 23 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug > index 1c906d932d6b..be552fa351e2 100644 > --- a/arch/arm64/Kconfig.debug > +++ b/arch/arm64/Kconfig.debug > @@ -48,7 +48,8 @@ config 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's a one time check and > + can be checked by echo "1" to "check_wx_pages" debugfs in runtime. I would suggest it may be better spelling this out a bit more, because at the moment it's a little confusing when the config option is "Warn on W+X mappings at boot", but your change makes it sound like it only happens when you do the echo. Perhaps something like: There is no runtime or memory usage effect of this option once the kernel has booted up - it's a one time check at boot, and can also be triggered at runtime by echo "1" to "check_wx_pages". > > If in doubt, say "Y". > > diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h > index 38187f74e089..b80d6b4fc508 100644 > --- a/arch/arm64/include/asm/ptdump.h > +++ b/arch/arm64/include/asm/ptdump.h > @@ -24,9 +24,11 @@ struct ptdump_info { > void ptdump_walk(struct seq_file *s, struct ptdump_info *info); > #ifdef CONFIG_PTDUMP_DEBUGFS > void ptdump_debugfs_register(struct ptdump_info *info, const char *name); > +int ptdump_check_wx_init(void); > #else > static inline void ptdump_debugfs_register(struct ptdump_info *info, > const char *name) { } > +static inline int ptdump_check_wx_init(void) { return 0; } > #endif > void ptdump_check_wx(void); > #endif /* CONFIG_PTDUMP_CORE */ This is a confusing! Why have you made it dependent on CONFIG_PTDUMP_DEBUGFS? Well actually I can see why - it's because you've put the new functions in ptdump_debugfs.c which is (currently) only built when CONFIG_PTDUMP_DBEUGFS is enabled. So you need to either: a) Ensure the new code is built when CONFIG_PTDUMP_DEBUGFS isn't enabled. b) Update the Kconfig help text to say that the debugfs file for triggering a runtime W+X check is only available if CONFIG_PTDUMP_DEBUGFS is also enabled. Other than the confusion over config symbols this looks good. Thanks, Steve > diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c > index 860c00ec8bd3..60c99a047763 100644 > --- a/arch/arm64/mm/dump.c > +++ b/arch/arm64/mm/dump.c > @@ -378,6 +378,7 @@ static int ptdump_init(void) > #endif > ptdump_initialize(); > ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); > + ptdump_check_wx_init(); > return 0; > } > device_initcall(ptdump_init); > diff --git a/arch/arm64/mm/ptdump_debugfs.c b/arch/arm64/mm/ptdump_debugfs.c > index 1f2eae3e988b..73cddc12c3c2 100644 > --- a/arch/arm64/mm/ptdump_debugfs.c > +++ b/arch/arm64/mm/ptdump_debugfs.c > @@ -16,3 +16,21 @@ void ptdump_debugfs_register(struct ptdump_info *info, const char *name) > { > debugfs_create_file(name, 0400, NULL, info, &ptdump_fops); > } > + > +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"); > + > +int ptdump_check_wx_init(void) > +{ > + return debugfs_create_file("check_wx_pages", 0200, NULL, > + NULL, &check_wx_fops) ? 0 : -ENOMEM; > +} >