Skip to content

Commit 76194c4

Browse files
Christian Braunerkees
authored andcommitted
seccomp: Lift wait_queue into struct seccomp_filter
Lift the wait_queue from struct notification into struct seccomp_filter. This is cleaner overall and lets us avoid having to take the notifier mutex in the future for EPOLLHUP notifications since we need to neither read nor modify the notifier specific aspects of the seccomp filter. In the exit path I'd very much like to avoid having to take the notifier mutex for each filter in the task's filter hierarchy. 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]> Signed-off-by: Kees Cook <[email protected]>
1 parent 3a15fb6 commit 76194c4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

kernel/seccomp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ struct seccomp_knotif {
9595
* filter->notify_lock.
9696
* @next_id: The id of the next request.
9797
* @notifications: A list of struct seccomp_knotif elements.
98-
* @wqh: A wait queue for poll.
9998
*/
10099
struct notification {
101100
struct semaphore request;
102101
u64 next_id;
103102
struct list_head notifications;
104-
wait_queue_head_t wqh;
105103
};
106104

107105
/**
@@ -117,6 +115,7 @@ struct notification {
117115
* @prog: the BPF program to evaluate
118116
* @notif: the struct that holds all notification related information
119117
* @notify_lock: A lock for all notification-related accesses.
118+
* @wqh: A wait queue for poll if a notifier is in use.
120119
*
121120
* seccomp_filter objects are organized in a tree linked via the @prev
122121
* pointer. For any task, it appears to be a singly-linked list starting
@@ -135,6 +134,7 @@ struct seccomp_filter {
135134
struct bpf_prog *prog;
136135
struct notification *notif;
137136
struct mutex notify_lock;
137+
wait_queue_head_t wqh;
138138
};
139139

140140
/* Limit any path through the tree to 256KB worth of instructions. */
@@ -502,6 +502,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
502502
}
503503

504504
refcount_set(&sfilter->refs, 1);
505+
init_waitqueue_head(&sfilter->wqh);
505506

506507
return sfilter;
507508
}
@@ -774,7 +775,7 @@ static int seccomp_do_user_notification(int this_syscall,
774775
list_add(&n.list, &match->notif->notifications);
775776

776777
up(&match->notif->request);
777-
wake_up_poll(&match->notif->wqh, EPOLLIN | EPOLLRDNORM);
778+
wake_up_poll(&match->wqh, EPOLLIN | EPOLLRDNORM);
778779
mutex_unlock(&match->notify_lock);
779780

780781
/*
@@ -1098,7 +1099,7 @@ static long seccomp_notify_recv(struct seccomp_filter *filter,
10981099
unotif.data = *(knotif->data);
10991100

11001101
knotif->state = SECCOMP_NOTIFY_SENT;
1101-
wake_up_poll(&filter->notif->wqh, EPOLLOUT | EPOLLWRNORM);
1102+
wake_up_poll(&filter->wqh, EPOLLOUT | EPOLLWRNORM);
11021103
ret = 0;
11031104
out:
11041105
mutex_unlock(&filter->notify_lock);
@@ -1217,7 +1218,7 @@ static __poll_t seccomp_notify_poll(struct file *file,
12171218
__poll_t ret = 0;
12181219
struct seccomp_knotif *cur;
12191220

1220-
poll_wait(file, &filter->notif->wqh, poll_tab);
1221+
poll_wait(file, &filter->wqh, poll_tab);
12211222

12221223
if (mutex_lock_interruptible(&filter->notify_lock) < 0)
12231224
return EPOLLERR;
@@ -1261,7 +1262,6 @@ static struct file *init_listener(struct seccomp_filter *filter)
12611262
sema_init(&filter->notif->request, 0);
12621263
filter->notif->next_id = get_random_u64();
12631264
INIT_LIST_HEAD(&filter->notif->notifications);
1264-
init_waitqueue_head(&filter->notif->wqh);
12651265

12661266
ret = anon_inode_getfile("seccomp notify", &seccomp_notify_ops,
12671267
filter, O_RDWR);

0 commit comments

Comments
 (0)