s_pointer(res->bpf_filters->filters[req->opcode])) return 0; /* * req->opcode has already been validated to be within the range * of what we expect, io_init_req() does this. */ guard(rcu)(); filter = rcu_dereference(res->bpf_filters->filters[req->opcode]); if (!filter) return 0; if (filter == &dummy_filter) return -EACCES; io_uring_populate_bpf_ctx(&bpf_ctx, req); /* * Iterate registered filters. The opcode is allowed IFF all filters * return 1. If any filter returns denied, opcode will be denied. */ for (; filter ; filter = filter->next) { int ret; if (filter == &dummy_filter) return -EACCES; ret = bpf_prog_run(filter->prog, &bpf_ctx); if (!ret) return -EACCES; } return 0; } This is minor but I prefer: scoped_guard(spinlock)(&filters->lock) { filters = container_of(head, struct io_bpf_filters, rcu_head); filter = filters->filters; if (!filter) return; } static struct io_bpf_filters *io_new_bpf_filters(void) { struct io_bpf_filters *filters __free(kfree) = NULL; filters = kzalloc(sizeof(*filters), GFP_KERNEL_ACCOUNT); if (!filters) return ERR_PTR(-ENOMEM); filters->filters = kcalloc(IORING_OP_LAST, sizeof(struct io_bpf_filter *), GFP_KERNEL_ACCOUNT); if (!filters->filters) return ERR_PTR(-ENOMEM); refcount_set(&filters->refs, 1); spin_lock_init(&filters->lock); return no_free_ptr(filters); } Seems fine to me but I can't meaningfully review this. So you only support per-op-code filtering with cbpf. I assume that you would argue that people can use the existing io_uring restrictions. But that's not inherited, right? So then this forces users to have a bpf program for all opcodes that io_uring on their system supports. I think that this is a bit unfortunate and wasteful for both userspace and io_uring. Can't we do a combined thing where we also allow filters to attach to all op-codes. Then userspace could start with an allow-list or deny-list filter and then attach further per-op-code bpf programs to the op-codes they want to manage specifically. Then you also get inheritance of the restrictions per-task. That would be nicer imho.[PATCH 1/7] io_uring: add support for BPF filtering for opcode restrictionsChristian Brauner undefinedJens Axboe undefined undefined undefined undefined undefined‚r…