From patchwork Tue Jun 13 00:11:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 106969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp219192vqr; Mon, 12 Jun 2023 17:36:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5KWcIefjQlXJETw7xIYkn2JQ/M1b1xTTgSNqd5VzdScVDi+TWVIpHqrHhe87z9/h/hXYsq X-Received: by 2002:a17:907:6d1e:b0:977:b397:bbfa with SMTP id sa30-20020a1709076d1e00b00977b397bbfamr11592201ejc.6.1686616572482; Mon, 12 Jun 2023 17:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686616572; cv=none; d=google.com; s=arc-20160816; b=Q88iZdtRIirOyPqwZQfem//mpGiOJey/lF7bGTEqxERW7Kq4BY58aDaovrZbAkaYDI L7OD/X6IWxj2PHgkoII8a4f8ffaIexUJpdI9vlBjBPpLBj3ajMacfJ/xWGOHKv7xMLAp CQuCGclLp+ogteQ+dPkNdyAi94JO2GLQ4dSTzX5Kwb9tC+ALHqbsgB+FQTE7ofFivVk7 H4r47KTfs/ywtQmX8ncyUcaS2gQxXndPv1l4BUddO5pBxQKcNBlh038GrXovNPV26DI7 0pJhnpyJ54Ajlbm0Vd96nIXWP70mWXL0clSu/OnJ/MiilctgLl3qAlO5QlChM3uNagSn DHrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0WlSnIOpYVVB1S6QKfwhyiJstnml2qma1WgJwX0ae3s=; b=UHPjQsMA61VuBVvyVk8vZ45dLg7hKa5HJXP6fZDOEOQRNIkNZ83cM+4gQGrkIb0ZYl HZ3nWTSLgWIBge3B1kA3kQaCBqQ47ersGOYi3OTxtuMvPe2izHj5SBObfvrGSfcPCvIO mty+IbYfxVFLKo8KE/x+T+kjnTH+0zIIjhfdc9MyOhQu1ZOfx8feImm4VYTbFbMJPsiq ymExDzwBPTk9n1yMJNETNCQJsOsIbKCso3HZG9EDFbEoLt22c4gU1Hj1VxT8T1BpGajb f5mo+rCt5M6AavQr1FY0h4k9OiseQknfSaTG+LiaHTWzWsrFxOQeWNhVx6fBueKPaVZE 5VnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MN4bLAP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a170906614900b00977cc3d4bf2si5730128ejl.1007.2023.06.12.17.35.12; Mon, 12 Jun 2023 17:36:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MN4bLAP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239357AbjFMATJ (ORCPT + 99 others); Mon, 12 Jun 2023 20:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239183AbjFMARe (ORCPT ); Mon, 12 Jun 2023 20:17:34 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8447198D; Mon, 12 Jun 2023 17:14:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686615249; x=1718151249; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x/pco2Xet/ihWAT7hysHs+5knwsBlg8L8hAHOHmdlgo=; b=MN4bLAP1UKupjLheS/bfz31PM8cXj7TLiVHKl7HIS1Hhdi369CtYqpgL MaIMhOAe9E3OjGCL9txRFET4Kkmf47SZXzdUZgM9IAV9l24NR8pU8y6x5 k7/oVLF5Cr0w1GiG+x94Oz8nq0Ys3qf0EBd4GrQnxjcOBu4X+wsO+jxeq 9qE0ySXyO0gSLmh0SCRE+26hnqRvTQhc0P6eW0G8fK2gyPrU9dctGHOlo Ed5Nwji1Y7Yi3b8uFq5vnP1rm2dRelLZSCk0K86qrwSgivl/NW1xNujNu khoRkBWvRXq7wbOKsUc+n8iwE7YdMGo9mRtMTIGDgI72GZhT3M9QZt9w2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="361557511" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="361557511" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="835671140" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="835671140" Received: from almeisch-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.amr.corp.intel.com) ([10.209.42.242]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:38 -0700 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, szabolcs.nagy@arm.com, torvalds@linux-foundation.org, broonie@kernel.org Cc: rick.p.edgecombe@intel.com, Pengfei Xu Subject: [PATCH v9 36/42] x86: Expose thread features in /proc/$PID/status Date: Mon, 12 Jun 2023 17:11:02 -0700 Message-Id: <20230613001108.3040476-37-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> References: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768545659227315735?= X-GMAIL-MSGID: =?utf-8?q?1768545659227315735?= 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. [Switched to CET, added to commit log] Co-developed-by: Kirill A. Shutemov Signed-off-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook --- 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 d35bbf35a874..2c2efbe685d8 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -431,6 +431,11 @@ static inline void task_untag_mask(struct seq_file *m, struct mm_struct *mm) seq_printf(m, "untag_mask:\t%#lx\n", mm_untag_mask(mm)); } +__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) { @@ -455,6 +460,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)