Skip to content

Commit b707dde

Browse files
Christian Braunerkees
authored andcommitted
seccomp: rename "usage" to "refs" and document
Naming the lifetime counter of a seccomp filter "usage" suggests a little too strongly that its about tasks that are using this filter while it also tracks other references such as the user notifier or ptrace. This also updates the documentation to note this fact. We'll be introducing an actual usage counter in a follow-up patch. Cc: Tycho Andersen <[email protected]> Cc: Kees Cook <[email protected]> Cc: Matt Denton <[email protected]> Cc: Sargun Dhillon <[email protected]> Cc: Jann Horn <[email protected]> Cc: Chris Palmer <[email protected]> Cc: Aleksa Sarai <[email protected]> Cc: Robert Sesek <[email protected]> Cc: Jeffrey Vander Stoep <[email protected]> Cc: Linux Containers <[email protected]> Signed-off-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 9f87dcf commit b707dde

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

kernel/seccomp.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ struct notification {
107107
/**
108108
* struct seccomp_filter - container for seccomp BPF programs
109109
*
110-
* @usage: reference count to manage the object lifetime.
111-
* get/put helpers should be used when accessing an instance
112-
* outside of a lifetime-guarded section. In general, this
113-
* is only needed for handling filters shared across tasks.
110+
* @refs: Reference count to manage the object lifetime.
111+
* A filter's reference count is incremented for each directly
112+
* attached task, once for the dependent filter, and if
113+
* requested for the user notifier. When @refs reaches zero,
114+
* the filter can be freed.
114115
* @log: true if all actions except for SECCOMP_RET_ALLOW should be logged
115116
* @prev: points to a previously installed, or inherited, filter
116117
* @prog: the BPF program to evaluate
@@ -125,10 +126,10 @@ struct notification {
125126
* how namespaces work.
126127
*
127128
* seccomp_filter objects should never be modified after being attached
128-
* to a task_struct (other than @usage).
129+
* to a task_struct (other than @refs).
129130
*/
130131
struct seccomp_filter {
131-
refcount_t usage;
132+
refcount_t refs;
132133
bool log;
133134
struct seccomp_filter *prev;
134135
struct bpf_prog *prog;
@@ -464,7 +465,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
464465
return ERR_PTR(ret);
465466
}
466467

467-
refcount_set(&sfilter->usage, 1);
468+
refcount_set(&sfilter->refs, 1);
468469

469470
return sfilter;
470471
}
@@ -558,7 +559,7 @@ static long seccomp_attach_filter(unsigned int flags,
558559

559560
static void __get_seccomp_filter(struct seccomp_filter *filter)
560561
{
561-
refcount_inc(&filter->usage);
562+
refcount_inc(&filter->refs);
562563
}
563564

564565
/* get_seccomp_filter - increments the reference count of the filter on @tsk */
@@ -581,7 +582,7 @@ static inline void seccomp_filter_free(struct seccomp_filter *filter)
581582
static void __put_seccomp_filter(struct seccomp_filter *orig)
582583
{
583584
/* Clean up single-reference branches iteratively. */
584-
while (orig && refcount_dec_and_test(&orig->usage)) {
585+
while (orig && refcount_dec_and_test(&orig->refs)) {
585586
struct seccomp_filter *freeme = orig;
586587
orig = orig->prev;
587588
seccomp_filter_free(freeme);

0 commit comments

Comments
 (0)