Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp1557844rwl; Fri, 4 Nov 2022 15:54:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM53RaGkUlnB6J2YioHA4KGD1OEAGkoyjqewJikimkZ8L8eQjkcHhRnMdC2+ZM0IM7lwJtEG X-Received: by 2002:a17:902:dac3:b0:186:a437:f4b8 with SMTP id q3-20020a170902dac300b00186a437f4b8mr37538058plx.70.1667602467056; Fri, 04 Nov 2022 15:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667602467; cv=none; d=google.com; s=arc-20160816; b=V1nfq02NQECzwP4TDH+siuoSZWMmnrBh0/EIUb8yfaBGSILIn2JNGAqPeTpRwmLRZO KEd83Smp8p65VQ6F1d3OlrXptlDfSUN5EegWWsAX2siMRvk1EHHUC3h80GsRrtDbqrdb En8Z7NXjZ3XAToeqodhjT0LiAl3b9pCiJlxf96JgHg+uKblvEaNj2av98A92fuTijFQG 3utqUnyoC/pAFU9Jnq+8e+0gHa1+R882ifBChwNPeS3fb24c0NX4ZptTqHyySV8iboWT g2px4rOSC84vB8pUWeOhcxr0d/bOET9EFR1nDFHx3yK4ebfU3u3XJZQOg91Z2fDiUbnb k95g== 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=Eu7eLlxVBWKEVHa42ldyG6KO0oyIM+LboIItdIy+tuY=; b=jRj6iEyRaagoj80PGwbRObtI7lTgzbYiuF3fKvZ+uzuHcG/Sklc3jV/zxA8NJiYk1I NfFeLvJeyGtfnGfugxrr8Brr28rSYBMFXtGh7hrwbW/oWJfIVQb+yFGUsN445oD3596a TrHQKFbE7fevqyWPA1W/imcSbGZlU5mR08h/VMvdJZ/hSa12GJ1lzvfOI6gRQoTaMTa4 mek09tUUVOO3QI3HczO3FANKzNzhJ4H+FX7RIQtwS3nyh65PHwuFyF+dZZe3b1VJ5yMx 5jlX7y8mn6Ao18pJ/pe5mayDZho2KQ7NOEoV/fRCWUdgyHqPK2ILUeFEzjFjft6UjUxr sc8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UxWHCTtw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc22-20020a656d96000000b0046ffae350d0si1044544pgb.30.2022.11.04.15.54.15; Fri, 04 Nov 2022 15:54:27 -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=UxWHCTtw; 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 S230403AbiKDWpB (ORCPT + 97 others); Fri, 4 Nov 2022 18:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbiKDWoO (ORCPT ); Fri, 4 Nov 2022 18:44:14 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A55F66CB1; Fri, 4 Nov 2022 15:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667601635; x=1699137635; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UXzhjhw4AECWj6QkxFrPwKgALHbK58V+F3EC9InWArw=; b=UxWHCTtwo6qvjZcO1ouMRx4w8+ikBSSu343rXTUR5f16MA7AJYw1qVct Wx/RVJZvQh+koGBoHJL6/9Hbg/jF46qM0MF+KNa0NBL8E2XMlsc6GNT4C Ws+YStziG1iLRJbXhNGZ9CoRab+UHsVtTrLlEq5HELRSOdTc8w+Xe1ioS AE5zI4F4rndcEiL4s6/66dr3vS1vPq7A0YWQxKrVWMxuxHdN0VjvGeaVw n+EMz8iId7jmCPDrREgOklzlnI+mloQxVJjuegBLVnSwNljOSrat/LPkV S4bEWgqhumCLA52c9ks2C1SOcBLDsZJKFqeLrmTKdAhBk4/26csXGj4Nx A==; X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="311840602" X-IronPort-AV: E=Sophos;i="5.96,138,1665471600"; d="scan'208";a="311840602" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 15:39:50 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10521"; a="668514142" X-IronPort-AV: E=Sophos;i="5.96,138,1665471600"; d="scan'208";a="668514142" Received: from adhjerms-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.212.227.68]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2022 15:39:49 -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 , "Ravi V . Shankar" , 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 Cc: rick.p.edgecombe@intel.com Subject: [PATCH v3 31/37] x86: Expose thread features in /proc/$PID/status Date: Fri, 4 Nov 2022 15:35:58 -0700 Message-Id: <20221104223604.29615-32-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221104223604.29615-1-rick.p.edgecombe@intel.com> References: <20221104223604.29615-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-5.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 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 Applications and loaders can have logic to decide whether to enable CET. They usually don't report whether CET has been enabled or not, so there is no way to verify whether an application actually is protected by CET features. 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 Signed-off-by: Kirill A. Shutemov [Switched to CET, added to commit log] Signed-off-by: Rick Edgecombe --- 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..105587d43500 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 & CET_SHSTK) + seq_puts(m, "shstk "); + if (features & CET_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 81d6e4ec2294..5a8b21c0a587 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) -- 2.17.1