@@ -1035,9 +1035,9 @@ static void io_dismantle_req(struct io_kiocb *req);
1035
1035
static void io_put_task (struct task_struct * task , int nr );
1036
1036
static struct io_kiocb * io_prep_linked_timeout (struct io_kiocb * req );
1037
1037
static void io_queue_linked_timeout (struct io_kiocb * req );
1038
- static int __io_sqe_files_update (struct io_ring_ctx * ctx ,
1039
- struct io_uring_rsrc_update * ip ,
1040
- unsigned nr_args );
1038
+ static int __io_register_rsrc_update (struct io_ring_ctx * ctx , unsigned opcode ,
1039
+ struct io_uring_rsrc_update * up ,
1040
+ unsigned nr_args );
1041
1041
static void io_clean_op (struct io_kiocb * req );
1042
1042
static struct file * io_file_get (struct io_submit_state * state ,
1043
1043
struct io_kiocb * req , int fd , bool fixed );
@@ -5824,7 +5824,8 @@ static int io_files_update(struct io_kiocb *req, unsigned int issue_flags)
5824
5824
up .data = req -> rsrc_update .arg ;
5825
5825
5826
5826
mutex_lock (& ctx -> uring_lock );
5827
- ret = __io_sqe_files_update (ctx , & up , req -> rsrc_update .nr_args );
5827
+ ret = __io_register_rsrc_update (ctx , IORING_REGISTER_FILES_UPDATE ,
5828
+ & up , req -> rsrc_update .nr_args );
5828
5829
mutex_unlock (& ctx -> uring_lock );
5829
5830
5830
5831
if (ret < 0 )
@@ -7726,25 +7727,20 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
7726
7727
struct io_uring_rsrc_update * up ,
7727
7728
unsigned nr_args )
7728
7729
{
7730
+ __s32 __user * fds = u64_to_user_ptr (up -> data );
7729
7731
struct io_rsrc_data * data = ctx -> file_data ;
7730
7732
struct io_fixed_file * file_slot ;
7731
7733
struct file * file ;
7732
- __s32 __user * fds ;
7733
- int fd , i , err ;
7734
- __u32 done ;
7734
+ int fd , i , err = 0 ;
7735
+ unsigned int done ;
7735
7736
bool needs_switch = false;
7736
7737
7737
- if (check_add_overflow ( up -> offset , nr_args , & done ) )
7738
- return - EOVERFLOW ;
7739
- if (done > ctx -> nr_user_files )
7738
+ if (! ctx -> file_data )
7739
+ return - ENXIO ;
7740
+ if (up -> offset + nr_args > ctx -> nr_user_files )
7740
7741
return - EINVAL ;
7741
- err = io_rsrc_node_switch_start (ctx );
7742
- if (err )
7743
- return err ;
7744
7742
7745
- fds = u64_to_user_ptr (up -> data );
7746
7743
for (done = 0 ; done < nr_args ; done ++ ) {
7747
- err = 0 ;
7748
7744
if (copy_from_user (& fd , & fds [done ], sizeof (fd ))) {
7749
7745
err = - EFAULT ;
7750
7746
break ;
@@ -7798,23 +7794,6 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
7798
7794
return done ? done : err ;
7799
7795
}
7800
7796
7801
- static int io_sqe_files_update (struct io_ring_ctx * ctx , void __user * arg ,
7802
- unsigned nr_args )
7803
- {
7804
- struct io_uring_rsrc_update up ;
7805
-
7806
- if (!ctx -> file_data )
7807
- return - ENXIO ;
7808
- if (!nr_args )
7809
- return - EINVAL ;
7810
- if (copy_from_user (& up , arg , sizeof (up )))
7811
- return - EFAULT ;
7812
- if (up .resv )
7813
- return - EINVAL ;
7814
-
7815
- return __io_sqe_files_update (ctx , & up , nr_args );
7816
- }
7817
-
7818
7797
static struct io_wq_work * io_free_work (struct io_wq_work * work )
7819
7798
{
7820
7799
struct io_kiocb * req = container_of (work , struct io_kiocb , work );
@@ -9730,6 +9709,40 @@ static int io_register_enable_rings(struct io_ring_ctx *ctx)
9730
9709
return 0 ;
9731
9710
}
9732
9711
9712
+ static int __io_register_rsrc_update (struct io_ring_ctx * ctx , unsigned opcode ,
9713
+ struct io_uring_rsrc_update * up ,
9714
+ unsigned nr_args )
9715
+ {
9716
+ __u32 tmp ;
9717
+ int err ;
9718
+
9719
+ if (check_add_overflow (up -> offset , nr_args , & tmp ))
9720
+ return - EOVERFLOW ;
9721
+ err = io_rsrc_node_switch_start (ctx );
9722
+ if (err )
9723
+ return err ;
9724
+
9725
+ switch (opcode ) {
9726
+ case IORING_REGISTER_FILES_UPDATE :
9727
+ return __io_sqe_files_update (ctx , up , nr_args );
9728
+ }
9729
+ return - EINVAL ;
9730
+ }
9731
+
9732
+ static int io_register_rsrc_update (struct io_ring_ctx * ctx , unsigned opcode ,
9733
+ void __user * arg , unsigned nr_args )
9734
+ {
9735
+ struct io_uring_rsrc_update up ;
9736
+
9737
+ if (!nr_args )
9738
+ return - EINVAL ;
9739
+ if (copy_from_user (& up , arg , sizeof (up )))
9740
+ return - EFAULT ;
9741
+ if (up .resv )
9742
+ return - EINVAL ;
9743
+ return __io_register_rsrc_update (ctx , opcode , & up , nr_args );
9744
+ }
9745
+
9733
9746
static bool io_register_op_must_quiesce (int op )
9734
9747
{
9735
9748
switch (op ) {
@@ -9816,7 +9829,7 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
9816
9829
ret = io_sqe_files_unregister (ctx );
9817
9830
break ;
9818
9831
case IORING_REGISTER_FILES_UPDATE :
9819
- ret = io_sqe_files_update (ctx , arg , nr_args );
9832
+ ret = io_register_rsrc_update (ctx , opcode , arg , nr_args );
9820
9833
break ;
9821
9834
case IORING_REGISTER_EVENTFD :
9822
9835
case IORING_REGISTER_EVENTFD_ASYNC :
0 commit comments