Skip to content

Commit e344eb7

Browse files
committed
Merge tag 'io_uring-6.3-2023-03-24' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Fix an issue with repeated -ECONNREFUSED on a socket (me) - Fix a NULL pointer deference due to a stale lookup cache for allocating direct descriptors (Savino) * tag 'io_uring-6.3-2023-03-24' of git://git.kernel.dk/linux: io_uring/rsrc: fix null-ptr-deref in io_file_bitmap_get() io_uring/net: avoid sending -ECONNABORTED on repeated connection requests
2 parents fd3d06f + 02a4d92 commit e344eb7

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

io_uring/filetable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ static int io_file_bitmap_get(struct io_ring_ctx *ctx)
1919
unsigned long nr = ctx->file_alloc_end;
2020
int ret;
2121

22+
if (!table->bitmap)
23+
return -ENFILE;
24+
2225
do {
2326
ret = find_next_zero_bit(table->bitmap, nr, table->alloc_hint);
2427
if (ret != nr)

io_uring/net.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct io_connect {
4747
struct sockaddr __user *addr;
4848
int addr_len;
4949
bool in_progress;
50+
bool seen_econnaborted;
5051
};
5152

5253
struct io_sr_msg {
@@ -1424,7 +1425,7 @@ int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
14241425

14251426
conn->addr = u64_to_user_ptr(READ_ONCE(sqe->addr));
14261427
conn->addr_len = READ_ONCE(sqe->addr2);
1427-
conn->in_progress = false;
1428+
conn->in_progress = conn->seen_econnaborted = false;
14281429
return 0;
14291430
}
14301431

@@ -1461,18 +1462,24 @@ int io_connect(struct io_kiocb *req, unsigned int issue_flags)
14611462

14621463
ret = __sys_connect_file(req->file, &io->address,
14631464
connect->addr_len, file_flags);
1464-
if ((ret == -EAGAIN || ret == -EINPROGRESS) && force_nonblock) {
1465+
if ((ret == -EAGAIN || ret == -EINPROGRESS || ret == -ECONNABORTED)
1466+
&& force_nonblock) {
14651467
if (ret == -EINPROGRESS) {
14661468
connect->in_progress = true;
1467-
} else {
1468-
if (req_has_async_data(req))
1469-
return -EAGAIN;
1470-
if (io_alloc_async_data(req)) {
1471-
ret = -ENOMEM;
1469+
return -EAGAIN;
1470+
}
1471+
if (ret == -ECONNABORTED) {
1472+
if (connect->seen_econnaborted)
14721473
goto out;
1473-
}
1474-
memcpy(req->async_data, &__io, sizeof(__io));
1474+
connect->seen_econnaborted = true;
1475+
}
1476+
if (req_has_async_data(req))
1477+
return -EAGAIN;
1478+
if (io_alloc_async_data(req)) {
1479+
ret = -ENOMEM;
1480+
goto out;
14751481
}
1482+
memcpy(req->async_data, &__io, sizeof(__io));
14761483
return -EAGAIN;
14771484
}
14781485
if (ret == -ERESTARTSYS)

io_uring/rsrc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
794794
}
795795
#endif
796796
io_free_file_tables(&ctx->file_table);
797+
io_file_table_set_alloc_range(ctx, 0, 0);
797798
io_rsrc_data_free(ctx->file_data);
798799
ctx->file_data = NULL;
799800
ctx->nr_user_files = 0;

0 commit comments

Comments
 (0)