diff --git a/fs/file.c b/fs/file.c index f78fd5062429eb2885f69d4d28b2e4f430afd34d..e07d18f8865be1dc59531823dbb87bf8414eb047 100644 --- a/fs/file.c +++ b/fs/file.c @@ -579,9 +579,14 @@ static int alloc_fd(unsigned start, unsigned flags) return __alloc_fd(current->files, start, rlimit(RLIMIT_NOFILE), flags); } +int __get_unused_fd_flags(unsigned flags, unsigned long nofile) +{ + return __alloc_fd(current->files, 0, nofile, flags); +} + int get_unused_fd_flags(unsigned flags) { - return __alloc_fd(current->files, 0, rlimit(RLIMIT_NOFILE), flags); + return __get_unused_fd_flags(flags, rlimit(RLIMIT_NOFILE)); } EXPORT_SYMBOL(get_unused_fd_flags); diff --git a/fs/io_uring.c b/fs/io_uring.c index ffbf53755ac4ead31945744b82ab7380127c95e7..a58c4b78f811fb06092c36a3b366af4d9e7d4094 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -398,6 +398,7 @@ struct io_open { struct filename *filename; struct statx __user *buffer; int flags; + unsigned long nofile; }; struct io_files_update { @@ -2571,6 +2572,7 @@ static int io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) return ret; } + req->open.nofile = rlimit(RLIMIT_NOFILE); req->flags |= REQ_F_NEED_CLEANUP; return 0; } @@ -2589,7 +2591,7 @@ static int io_openat(struct io_kiocb *req, struct io_kiocb **nxt, if (ret) goto err; - ret = get_unused_fd_flags(req->open.flags); + ret = __get_unused_fd_flags(req->open.flags, req->open.nofile); if (ret < 0) goto err; diff --git a/include/linux/file.h b/include/linux/file.h index 3fcddff56bc4bb30b7ac46da444be05a771964bf..82fa6064662d8ce56d8fb41d0429e3b8bd877ade 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -83,6 +83,7 @@ extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); extern int replace_fd(unsigned fd, struct file *file, unsigned flags); extern void set_close_on_exec(unsigned int fd, int flag); extern bool get_close_on_exec(unsigned int fd); +extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile); extern int get_unused_fd_flags(unsigned flags); extern void put_unused_fd(unsigned int fd);