Skip to contentSkip to conversation

io_uring/bpf_filter: Set src->bpf_filters_cow in io_bpf_filter_clone()

PATCH In review Hui Peng 2 participants 2 messages Sep 19 – Sep 21 io_uring

lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH v2 1/1 io_uring/bpf_filter: Set src->bpf_filters_cow in io_bpf_filter_clone()

When io_bpf_filter_clone() clones a struct io_bpf_filters table from a source restriction set to a destination restriction set, it increments src->bpf_filters->refs and sets dst->bpf_filters_cow = true, but forgets to set src->bpf_filters_cow = true.

As a result, subsequent IORING_REGISTER_BPF_FILTER registrations on an io_uring instance or task holding the source restriction set bypass copy-on-write and mutate the shared io_bpf_filters table in place, corrupting the BPF filter rules of already-cloned rings.

Fix this by setting src->bpf_filters_cow = true alongside dst->bpf_filters_cow = true in io_bpf_filter_clone().

Fixes ed82f35b926b ("io_uring: allow registration of per-task restrictions")
Assisted-by LLM

---
v2: Resend as plain text. v1 went out as PGP/MIME, which I now understand is not wanted on the lists - apologies for the noise. Also add a Fixes: tag and the Assisted-by: LLM tag.

io_bpf_filter_clone(), the bpf_filters_cow flag and its only consumer in io_register_bpf_filter() were all added together by ed82f35b926b ("io_uring: allow registration of per-task restrictions"), first released in v7.0-rc1, so that is the tag. Note d42eb05e60fe ("io_uring: add support for BPF filtering for opcode restrictions") created bpf_filter.c and has a later author date because of a rebase, but it predates ed82f35b926b in the history and contains neither io_bpf_filter_clone() nor bpf_filters_cow.

To be clear about severity: this is a restriction-bypass / filter-set corruption issue, not a memory-safety one. The refcount is taken correctly and there is no use-after-free; the problem is purely that the source side of the clone is never marked COW, so a later IORING_REGISTER_BPF_FILTER on the source mutates the table that the cloned ring is still using.

Found by code inspection; build tested only, no reproducer.

 io_uring/bpf_filter.c | 1 +
 1 file changed, 1 insertion(+)
io_uring/bpf_filter.c +1 -0
index c0037632b7af..4a21511c4811 100644
@@ -253,6 +253,7 @@ void io_bpf_filter_clone(struct io_restriction *dst, struct io_restriction *src)
 	 * If the src filter is going away, just ignore it.
 	 */
 	if (refcount_inc_not_zero(&src->bpf_filters->refs)) {
+		src->bpf_filters_cow = true;
 		dst->bpf_filters = src->bpf_filters;
 		dst->bpf_filters_cow = true;
 	}
maintainer
#1 lore raw
Quoted 5 lines · Hui Peng

When io_bpf_filter_clone() clones a struct io_bpf_filters table from a source restriction set to a destination restriction set, it increments src->bpf_filters->refs and sets dst->bpf_filters_cow = true, but forgets to set src->bpf_filters_cow = true.

Quoted 7 lines

As a result, subsequent IORING_REGISTER_BPF_FILTER registrations on an io_uring instance or task holding the source restriction set bypass copy-on-write and mutate the shared io_bpf_filters table in place, corrupting the BPF filter rules of already-cloned rings.

Fix this by setting src->bpf_filters_cow = true alongside dst->bpf_filters_cow = true in io_bpf_filter_clone().

This one looks fine. But:

Quoted 1 line

Found by code inspection; build tested only, no reproducer.

run the test suite. As far as I can tell from your patches, "code inspection" simply means an LLM looked at it for you. Do you even look at the code? It's clear it hasn't been run.

In the future, don't send patches without having tested them. And tell your LLM to refrain from both the overly verbose and alarmist writing.

Signature · 1 line
Jens Axboe