From patchwork Mon Mar 20 16:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 72313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1334388wrt; Mon, 20 Mar 2023 10:18:03 -0700 (PDT) X-Google-Smtp-Source: AK7set9rty3s6vSNJtRj6FS+OxAk3nBPOkNiIEcazycWCyfyVsBfq9kIyA35lnTBLLt7I/DiCJwg X-Received: by 2002:a05:6a20:b71a:b0:d9:5a7c:b1c5 with SMTP id fg26-20020a056a20b71a00b000d95a7cb1c5mr5248099pzb.11.1679332682737; Mon, 20 Mar 2023 10:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679332682; cv=none; d=google.com; s=arc-20160816; b=vEXKm3B4+Tx4aEQZO4+dAuwoRdrK2CqcqpC2zYixXRB11bVQRYMzGlKY17kKGYLxlZ EdM796TNq37JS6q0Xph7kHI3Ooa2YGMwTHs7u2Ioyq2TDx1T5KWBYxzPQhiXK1tzO0zV OuZ8eYGWdh81N7AAjTmCe9zJ5i4eLL5eLkg8y+9tEzAfy9iBz6hpJnwdclm/OofhTOFX 0gFH1TGmFHFin4WWACBIdnOPx4wusSdANHHax9kXAuCSgJsRDOTAufB2S1fTnVGeOBEb Y36HryhMeC00y2iNyUhx6SNnsp0psQlfTOSIlYVoAZUY6N8JX+zTPKFmxmVpk7tiN66C 9jSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=x/2uKAj9QuiNWYk1J6LZ46bUVw3Zerzu5lcdgu4FjH8=; b=suy4dkPl+U9yLau/xEmUFgfzwTVBTbQJZqr5flQFA20Q9KwA2p+MPI6lNpYXvcO/Oz e08DsPLZe2BRktRROPVjaYoPtis1RI7i2QsDC54CwduacCNVcs6GrCLFxEXJGQQSqjoO KyK4FBmhlnmn4FgFbKfXvZdUd8AXjAgs9xuDWDGnm8+UoZap7p0n63dgn4duXFqwRx3b 64+LvTtJICGQbBGpyYrWQUj+2H74cGFUGWtvDv1Y4cuJwt4aaPUSlXO2wHs0WrFMmkmy ZHo2bOLYO9iuRXY9Ygc8hdFBd1dzvvK+Z0uyXYM9VKnBrfnlUUvHCIYk6hPq98u35+/D VWxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="g6VWcw/r"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a631403000000b00509bec0d7c3si10886819pgl.468.2023.03.20.10.17.47; Mon, 20 Mar 2023 10:18:02 -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=@linutronix.de header.s=2020 header.b="g6VWcw/r"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbjCTQqR (ORCPT + 99 others); Mon, 20 Mar 2023 12:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233426AbjCTQpW (ORCPT ); Mon, 20 Mar 2023 12:45:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16769213F; Mon, 20 Mar 2023 09:40:10 -0700 (PDT) Date: Mon, 20 Mar 2023 16:39:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679330362; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x/2uKAj9QuiNWYk1J6LZ46bUVw3Zerzu5lcdgu4FjH8=; b=g6VWcw/rymMR9rxUoVH5sQnRPBDtTP+fqcTP0+drzLPpizINthZXbZbq5tx2JbUl35hLIX DeQDRa29Y+wA5EDKAo1PNlVfDGIScUN5DYegDJhsbPBYSHH8CQcChuRJD/YMi9NDQG1wtL cO3cF5fG960TDsqBMOgDY7Iv0gPXCdccDxx9BxbWHDR6nCUVgnjTwhBEs3fMKNmo7aQKYf JFIylfSEqs6HcdXj9zndjoabpuXz290+VGcqfMYBDa465kwY4gHXYsQ3C2LnKIuPLJTX++ gzM46sorph2s0cFsc4/EnUmprWgYgkvx4wAC3M0kxItqEd3Xi3Hhj3Vmqm2PCg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679330362; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=x/2uKAj9QuiNWYk1J6LZ46bUVw3Zerzu5lcdgu4FjH8=; b=SVgEJynVHjQPKjcj1hO3UoiRnrvsMs7PDp/WFjbtYPuAJ4QudswAJ154MWmmUBkVrtTJk3 h9kFN6ySTs6iuVBg== From: "tip-bot2 for Rick Edgecombe" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86: Expose thread features in /proc/$PID/status Cc: "Kirill A. Shutemov" , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , "Mike Rapoport (IBM)" , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <167933036183.5837.12618610040956746441.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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?1760907947089838945?= X-GMAIL-MSGID: =?utf-8?q?1760907947089838945?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 214b23e1186488ff68feb74d8561286a5c83b281 Gitweb: https://git.kernel.org/tip/214b23e1186488ff68feb74d8561286a5c83b281 Author: Rick Edgecombe AuthorDate: Sat, 18 Mar 2023 17:15:30 -07:00 Committer: Dave Hansen CommitterDate: Mon, 20 Mar 2023 09:01:12 -07:00 x86: Expose thread features in /proc/$PID/status 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 Signed-off-by: Dave Hansen 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 Link: https://lore.kernel.org/all/20230319001535.23210-36-rick.p.edgecombe%40intel.com --- 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 099b6f0..31c0e68 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 9b0315d..3e1a33d 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -423,6 +423,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) { @@ -446,6 +451,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 0260f5e..80ff8e5 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)