Skip to content

Commit 0ee4488

Browse files
rpedgecohansendc
authored andcommitted
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 <[email protected]> Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Rick Edgecombe <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Mike Rapoport (IBM) <[email protected]> Tested-by: Pengfei Xu <[email protected]> Tested-by: John Allen <[email protected]> Tested-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/all/20230613001108.3040476-37-rick.p.edgecombe%40intel.com
1 parent 1d62c65 commit 0ee4488

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

arch/x86/kernel/cpu/proc.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <linux/string.h>
55
#include <linux/seq_file.h>
66
#include <linux/cpufreq.h>
7+
#include <asm/prctl.h>
8+
#include <linux/proc_fs.h>
79

810
#include "cpu.h"
911

@@ -175,3 +177,24 @@ const struct seq_operations cpuinfo_op = {
175177
.stop = c_stop,
176178
.show = show_cpuinfo,
177179
};
180+
181+
#ifdef CONFIG_X86_USER_SHADOW_STACK
182+
static void dump_x86_features(struct seq_file *m, unsigned long features)
183+
{
184+
if (features & ARCH_SHSTK_SHSTK)
185+
seq_puts(m, "shstk ");
186+
if (features & ARCH_SHSTK_WRSS)
187+
seq_puts(m, "wrss ");
188+
}
189+
190+
void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task)
191+
{
192+
seq_puts(m, "x86_Thread_features:\t");
193+
dump_x86_features(m, task->thread.features);
194+
seq_putc(m, '\n');
195+
196+
seq_puts(m, "x86_Thread_features_locked:\t");
197+
dump_x86_features(m, task->thread.features_locked);
198+
seq_putc(m, '\n');
199+
}
200+
#endif /* CONFIG_X86_USER_SHADOW_STACK */

fs/proc/array.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ static inline void task_untag_mask(struct seq_file *m, struct mm_struct *mm)
431431
seq_printf(m, "untag_mask:\t%#lx\n", mm_untag_mask(mm));
432432
}
433433

434+
__weak void arch_proc_pid_thread_features(struct seq_file *m,
435+
struct task_struct *task)
436+
{
437+
}
438+
434439
int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
435440
struct pid *pid, struct task_struct *task)
436441
{
@@ -455,6 +460,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
455460
task_cpus_allowed(m, task);
456461
cpuset_task_status_allowed(m, task);
457462
task_context_switch_counts(m, task);
463+
arch_proc_pid_thread_features(m, task);
458464
return 0;
459465
}
460466

include/linux/proc_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int proc_pid_arch_status(struct seq_file *m, struct pid_namespace *ns,
159159
#endif /* CONFIG_PROC_PID_ARCH_STATUS */
160160

161161
void arch_report_meminfo(struct seq_file *m);
162+
void arch_proc_pid_thread_features(struct seq_file *m, struct task_struct *task);
162163

163164
#else /* CONFIG_PROC_FS */
164165

0 commit comments

Comments
 (0)