Skip to content

Commit 63ff822

Browse files
committed
io_uring: don't use 'fd' for openat/openat2/statx
We currently make some guesses as when to open this fd, but in reality we have no business (or need) to do so at all. In fact, it makes certain things fail, like O_PATH. Remove the fd lookup from these opcodes, we're just passing the 'fd' to generic helpers anyway. With that, we can also remove the special casing of fd values in io_req_needs_file(), and the 'fd_non_neg' check that we have. And we can ensure that we only read sqe->fd once. This fixes O_PATH usage with openat/openat2, and ditto statx path side oddities. Cc: [email protected]: # v5.6 Reported-by: Max Kellermann <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 90da2e3 commit 63ff822

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

fs/io_uring.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,6 @@ struct io_op_def {
680680
unsigned needs_mm : 1;
681681
/* needs req->file assigned */
682682
unsigned needs_file : 1;
683-
/* needs req->file assigned IFF fd is >= 0 */
684-
unsigned fd_non_neg : 1;
685683
/* hash wq insertion if file is a regular file */
686684
unsigned hash_reg_file : 1;
687685
/* unbound wq insertion if file is a non-regular file */
@@ -784,8 +782,6 @@ static const struct io_op_def io_op_defs[] = {
784782
.needs_file = 1,
785783
},
786784
[IORING_OP_OPENAT] = {
787-
.needs_file = 1,
788-
.fd_non_neg = 1,
789785
.file_table = 1,
790786
.needs_fs = 1,
791787
},
@@ -799,8 +795,6 @@ static const struct io_op_def io_op_defs[] = {
799795
},
800796
[IORING_OP_STATX] = {
801797
.needs_mm = 1,
802-
.needs_file = 1,
803-
.fd_non_neg = 1,
804798
.needs_fs = 1,
805799
.file_table = 1,
806800
},
@@ -837,8 +831,6 @@ static const struct io_op_def io_op_defs[] = {
837831
.buffer_select = 1,
838832
},
839833
[IORING_OP_OPENAT2] = {
840-
.needs_file = 1,
841-
.fd_non_neg = 1,
842834
.file_table = 1,
843835
.needs_fs = 1,
844836
},
@@ -5368,15 +5360,6 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
53685360
io_steal_work(req, workptr);
53695361
}
53705362

5371-
static int io_req_needs_file(struct io_kiocb *req, int fd)
5372-
{
5373-
if (!io_op_defs[req->opcode].needs_file)
5374-
return 0;
5375-
if ((fd == -1 || fd == AT_FDCWD) && io_op_defs[req->opcode].fd_non_neg)
5376-
return 0;
5377-
return 1;
5378-
}
5379-
53805363
static inline struct file *io_file_from_index(struct io_ring_ctx *ctx,
53815364
int index)
53825365
{
@@ -5414,14 +5397,11 @@ static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
54145397
}
54155398

54165399
static int io_req_set_file(struct io_submit_state *state, struct io_kiocb *req,
5417-
int fd, unsigned int flags)
5400+
int fd)
54185401
{
54195402
bool fixed;
54205403

5421-
if (!io_req_needs_file(req, fd))
5422-
return 0;
5423-
5424-
fixed = (flags & IOSQE_FIXED_FILE);
5404+
fixed = (req->flags & REQ_F_FIXED_FILE) != 0;
54255405
if (unlikely(!fixed && req->needs_fixed_file))
54265406
return -EBADF;
54275407

@@ -5798,7 +5778,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
57985778
struct io_submit_state *state, bool async)
57995779
{
58005780
unsigned int sqe_flags;
5801-
int id, fd;
5781+
int id;
58025782

58035783
/*
58045784
* All io need record the previous position, if LINK vs DARIN,
@@ -5850,8 +5830,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
58505830
IOSQE_ASYNC | IOSQE_FIXED_FILE |
58515831
IOSQE_BUFFER_SELECT | IOSQE_IO_LINK);
58525832

5853-
fd = READ_ONCE(sqe->fd);
5854-
return io_req_set_file(state, req, fd, sqe_flags);
5833+
if (!io_op_defs[req->opcode].needs_file)
5834+
return 0;
5835+
5836+
return io_req_set_file(state, req, READ_ONCE(sqe->fd));
58555837
}
58565838

58575839
static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,

0 commit comments

Comments
 (0)