From patchwork Tue Jan 9 12:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13514856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A4D3C46CD2 for ; Tue, 9 Jan 2024 12:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5ED16B0096; Tue, 9 Jan 2024 07:15:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0D636B0098; Tue, 9 Jan 2024 07:15:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FD026B009A; Tue, 9 Jan 2024 07:15:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 812846B0096 for ; Tue, 9 Jan 2024 07:15:21 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5FE26140330 for ; Tue, 9 Jan 2024 12:15:21 +0000 (UTC) X-FDA: 81659667642.02.001422D Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf21.hostedemail.com (Postfix) with ESMTP id 005E11C0022 for ; Tue, 9 Jan 2024 12:15:18 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf21.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704802519; a=rsa-sha256; cv=none; b=cxdliE9Xh1P/a9fU3M6BF6U4j6Et65aAxZxjf/gizUwO/ZRhpUprI47cXW1O8lKeFmgXik lmeCNhLAnk17kwmshZIkR7vJTkxsY5dW5CT3NOIwbW+aelK4shqbaUzSXE6GGlBzfc9RLd UhaYxSp0lkasJALUZdhnAYfUUzy5O6w= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf21.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704802519; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S4h/eBRgu6rW2Ay87oOQPbiSaA0iFoQOvLpXIcx+L4I=; b=0ehimlA2EchrrOiV/+7iVRLT6DpDpLkPI4ZhQCaG73of2bhd63IB38V6ggaiE4lTy4Akmk GQS+vc3dOXO/rA0cYXCA7t9M5EycLSJNadAkXM3uSD3zzGgkD0aVqE7JaiXy9ezxgKlkTo SnVk8rnesfp97awEaTT17VZ1VaMenbw= Received: from localhost (mailhub3.si.c-s.fr [192.168.12.233]) by localhost (Postfix) with ESMTP id 4T8VHY0sNRz9v7N; Tue, 9 Jan 2024 13:15:05 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0ozAHoRKaJAh; Tue, 9 Jan 2024 13:15:05 +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 4T8VHY02Bvz9v2V; Tue, 9 Jan 2024 13:15:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id ECE6E8B774; Tue, 9 Jan 2024 13:15:04 +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 FZoHIGzf4vrQ; Tue, 9 Jan 2024 13:15:04 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.233.126]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 313958B77D; Tue, 9 Jan 2024 13:15:03 +0100 (CET) From: Christophe Leroy To: linux-hardening@vger.kernel.org, Russell King , Catalin Marinas , Will Deacon , Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K.V" , "Naveen N. Rao" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Kees Cook Cc: Christophe Leroy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-mm@kvack.org, steven.price@arm.com, Phong Tran , mark.rutland@arm.com, Greg KH Subject: [PATCH 4/4] ptdump: add check_wx_pages debugfs attribute Date: Tue, 9 Jan 2024 13:14:38 +0100 Message-ID: <2e8806da45a4b00249d5c449130b5f9ce78b3403.1704800524.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1704802474; l=1205; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=GHXEAlv0k5WPsTIzSlwSomj0miEDu7ks2lV9a6+wMCY=; b=ibzm/cyPs51Q7IIlWinvVhCDJTVa2O93PdiVEWCD+bsWH/ncfG8IK1blTnxut+3ypcbloBgn2 fQjuoG4nNpPArnos+jqQxEly3FXt6Jg7j8Ye6GzOwyRghOCV7gDmUAh X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 005E11C0022 X-Stat-Signature: sitd4zatitdponxj1wy4d3adh7pkjq9i X-Rspam-User: X-HE-Tag: 1704802518-283915 X-HE-Meta: U2FsdGVkX19JSOfH+hevyLqs+X4ZI/NuF4/s/z1b8zVS0bGVvTKpk5My2ecacOE5WzcuR4njVbR1ZoMrWWGwXsD9GwXNR3CfRV3G47hUIvvZen32EcURMziqdvng4vI9d769B7S6N2zA8M1SegM+rE0D1UEorFv24VtKP3dFYp1xlBiIPmr+dtSEcmVRLz04wIYU3AAspT3G9rcj7n88IQKR0DnZnrxD9fEWt5CPPeaDYbe91edMw1/x5t8MUO3e60uOW+GDZW9bErLay15tilJg1/zeHjg1g1ba0byXxJ2Tc6WlDwZa08Tq5UeR3NlclVzNdih73UQXVCZtUCslR2i0matLNX3omA6wztqcRv3V8MHfJN7ORkZBhls93TfNbMkECsluW/cVpgVRkdo3g9wwcO8GbQUw8d5qRFxko2dKu8fDbTEMy3Sam2bCqGcm3H7GFb26W9GnabSPsuRb96K7vm8httB3O37YKGT/u+X+v75QE1UfWfQEuibhudQS1xDxNa9jqlVdzQGZxl5CfBkxte/dmVENe0AOApgQ9y1ALPD7fmzKdwh+KAwxpw5HP6uNmVyaTFyxrcju+SqlCXljxmFSPa6FPY7sO2yy2aCbtCq9ZGsP//wTM27BRDSUPYfGk0Slk1LYdDO5H02jDkPQ1hpHV3axO+MS4SEOww5mMAypJLyjqNgbpNESHIO5YdGBQu6SRGuFMQUmgs7dL8nTGBwjObRzZSKoxAEht9HiEWeBvBDWBkOJnlhHC1LUl2eMZxeaJdhr67W4kbpHNFblHtOrOm0PNDgThzdatPyRMCiycI+ytepNjR8P2LGoyFLWzAtrs39lxWI+hOLtDy/6JFFRUfxXzdM7yatnykMJhHbWycbisG+6UHQFb2L3daTldWSp9sxErqad9o0tzOyz583l93ryixDojtDgmBnpfCobVph8ggqdRbJy79d8nLKWQQiZ6i+zoFW1EQE qAYih/dq zR6bps0+XGZs4XZuM8V/O8xZOwDCdctZDZ/QEwKvci1tssZXV6gDi0ZujrdHaREH6cncpYzUh04V6qQbxgkf0vT/4mPWU7PTEyt/yhmxy40+T5gzLSiiBcSqyQLo3yqMQJdVekUHbuooZYiAkAYBRU3nwPDO2iX9jFI7YJzy+y/jTGcLSYQBdtptJnnUMtfgxOP8AI3Kw7AJGMXEtg9UOm3DpvhUAEuAkH0Clc9e0U69jm/HafXYJy0M77A== 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: List-Subscribe: List-Unsubscribe: Add a writable attribute in debugfs to trigger a W^X pages check at any time. To trigger the test, just echo any numeric value into /sys/kernel/debug/check_wx_pages The result is provided into dmesg. Signed-off-by: Christophe Leroy --- mm/ptdump.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/ptdump.c b/mm/ptdump.c index 03c1bdae4a43..e154099c2584 100644 --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include @@ -163,3 +164,21 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd) /* Flush out the last page */ st->note_page(st, 0, -1, 0); } + +static int check_wx_debugfs_set(void *data, u64 val) +{ + ptdump_check_wx(); + + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(check_wx_fops, NULL, check_wx_debugfs_set, "%llu\n"); + +static int ptdump_debugfs_init(void) +{ + debugfs_create_file("check_wx_pages", 0200, NULL, NULL, &check_wx_fops); + + return 0; +} + +device_initcall(ptdump_debugfs_init);