From patchwork Tue Jan 30 10:34:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13537195 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 0279AC47DDF for ; Tue, 30 Jan 2024 10:36:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA726B0088; Tue, 30 Jan 2024 05:36:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85A736B0089; Tue, 30 Jan 2024 05:36:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBA86B008C; Tue, 30 Jan 2024 05:36:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5DCD26B0088 for ; Tue, 30 Jan 2024 05:36:54 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 04A5540797 for ; Tue, 30 Jan 2024 10:36:53 +0000 (UTC) X-FDA: 81735624348.30.E4B2D7C Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by imf29.hostedemail.com (Postfix) with ESMTP id 34E35120035 for ; Tue, 30 Jan 2024 10:36:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706611011; a=rsa-sha256; cv=none; b=XoL9XzuBSqLI/hcw3YcxMc9xrxGBW/RDdsmdbRCLLb4qNdlYlpeHGFGqn1XnuxPfE8vjqA K/6zP5aXv4fmOCD93BrdX0OmlGthnafVoiIAWAr8vwpEJ1U755ZWI+81wIWLeOKo7wgn/J qjUn1QPpU1P1T5As97uX7uu+L1HH88g= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.236.30 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706611011; 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=kDtoWL0FXbby/1Dl/nHQdmVAaRAgf4sC4/XJe+7wAiI=; b=3YicC+7hVIMv1GgPY6tR04ZUoFgSw0ndMjlkCueDNBgglL7FDGqqBHYbZKFQxE5ZEkMooA /mlhuLobbD6tnR9xrEwfyMYLuBsrOGa01Wn+S3mvu8syOeKaJfuk25bbxgzQ3ZDgExY0Pj qD0L+TP7PNo9B4mcW8w6fvrKB8CITx0= Received: from localhost (mailhub3.si.c-s.fr [192.168.12.233]) by localhost (Postfix) with ESMTP id 4TPM6B2Rk2z9t5l; Tue, 30 Jan 2024 11:36:34 +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 bWlRn__eVLko; Tue, 30 Jan 2024 11:36:34 +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 4TPM4b0x0Nz9sbF; Tue, 30 Jan 2024 11:35:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 16E428B763; Tue, 30 Jan 2024 11:35:11 +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 W3NGrQMVAtQf; Tue, 30 Jan 2024 11:35:11 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.232.134]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9D00E8B76C; Tue, 30 Jan 2024 11:35:09 +0100 (CET) From: Christophe Leroy To: Andrew Morton , Kees Cook Cc: Christophe Leroy , 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 , 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 v2 5/5] mm: ptdump: add check_wx_pages debugfs attribute Date: Tue, 30 Jan 2024 11:34:36 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706610876; l=1389; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=joW5f5HSLrWZ5GQmf1rXby/U2dLAlVL7zEy3NPVkAVA=; b=sNgiUjWR0Fhosv8enaHSXqsDx5ggf6VAZ13c2rbebUX4KZyQTgf7zPLtHsJdwuYc6lV39bCGn 7Ww4MoEZLHXBCZISIB9MHxmZP08gTQfzYa0f+uOXeeMWzGpYGg6D3St X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 34E35120035 X-Stat-Signature: iuw9et86jxyrpk384dc79iw9b176iezn X-HE-Tag: 1706611010-744479 X-HE-Meta: U2FsdGVkX191AxcWfB9DFo3MvYAHTtTCajbyZQhzc2xSI7ZSF+LZf81FeJi5E7W4Oaw40+eFeNkVgYJccbenrpdWzkvn1tj5szBodKTfzTkfAGL0dKRJE2+4KsEtwMFOgZZfh5gJWAXp4JPL6d1puP7kH3KhkOh3F+72pYpgwux3x8Awk0v26p88bWMPmDjSvyjNEivkN8p75OV3T6Pmvz/UbNfAzkBUTjadjjSTO+KhlJu1sNetLOdLUABKzaNqVZ6p4MtEO8UpamXfwmsTP3YnVHgb5knF0EJP1vhPN9a+u/fNCgiXbKtuQqTGgJbFaIv0C1822Z8HlsLynptOqqfW6KXMyGiIhC+pYBgMxJ9QmzjoWiJ3kdErdYZJBnobTx96EzyYKLKJWpKhBTFuMY5asQ9gu5YeF3KMa13E17Bp2ZFzl+a+1LV608LflInA7d5G4ZPkFjimPhxF4blqufDpWVHWuF9fDEv8PFImxW3bNKd7Eh+1SRY3xfNzkUX93DdkHNcJpzOZk6ygpvbB3Suy72dKOIs0GZJDq26dnv9jgysLP7WlonpmMyKLVDABmm/bfp5UH4y4KYeD+uQQikKWmt9Ag7BJwSAnRCwcORaKz6HYfGKxJQe5YzO1W+wpvziiU1W36aJQ8iXhpAHfBFfLL4cgEr6y2FKoq6Oxfbj7P5gw3OovfbPD2xOz2agfZvXr9D000JGlEJiKRkQraqHOfN3Wz2p+BLX/2XGV0+X8VYjrnF+2XshfYDRFcu2DgBV7LHmGYoGBr9m36Z8NvtYQbu/kKLdS2BJTFopJxaLjAEadS0kq8UNv420SSd4gIYVdkQQXMGxxC9sra1wyWapjJc0uesabGzbde1SZ64f1wy3sdGwAa+x6Ekzs/uXkoe2lWaEtSVCyXjEDQs/9Gqev+XpQpgMUqC9BgNIkz4gKodJehd06kyyqPYtJg57H96Zq2Tz8vZMgQZhWMee xPb1ZsJr 8IBy+NVE3q+kz1fd/KwhIN0lgv9gpuO+h1pXnhxrUNdBLgxnVoRIUqpaMQwy8JXGCXabU4iL+0Z3C5vVMWfbXIddtBGsXjcrFqHisQmgzhhspwgKgQYurUyXAXMh2reaVXUewGdpDCvJHPL0ccZ0Ho/iaZVFJclecMOfMeWoG7BqWbrk= 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 readable attribute in debugfs to trigger a W^X pages check at any time. To trigger the test, just read /sys/kernel/debug/check_wx_pages It will report FAILED if the test failed, SUCCESS otherwise. Detailed result is provided into dmesg. Signed-off-by: Christophe Leroy --- v2: Make it a read attribute which reports SUCCESS/FAILED instead of only relying on kernel message log. --- mm/ptdump.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/ptdump.c b/mm/ptdump.c index 03c1bdae4a43..106e1d66e9f9 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,24 @@ 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_show(struct seq_file *m, void *v) +{ + if (ptdump_check_wx()) + seq_puts(m, "SUCCESS\n"); + else + seq_puts(m, "FAILED\n"); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(check_wx); + +static int ptdump_debugfs_init(void) +{ + debugfs_create_file("check_wx_pages", 0400, NULL, NULL, &check_wx_fops); + + return 0; +} + +device_initcall(ptdump_debugfs_init);