@@ -684,7 +684,7 @@ static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
684684 struct sock * sk = & sp -> inet .sk ;
685685 struct net * net = sock_net (sk );
686686 struct net_device * dev = NULL ;
687- int type ;
687+ int type , res , bound_dev_if ;
688688
689689 type = ipv6_addr_type (in6 );
690690 if (IPV6_ADDR_ANY == type )
@@ -698,14 +698,21 @@ static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
698698 if (!(type & IPV6_ADDR_UNICAST ))
699699 return 0 ;
700700
701- if (sk -> sk_bound_dev_if ) {
702- dev = dev_get_by_index_rcu (net , sk -> sk_bound_dev_if );
701+ rcu_read_lock ();
702+ bound_dev_if = READ_ONCE (sk -> sk_bound_dev_if );
703+ if (bound_dev_if ) {
704+ res = 0 ;
705+ dev = dev_get_by_index_rcu (net , bound_dev_if );
703706 if (!dev )
704- return 0 ;
707+ goto out ;
705708 }
706709
707- return ipv6_can_nonlocal_bind (net , & sp -> inet ) ||
708- ipv6_chk_addr (net , in6 , dev , 0 );
710+ res = ipv6_can_nonlocal_bind (net , & sp -> inet ) ||
711+ ipv6_chk_addr (net , in6 , dev , 0 );
712+
713+ out :
714+ rcu_read_unlock ();
715+ return res ;
709716}
710717
711718/* This function checks if the address is a valid address to be used for
0 commit comments