@@ -104,21 +104,13 @@ static int io_register_personality(struct io_ring_ctx *ctx)
104104 return id ;
105105}
106106
107- static __cold int io_register_restrictions ( struct io_ring_ctx * ctx ,
108- void __user * arg , unsigned int nr_args )
107+ static __cold int io_parse_restrictions ( void __user * arg , unsigned int nr_args ,
108+ struct io_restriction * restrictions )
109109{
110110 struct io_uring_restriction * res ;
111111 size_t size ;
112112 int i , ret ;
113113
114- /* Restrictions allowed only if rings started disabled */
115- if (!(ctx -> flags & IORING_SETUP_R_DISABLED ))
116- return - EBADFD ;
117-
118- /* We allow only a single restrictions registration */
119- if (ctx -> restrictions .registered )
120- return - EBUSY ;
121-
122114 if (!arg || nr_args > IORING_MAX_RESTRICTIONS )
123115 return - EINVAL ;
124116
@@ -130,47 +122,57 @@ static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
130122 if (IS_ERR (res ))
131123 return PTR_ERR (res );
132124
133- ret = 0 ;
125+ ret = - EINVAL ;
134126
135127 for (i = 0 ; i < nr_args ; i ++ ) {
136128 switch (res [i ].opcode ) {
137129 case IORING_RESTRICTION_REGISTER_OP :
138- if (res [i ].register_op >= IORING_REGISTER_LAST ) {
139- ret = - EINVAL ;
140- goto out ;
141- }
142-
143- __set_bit (res [i ].register_op ,
144- ctx -> restrictions .register_op );
130+ if (res [i ].register_op >= IORING_REGISTER_LAST )
131+ goto err ;
132+ __set_bit (res [i ].register_op , restrictions -> register_op );
145133 break ;
146134 case IORING_RESTRICTION_SQE_OP :
147- if (res [i ].sqe_op >= IORING_OP_LAST ) {
148- ret = - EINVAL ;
149- goto out ;
150- }
151-
152- __set_bit (res [i ].sqe_op , ctx -> restrictions .sqe_op );
135+ if (res [i ].sqe_op >= IORING_OP_LAST )
136+ goto err ;
137+ __set_bit (res [i ].sqe_op , restrictions -> sqe_op );
153138 break ;
154139 case IORING_RESTRICTION_SQE_FLAGS_ALLOWED :
155- ctx -> restrictions . sqe_flags_allowed = res [i ].sqe_flags ;
140+ restrictions -> sqe_flags_allowed = res [i ].sqe_flags ;
156141 break ;
157142 case IORING_RESTRICTION_SQE_FLAGS_REQUIRED :
158- ctx -> restrictions . sqe_flags_required = res [i ].sqe_flags ;
143+ restrictions -> sqe_flags_required = res [i ].sqe_flags ;
159144 break ;
160145 default :
161- ret = - EINVAL ;
162- goto out ;
146+ goto err ;
163147 }
164148 }
165149
166- out :
150+ ret = 0 ;
151+
152+ err :
153+ kfree (res );
154+ return ret ;
155+ }
156+
157+ static __cold int io_register_restrictions (struct io_ring_ctx * ctx ,
158+ void __user * arg , unsigned int nr_args )
159+ {
160+ int ret ;
161+
162+ /* Restrictions allowed only if rings started disabled */
163+ if (!(ctx -> flags & IORING_SETUP_R_DISABLED ))
164+ return - EBADFD ;
165+
166+ /* We allow only a single restrictions registration */
167+ if (ctx -> restrictions .registered )
168+ return - EBUSY ;
169+
170+ ret = io_parse_restrictions (arg , nr_args , & ctx -> restrictions );
167171 /* Reset all restrictions if an error happened */
168172 if (ret != 0 )
169173 memset (& ctx -> restrictions , 0 , sizeof (ctx -> restrictions ));
170174 else
171175 ctx -> restrictions .registered = true;
172-
173- kfree (res );
174176 return ret ;
175177}
176178
0 commit comments