diff --git a/io_uring/bpf_filter.c b/io_uring/bpf_filter.c index 1409d625b686..b94944ab8442 100644 --- a/io_uring/bpf_filter.c +++ b/io_uring/bpf_filter.c @@ -15,6 +15,7 @@ #include "openclose.h" struct io_bpf_filter { + refcount_t refs; struct bpf_prog *prog; struct io_bpf_filter *next; }; @@ -125,6 +126,11 @@ static void io_free_bpf_filters(struct rcu_head *head) */ if (f == &dummy_filter) break; + + /* Someone still holds a ref, stop iterating. */ + if (!refcount_dec_and_test(&f->refs)) + break; + bpf_prog_destroy(f->prog); kfree(f); f = next; @@ -298,6 +304,7 @@ int io_register_bpf_filter(struct io_restriction *res, ret = -ENOMEM; goto err; } + refcount_set(&filter->refs, 1); filter->prog = prog; res->bpf_filters = filters;