Skip to content

Commit 73c2a12

Browse files
joannekoonggregkh
authored andcommitted
io_uring/rsrc: clean up buffer cloning arg validation
commit b8201b5 upstream. Get rid of some redundant checks and move the src arg validation to before the buffer table allocation, which simplifies error handling. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b20266f commit 73c2a12

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

io_uring/rsrc.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,12 +1185,16 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
11851185
return -EBUSY;
11861186

11871187
nbufs = src_ctx->buf_table.nr;
1188+
if (!nbufs)
1189+
return -ENXIO;
11881190
if (!arg->nr)
11891191
arg->nr = nbufs;
11901192
else if (arg->nr > nbufs)
11911193
return -EINVAL;
11921194
else if (arg->nr > IORING_MAX_REG_BUFFERS)
11931195
return -EINVAL;
1196+
if (check_add_overflow(arg->nr, arg->src_off, &off) || off > nbufs)
1197+
return -EOVERFLOW;
11941198
if (check_add_overflow(arg->nr, arg->dst_off, &nbufs))
11951199
return -EOVERFLOW;
11961200
if (nbufs > IORING_MAX_REG_BUFFERS)
@@ -1210,21 +1214,6 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
12101214
}
12111215
}
12121216

1213-
ret = -ENXIO;
1214-
nbufs = src_ctx->buf_table.nr;
1215-
if (!nbufs)
1216-
goto out_free;
1217-
ret = -EINVAL;
1218-
if (!arg->nr)
1219-
arg->nr = nbufs;
1220-
else if (arg->nr > nbufs)
1221-
goto out_free;
1222-
ret = -EOVERFLOW;
1223-
if (check_add_overflow(arg->nr, arg->src_off, &off))
1224-
goto out_free;
1225-
if (off > nbufs)
1226-
goto out_free;
1227-
12281217
off = arg->dst_off;
12291218
i = arg->src_off;
12301219
nr = arg->nr;
@@ -1237,8 +1226,8 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
12371226
} else {
12381227
dst_node = io_rsrc_node_alloc(ctx, IORING_RSRC_BUFFER);
12391228
if (!dst_node) {
1240-
ret = -ENOMEM;
1241-
goto out_free;
1229+
io_rsrc_data_free(ctx, &data);
1230+
return -ENOMEM;
12421231
}
12431232

12441233
refcount_inc(&src_node->buf->refs);
@@ -1274,10 +1263,6 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
12741263
WARN_ON_ONCE(ctx->buf_table.nr);
12751264
ctx->buf_table = data;
12761265
return 0;
1277-
1278-
out_free:
1279-
io_rsrc_data_free(ctx, &data);
1280-
return ret;
12811266
}
12821267

12831268
/*

0 commit comments

Comments
 (0)