@@ -104,21 +104,13 @@ static int io_register_personality(struct io_ring_ctx *ctx)
104
104
return id ;
105
105
}
106
106
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 )
109
109
{
110
110
struct io_uring_restriction * res ;
111
111
size_t size ;
112
112
int i , ret ;
113
113
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
-
122
114
if (!arg || nr_args > IORING_MAX_RESTRICTIONS )
123
115
return - EINVAL ;
124
116
@@ -130,47 +122,57 @@ static __cold int io_register_restrictions(struct io_ring_ctx *ctx,
130
122
if (IS_ERR (res ))
131
123
return PTR_ERR (res );
132
124
133
- ret = 0 ;
125
+ ret = - EINVAL ;
134
126
135
127
for (i = 0 ; i < nr_args ; i ++ ) {
136
128
switch (res [i ].opcode ) {
137
129
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 );
145
133
break ;
146
134
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 );
153
138
break ;
154
139
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 ;
156
141
break ;
157
142
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 ;
159
144
break ;
160
145
default :
161
- ret = - EINVAL ;
162
- goto out ;
146
+ goto err ;
163
147
}
164
148
}
165
149
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 );
167
171
/* Reset all restrictions if an error happened */
168
172
if (ret != 0 )
169
173
memset (& ctx -> restrictions , 0 , sizeof (ctx -> restrictions ));
170
174
else
171
175
ctx -> restrictions .registered = true;
172
-
173
- kfree (res );
174
176
return ret ;
175
177
}
176
178
0 commit comments