Skip to content

Commit c818c03

Browse files
committed
seccomp: Report number of loaded filters in /proc/$pid/status
A common question asked when debugging seccomp filters is "how many filters are attached to your process?" Provide a way to easily answer this question through /proc/$pid/status with a "Seccomp_filters" line. Signed-off-by: Kees Cook <[email protected]>
1 parent e4d0502 commit c818c03

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

fs/proc/array.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
341341
seq_put_decimal_ull(m, "NoNewPrivs:\t", task_no_new_privs(p));
342342
#ifdef CONFIG_SECCOMP
343343
seq_put_decimal_ull(m, "\nSeccomp:\t", p->seccomp.mode);
344+
seq_put_decimal_ull(m, "\nSeccomp_filters:\t",
345+
atomic_read(&p->seccomp.filter_count));
344346
#endif
345347
seq_puts(m, "\nSpeculation_Store_Bypass:\t");
346348
switch (arch_prctl_spec_ctrl_get(p, PR_SPEC_STORE_BYPASS)) {

include/linux/seccomp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifdef CONFIG_SECCOMP
1414

1515
#include <linux/thread_info.h>
16+
#include <linux/atomic.h>
1617
#include <asm/seccomp.h>
1718

1819
struct seccomp_filter;
@@ -29,6 +30,7 @@ struct seccomp_filter;
2930
*/
3031
struct seccomp {
3132
int mode;
33+
atomic_t filter_count;
3234
struct seccomp_filter *filter;
3335
};
3436

init/init_task.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ struct task_struct init_task
204204
#ifdef CONFIG_SECURITY
205205
.security = NULL,
206206
#endif
207+
#ifdef CONFIG_SECCOMP
208+
.seccomp = { .filter_count = ATOMIC_INIT(0) },
209+
#endif
207210
};
208211
EXPORT_SYMBOL(init_task);
209212

kernel/seccomp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ static inline void seccomp_sync_threads(unsigned long flags)
398398
put_seccomp_filter(thread);
399399
smp_store_release(&thread->seccomp.filter,
400400
caller->seccomp.filter);
401+
atomic_set(&thread->seccomp.filter_count,
402+
atomic_read(&thread->seccomp.filter_count));
401403

402404
/*
403405
* Don't let an unprivileged task work around
@@ -544,6 +546,7 @@ static long seccomp_attach_filter(unsigned int flags,
544546
*/
545547
filter->prev = current->seccomp.filter;
546548
current->seccomp.filter = filter;
549+
atomic_inc(&current->seccomp.filter_count);
547550

548551
/* Now that the new filter is in place, synchronize to all threads. */
549552
if (flags & SECCOMP_FILTER_FLAG_TSYNC)

0 commit comments

Comments
 (0)