@@ -168,7 +168,7 @@ static bool inet_use_bhash2_on_bind(const struct sock *sk)
168168}
169169
170170static bool inet_bind_conflict (const struct sock * sk , struct sock * sk2 ,
171- kuid_t sk_uid , bool relax ,
171+ kuid_t uid , bool relax ,
172172 bool reuseport_cb_ok , bool reuseport_ok )
173173{
174174 int bound_dev_if2 ;
@@ -185,20 +185,20 @@ static bool inet_bind_conflict(const struct sock *sk, struct sock *sk2,
185185 if (!relax || (!reuseport_ok && sk -> sk_reuseport &&
186186 sk2 -> sk_reuseport && reuseport_cb_ok &&
187187 (sk2 -> sk_state == TCP_TIME_WAIT ||
188- uid_eq (sk_uid , sock_i_uid (sk2 )))))
188+ uid_eq (uid , sk_uid (sk2 )))))
189189 return true;
190190 } else if (!reuseport_ok || !sk -> sk_reuseport ||
191191 !sk2 -> sk_reuseport || !reuseport_cb_ok ||
192192 (sk2 -> sk_state != TCP_TIME_WAIT &&
193- !uid_eq (sk_uid , sock_i_uid (sk2 )))) {
193+ !uid_eq (uid , sk_uid (sk2 )))) {
194194 return true;
195195 }
196196 }
197197 return false;
198198}
199199
200200static bool __inet_bhash2_conflict (const struct sock * sk , struct sock * sk2 ,
201- kuid_t sk_uid , bool relax ,
201+ kuid_t uid , bool relax ,
202202 bool reuseport_cb_ok , bool reuseport_ok )
203203{
204204 if (ipv6_only_sock (sk2 )) {
@@ -211,20 +211,20 @@ static bool __inet_bhash2_conflict(const struct sock *sk, struct sock *sk2,
211211#endif
212212 }
213213
214- return inet_bind_conflict (sk , sk2 , sk_uid , relax ,
214+ return inet_bind_conflict (sk , sk2 , uid , relax ,
215215 reuseport_cb_ok , reuseport_ok );
216216}
217217
218218static bool inet_bhash2_conflict (const struct sock * sk ,
219219 const struct inet_bind2_bucket * tb2 ,
220- kuid_t sk_uid ,
220+ kuid_t uid ,
221221 bool relax , bool reuseport_cb_ok ,
222222 bool reuseport_ok )
223223{
224224 struct sock * sk2 ;
225225
226226 sk_for_each_bound (sk2 , & tb2 -> owners ) {
227- if (__inet_bhash2_conflict (sk , sk2 , sk_uid , relax ,
227+ if (__inet_bhash2_conflict (sk , sk2 , uid , relax ,
228228 reuseport_cb_ok , reuseport_ok ))
229229 return true;
230230 }
@@ -242,8 +242,8 @@ static int inet_csk_bind_conflict(const struct sock *sk,
242242 const struct inet_bind2_bucket * tb2 , /* may be null */
243243 bool relax , bool reuseport_ok )
244244{
245- kuid_t uid = sock_i_uid ((struct sock * )sk );
246245 struct sock_reuseport * reuseport_cb ;
246+ kuid_t uid = sk_uid (sk );
247247 bool reuseport_cb_ok ;
248248 struct sock * sk2 ;
249249
@@ -287,11 +287,11 @@ static int inet_csk_bind_conflict(const struct sock *sk,
287287static bool inet_bhash2_addr_any_conflict (const struct sock * sk , int port , int l3mdev ,
288288 bool relax , bool reuseport_ok )
289289{
290- kuid_t uid = sock_i_uid ((struct sock * )sk );
291290 const struct net * net = sock_net (sk );
292291 struct sock_reuseport * reuseport_cb ;
293292 struct inet_bind_hashbucket * head2 ;
294293 struct inet_bind2_bucket * tb2 ;
294+ kuid_t uid = sk_uid (sk );
295295 bool conflict = false;
296296 bool reuseport_cb_ok ;
297297
@@ -425,15 +425,13 @@ inet_csk_find_open_port(const struct sock *sk, struct inet_bind_bucket **tb_ret,
425425static inline int sk_reuseport_match (struct inet_bind_bucket * tb ,
426426 struct sock * sk )
427427{
428- kuid_t uid = sock_i_uid (sk );
429-
430428 if (tb -> fastreuseport <= 0 )
431429 return 0 ;
432430 if (!sk -> sk_reuseport )
433431 return 0 ;
434432 if (rcu_access_pointer (sk -> sk_reuseport_cb ))
435433 return 0 ;
436- if (!uid_eq (tb -> fastuid , uid ))
434+ if (!uid_eq (tb -> fastuid , sk_uid ( sk ) ))
437435 return 0 ;
438436 /* We only need to check the rcv_saddr if this tb was once marked
439437 * without fastreuseport and then was reset, as we can only know that
@@ -458,14 +456,13 @@ static inline int sk_reuseport_match(struct inet_bind_bucket *tb,
458456void inet_csk_update_fastreuse (struct inet_bind_bucket * tb ,
459457 struct sock * sk )
460458{
461- kuid_t uid = sock_i_uid (sk );
462459 bool reuse = sk -> sk_reuse && sk -> sk_state != TCP_LISTEN ;
463460
464461 if (hlist_empty (& tb -> bhash2 )) {
465462 tb -> fastreuse = reuse ;
466463 if (sk -> sk_reuseport ) {
467464 tb -> fastreuseport = FASTREUSEPORT_ANY ;
468- tb -> fastuid = uid ;
465+ tb -> fastuid = sk_uid ( sk ) ;
469466 tb -> fast_rcv_saddr = sk -> sk_rcv_saddr ;
470467 tb -> fast_ipv6_only = ipv6_only_sock (sk );
471468 tb -> fast_sk_family = sk -> sk_family ;
@@ -492,7 +489,7 @@ void inet_csk_update_fastreuse(struct inet_bind_bucket *tb,
492489 */
493490 if (!sk_reuseport_match (tb , sk )) {
494491 tb -> fastreuseport = FASTREUSEPORT_STRICT ;
495- tb -> fastuid = uid ;
492+ tb -> fastuid = sk_uid ( sk ) ;
496493 tb -> fast_rcv_saddr = sk -> sk_rcv_saddr ;
497494 tb -> fast_ipv6_only = ipv6_only_sock (sk );
498495 tb -> fast_sk_family = sk -> sk_family ;
0 commit comments