@@ -572,6 +572,18 @@ config STACKLEAK_TRACK_MIN_SIZE
frame size greater than or equal to this parameter.
If unsure, leave the default value 100.
+config STACKLEAK_METRICS
+ bool "Show STACKLEAK metrics in the /proc file system"
+ depends on GCC_PLUGIN_STACKLEAK
+ depends on PROC_FS
+ help
+ If this is set, STACKLEAK metrics for every task are available in
+ the /proc file system. In particular, /proc/<pid>/stack_depth
+ shows the maximum kernel stack consumption for the current and
+ previous syscalls. Although this information is not precise, it
+ can be useful for estimating the STACKLEAK performance impact for
+ your workloads.
+
config HAVE_CC_STACKPROTECTOR
bool
help
@@ -134,6 +134,10 @@ ENTRY(erase_kstack)
mov %esp, %ecx
sub %edi, %ecx
+#ifdef CONFIG_STACKLEAK_METRICS
+ mov %edi, TASK_prev_lowest_stack(%ebp)
+#endif
+
cmp $THREAD_SIZE_asm, %ecx
jb .Lgood_counter
ud2
@@ -119,6 +119,10 @@ ENTRY(erase_kstack)
*/
or $2 * 8, %rdi
+#ifdef CONFIG_STACKLEAK_METRICS
+ mov %rdi, TASK_prev_lowest_stack(%r11)
+#endif
+
/*
* Check whether we are on the thread stack to prepare the counter
* for stack poisoning.
@@ -496,6 +496,9 @@ struct thread_struct {
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
unsigned long lowest_stack;
+# ifdef CONFIG_STACKLEAK_METRICS
+ unsigned long prev_lowest_stack;
+# endif
#endif
unsigned int sig_on_uaccess_err:1;
@@ -41,6 +41,9 @@ void common(void) {
OFFSET(TASK_addr_limit, task_struct, thread.addr_limit);
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
OFFSET(TASK_lowest_stack, task_struct, thread.lowest_stack);
+# ifdef CONFIG_STACKLEAK_METRICS
+ OFFSET(TASK_prev_lowest_stack, task_struct, thread.prev_lowest_stack);
+# endif
#endif
BLANK();
@@ -139,6 +139,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
2 * sizeof(unsigned long);
+# ifdef CONFIG_STACKLEAK_METRICS
+ p->thread.prev_lowest_stack = p->thread.lowest_stack;
+# endif
#endif
if (unlikely(p->flags & PF_KTHREAD)) {
@@ -284,6 +284,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
p->thread.lowest_stack = (unsigned long)task_stack_page(p) +
2 * sizeof(unsigned long);
+# ifdef CONFIG_STACKLEAK_METRICS
+ p->thread.prev_lowest_stack = p->thread.lowest_stack;
+# endif
#endif
savesegment(gs, p->thread.gsindex);
@@ -2914,6 +2914,21 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns,
}
#endif /* CONFIG_LIVEPATCH */
+#ifdef CONFIG_STACKLEAK_METRICS
+static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ unsigned long prev_depth = THREAD_SIZE -
+ (task->thread.prev_lowest_stack & (THREAD_SIZE - 1));
+ unsigned long depth = THREAD_SIZE -
+ (task->thread.lowest_stack & (THREAD_SIZE - 1));
+
+ seq_printf(m, "previous stack depth: %lu\nstack depth: %lu\n",
+ prev_depth, depth);
+ return 0;
+}
+#endif /* CONFIG_STACKLEAK_METRICS */
+
/*
* Thread groups
*/
@@ -3018,6 +3033,9 @@ static const struct pid_entry tgid_base_stuff[] = {
#ifdef CONFIG_LIVEPATCH
ONE("patch_state", S_IRUSR, proc_pid_patch_state),
#endif
+#ifdef CONFIG_STACKLEAK_METRICS
+ ONE("stack_depth", S_IRUGO, proc_stack_depth),
+#endif
};
static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
Introduce CONFIG_STACKLEAK_METRICS providing STACKLEAK information about tasks via the /proc file system. In particular, /proc/<pid>/stack_depth shows the maximum kernel stack consumption for the current and previous syscalls. Although this information is not precise, it can be useful for estimating the STACKLEAK performance impact for your workloads. Signed-off-by: Alexander Popov <alex.popov@linux.com> --- arch/Kconfig | 12 ++++++++++++ arch/x86/entry/entry_32.S | 4 ++++ arch/x86/entry/entry_64.S | 4 ++++ arch/x86/include/asm/processor.h | 3 +++ arch/x86/kernel/asm-offsets.c | 3 +++ arch/x86/kernel/process_32.c | 3 +++ arch/x86/kernel/process_64.c | 3 +++ fs/proc/base.c | 18 ++++++++++++++++++ 8 files changed, 50 insertions(+)