From patchwork Mon Feb 27 22:29:51 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: 62186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2683629wrd; Mon, 27 Feb 2023 14:37:08 -0800 (PST) X-Google-Smtp-Source: AK7set+7jNMDP8mJIIvO9SYUnmYnrLIE6RSYlahiKGTMi+bt3/JBQ8LZUsxHKwwU1jKrgPXvDgWK X-Received: by 2002:a05:6a21:32a8:b0:cd:f17:5292 with SMTP id yt40-20020a056a2132a800b000cd0f175292mr1174098pzb.44.1677537427908; Mon, 27 Feb 2023 14:37:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677537427; cv=none; d=google.com; s=arc-20160816; b=m+P3n71oayhSlWHeWL7h66sjRYxpZ2NIWiVMwlkmABQIb28wMW2YaE/lRY6udGxMnQ GSo6kaXGRvXbQiJrFyMEnlCC8iQkpVyCSS+ssXbPaeksGz+mU5j8+ZwNAmffrrDD8qs0 PXT2EGgT7M+9+Z5SP7QuVL/MYUzGnuvSqjRNnTtwgXPWCcZ20jtQY9yPO8Tqkf+MzPdZ 4sLIYjj2l1x2u8+lYIM/JT1yXVvYr5mjkZloGA1T+IgclNjj4ZzSEPB/j7UFLrlhUUE/ +lAYcvUlO0pbcGjtu1Wzwwups4XO5jViqVQGv13oeizApNPvozH9w1s261y7j7nSiXoc eDnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=v91OPFL+NXA/Nu8SB0fkXd3GzEnDmi+70tOEkSeZJRU=; b=Db4gwYWiATczXpQWjg/CFJGJ+fWRXp2/DfOziaLEu2szGQcQQfFZlC+YWTRoaYD8MZ PNDq56VV09jjRwXG113nenxbMEQfBPVmIC+F7qIitimbDPet7kRbybgMq7wFSNcobR99 9uZWVM/505O7xBy8+8ksy4vzwIuet+lsPDqCoxvIGaPFKxqAuCzeECtOq0kVbp58vi20 wZ0lorN5LHVjkbKIQcnLZH9DxaKEJcSzHKcsZtej0Z+H0w7qkUqGn6vBpfJ5HR4+kv6y AHSayQl6gQxYYXdvs0P0Hwxa2bAs/Ywe06n9RGmRow+0v/qMn3urIacExj+cf7EXrsJ7 t/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LHksjYJc; 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 d21-20020a056a00199500b005e30bfb5033si8543127pfl.330.2023.02.27.14.36.54; Mon, 27 Feb 2023 14:37:07 -0800 (PST) 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=LHksjYJc; 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 S230497AbjB0WgQ (ORCPT + 99 others); Mon, 27 Feb 2023 17:36:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjB0We0 (ORCPT ); Mon, 27 Feb 2023 17:34:26 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D35EF2A985; Mon, 27 Feb 2023 14:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537131; x=1709073131; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=IJ4r2WgIxo+o2NsnoMfw1hw6rWv+qYgJeXRvN9Qbwh8=; b=LHksjYJcI/QuSnaGEznMYcIJfAfc6h0ItInqzhtJ5m25yLjQ3AZ2msPr KypMzaRAqdoWGEZOcMFsofwQgpbSVSRA8OgsoGsEwQEJiSH4oiCggjEBa 9LKUg/zsjMV8ryj6uMNsMGGCaB5Qz0YRhs7poe3Um1ju0bV/+kyjGYsOn N/4pzKCun7Y7EyTPVkuFtAQbE1zXhas7ZAMh9jGmbI83psr8p4oX6+HZa ruvb58BHeWrzxNhWXM9fp6fxRGUxDaoI+1ecdVcYqZ4lE6tDrXeAm3j1C xmvMLbKF6Y69LfrXF1DLam/LWLWnckVtRX4pubtY8Mc2I65yAK+DUyAcZ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657854" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657854" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:34 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024780" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024780" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:33 -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 v7 35/41] x86: Expose thread features in /proc/$PID/status Date: Mon, 27 Feb 2023 14:29:51 -0800 Message-Id: <20230227222957.24501-36-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> 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_PASS,SPF_NONE 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?1759025485775939081?= X-GMAIL-MSGID: =?utf-8?q?1759025485775939081?= 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. Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Kees Cook 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)