From patchwork Sat Feb 18 21:14:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13145674 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 B4BCBC6379F for ; Sat, 18 Feb 2023 21:17:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8512280022; Sat, 18 Feb 2023 16:16:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE63C280019; Sat, 18 Feb 2023 16:16:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F92280023; Sat, 18 Feb 2023 16:16:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 89DD2280019 for ; Sat, 18 Feb 2023 16:16:30 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 663441C5CEC for ; Sat, 18 Feb 2023 21:16:30 +0000 (UTC) X-FDA: 80481671340.14.AAF7128 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf25.hostedemail.com (Postfix) with ESMTP id 6BDCBA0006 for ; Sat, 18 Feb 2023 21:16:28 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="cduPV+/J"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676754988; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=9GGr4I/3LFReBSYqcfJoP1HVRW9+H5YST8fr63qrVPw=; b=vebUHlv3NjopViO5FwRKN+nSDS2+X9wicO8jcXoOwrRfQEaIHAx1eKfsoCiwfn4sK4ve90 1N7mUiyFDImCg9D2eyniXIDSP/ymSM2vQwUbMplxvN6ayMYSJMHzZpq4HPEp/oRk9XCpOa xibJiYzSOMOfAKLYF9QvlVJhfhuvZW8= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="cduPV+/J"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676754988; a=rsa-sha256; cv=none; b=r0CfF+EccHX2yKBKI4Y47LZyUCC/6fZ+MLJ+qh+12TPK0MwcBltzGknIXP2U76Cb2YrZlr vkftdD9YcYmjWUp/2dTm3xVnpK/6qnS5g7VL/ksi373Hqex51oABOEGxTlsWICtASWZXbq FQprfe0EXwB1RUhjkgYwSIkVjdMv9M0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676754988; x=1708290988; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=rLqhRE2d5TzXO0jkrIimoFvYNyWSmS33HBbaA6qKIFg=; b=cduPV+/JoDbfGVKZuDZrXwkzlgP3AOpYm+S5Y6qFoaagN280FZtbpe2e lfvZgEcLPS04429pyo4tqYBQqbXe7pXq/uP5Idft0WQPjwf7OZjNqU2mN Qg7ZGZuj+IfP2QbzBCZ/cnTK8ASaTWV0qBdU4V+rFvgiAIQFnlRhUsdWq hZZhqMHPixEupOyzsL02vBcRXKpy/OMrP40ygJhZmKVQXLFvVZtrhiOIb h5Fw4/+pqq4xVY0WgxyO16Ht9Im3PGzm1DTSOrIAX2sHISmN+4iTv9UkK BRrxcuY/F3FezdHtoO0kwbB82QhlNo0QygNqkzLH3zPR4PJDTuQWGHoa1 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427850" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427850" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="664241739" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="664241739" Received: from adityava-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.80.223]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:24 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH v6 35/41] x86: Expose thread features in /proc/$PID/status Date: Sat, 18 Feb 2023 13:14:27 -0800 Message-Id: <20230218211433.26859-36-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230218211433.26859-1-rick.p.edgecombe@intel.com> References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: 6BDCBA0006 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: aai8ykhh8uykxih1uo7ks4c6swk9xej6 X-HE-Tag: 1676754988-604025 X-HE-Meta: U2FsdGVkX1/wcDg5cogOn5MjiJVkRB4DuYPFF3lpwK5HJ3ERqcH+5Ji6kMbcNSD+Ww5vJfm/PUurejyDduRvA7K911hXL6SHycByWYkE40RexwCRoYa9V3fN5GGtfG9OY99EQPqaqTe903mYnXFsB4rXpKuVqSzNStzbH4vlhsacNRh8M0HP5Cp7s1JyMidf0EmMmT49qpYLi1zPyBk+jzfCMgSP6dJ8Xgju83oX7ojFTxj28xI46iu8u2TEF18gYc/8XlXfQTYEHXtTL4+BH4ZcQoIUB762CKX5q6rCi9qQgGEuYzZ5QtI4Q9YHKi39mhgI9ODTT7yOKz5UU8U8u7g47eWz5gtCmla/mDwi9oz/cmbTwwFs1D02NYEgIZDbTxdtWvp4q+Jk+G3t1KEfROtxJdnO+6occ6BBkwjULnsvZWiFcTsGqYkwbkEQ+IO9VCRzRx/YXLLfxL/ChJ1cTrIEDGA6YfpjgbB12mN3DFbDXgvPdj7PUHxbiTaYN1zNCCq5DfxceKnj1TUtiA/2I8v914ZfMWr7F1G+jluFS6rJutCRZez7kGW7fzR7+b9axmz3dM/gLXFa4aB7vuSOsfzhyiX7tsoFwlYQCSOL3OQkBsFcNH2npQPsGTwctt9azqm7cI1odanA24o551V44KZrBU36cdma8ZYnoN/bhhJVaoLH0VjFPvdiLYIrKMdoXbl8a6AeOa3T5GCalnnjaWSFclhGAH/pzwsJybPCaFCzo+pUIM3SN7xgoE27KXVDgkhSfqehKzUApq5lcefBnqtMD6whVkZiZ1S3D/UDxiGRtWQFr3r034VvLlwE6MSVEliG+ul0F3JfMV9LUGB8cquWGkqtpD9MIG687YTwXx1wEWWlP8dUKHsKsIehAnBlAS90uyxZuhkas3kKiscghWbBNjMx5od25sgdIvD2WC9K1Jne7jfl94CMitMQZpa0+f0e9Md9sMoXKpngTEE OxEAtLg6 KPyAJIiX2AcWCEoLV7bJwdcgmakIlMdPgIkmC2Vp7SkTPoukXEUDTb/U3gpn2sC8i7iHWFSC/wxs89s/Q93iqPgQV5kZJFSCytOy1s1NBRq981/3Jje1mlvnW3HChDV5yqeboFZxd8wSpN+lNaJI6zrBnj2VGDcw2GbxC5npeYVjQLorzsQaSPRfHgZBbcP/+gMO+1vcuZxOcHIYL0rZ8l7x2oL3EFLIzrcdBRnbAjdM/HG93B8UjPQt9dV7Qx4ThydfTa3xprwKfFsgludFMUYc2JRK13E3qu/l4QjXGLgyZ+GYSHMdNyqm4kZydEh4aE6Tylez+K3SUklU= 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: Applications and loaders can have logic to decide whether to enable shadow stack. They usually don't report whether shadow stack has been enabled or not, so there is no way to verify whether an application actually is protected by shadow stack. Add two lines in /proc/$PID/status to report enabled and locked features. Since, this involves referring to arch specific defines in asm/prctl.h, implement an arch breakout to emit the feature lines. Reviewed-by: Kees Cook Tested-by: Pengfei Xu Tested-by: John Allen Signed-off-by: Kirill A. Shutemov [Switched to CET, added to commit log] Signed-off-by: Rick Edgecombe --- v4: - Remove "CET" references v3: - Move to /proc/pid/status (Kees) v2: - New patch --- arch/x86/kernel/cpu/proc.c | 23 +++++++++++++++++++++++ fs/proc/array.c | 6 ++++++ include/linux/proc_fs.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c index 099b6f0d96bd..31c0e68f6227 100644 --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "cpu.h" @@ -175,3 +177,24 @@ const struct seq_operations cpuinfo_op = { .stop = c_stop, .show = show_cpuinfo, }; + +#ifdef CONFIG_X86_USER_SHADOW_STACK +static void dump_x86_features(struct seq_file *m, unsigned long features) +{ + if (features & ARCH_SHSTK_SHSTK) + seq_puts(m, "shstk "); + if (features & ARCH_SHSTK_WRSS) + seq_puts(m, "wrss "); +} + +void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task) +{ + seq_puts(m, "x86_Thread_features:\t"); + dump_x86_features(m, task->thread.features); + seq_putc(m, '\n'); + + seq_puts(m, "x86_Thread_features_locked:\t"); + dump_x86_features(m, task->thread.features_locked); + seq_putc(m, '\n'); +} +#endif /* CONFIG_X86_USER_SHADOW_STACK */ diff --git a/fs/proc/array.c b/fs/proc/array.c index 49283b8103c7..7ac43ecda1c2 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -428,6 +428,11 @@ static inline void task_thp_status(struct seq_file *m, struct mm_struct *mm) seq_printf(m, "THP_enabled:\t%d\n", thp_enabled); } +__weak void arch_proc_pid_thread_features(struct seq_file *m, + struct task_struct *task) +{ +} + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { @@ -451,6 +456,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, task_cpus_allowed(m, task); cpuset_task_status_allowed(m, task); task_context_switch_counts(m, task); + arch_proc_pid_thread_features(m, task); return 0; } diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index 0260f5ea98fe..80ff8e533cbd 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -158,6 +158,8 @@ int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task); #endif /* CONFIG_PROC_PID_ARCH_STATUS */ +void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task); + #else /* CONFIG_PROC_FS */ static inline void proc_root_init(void)