Skip to content

Commit aa35dd6

Browse files
committed
io_uring/bpf_filters: retain COW'ed settings on parse failures
If io_parse_restrictions() fails, it ends up clearing any restrictions currently set. The intent is only to clear whatever it already applied, but it ends up clearing everything, including whatever settings may have been applied in a copy-on-write fashion already. Ensure that those are retained. Link: https://lore.kernel.org/io-uring/CAK8a0jzF-zaO5ZmdOrmfuxrhXuKg5m5+RDuO7tNvtj=kUYbW7Q@mail.gmail.com/ Reported-by: antonius <bluedragonsec2023@gmail.com> Fixes: ed82f35 ("io_uring: allow registration of per-task restrictions") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 61a11cf commit aa35dd6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

io_uring/register.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,17 @@ static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
178178
return -EBUSY;
179179

180180
ret = io_parse_restrictions(arg, nr_args, &ctx->restrictions);
181-
/* Reset all restrictions if an error happened */
181+
/*
182+
* Reset all restrictions if an error happened, but retain any COW'ed
183+
* settings.
184+
*/
182185
if (ret < 0) {
186+
struct io_bpf_filters *bpf = ctx->restrictions.bpf_filters;
187+
bool cowed = ctx->restrictions.bpf_filters_cow;
188+
183189
memset(&ctx->restrictions, 0, sizeof(ctx->restrictions));
190+
ctx->restrictions.bpf_filters = bpf;
191+
ctx->restrictions.bpf_filters_cow = cowed;
184192
return ret;
185193
}
186194
if (ctx->restrictions.op_registered)

0 commit comments

Comments
 (0)