@@ -2683,7 +2683,7 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
2683
2683
}
2684
2684
if (likely (saddr == NULL )) {
2685
2685
dev = packet_cached_dev_get (po );
2686
- proto = po -> num ;
2686
+ proto = READ_ONCE ( po -> num ) ;
2687
2687
} else {
2688
2688
err = - EINVAL ;
2689
2689
if (msg -> msg_namelen < sizeof (struct sockaddr_ll ))
@@ -2896,7 +2896,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
2896
2896
2897
2897
if (likely (saddr == NULL )) {
2898
2898
dev = packet_cached_dev_get (po );
2899
- proto = po -> num ;
2899
+ proto = READ_ONCE ( po -> num ) ;
2900
2900
} else {
2901
2901
err = - EINVAL ;
2902
2902
if (msg -> msg_namelen < sizeof (struct sockaddr_ll ))
@@ -3171,7 +3171,7 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex,
3171
3171
/* prevents packet_notifier() from calling
3172
3172
* register_prot_hook()
3173
3173
*/
3174
- po -> num = 0 ;
3174
+ WRITE_ONCE ( po -> num , 0 ) ;
3175
3175
__unregister_prot_hook (sk , true);
3176
3176
rcu_read_lock ();
3177
3177
dev_curr = po -> prot_hook .dev ;
@@ -3181,17 +3181,17 @@ static int packet_do_bind(struct sock *sk, const char *name, int ifindex,
3181
3181
}
3182
3182
3183
3183
BUG_ON (po -> running );
3184
- po -> num = proto ;
3184
+ WRITE_ONCE ( po -> num , proto ) ;
3185
3185
po -> prot_hook .type = proto ;
3186
3186
3187
3187
if (unlikely (unlisted )) {
3188
3188
dev_put (dev );
3189
3189
po -> prot_hook .dev = NULL ;
3190
- po -> ifindex = -1 ;
3190
+ WRITE_ONCE ( po -> ifindex , -1 ) ;
3191
3191
packet_cached_dev_reset (po );
3192
3192
} else {
3193
3193
po -> prot_hook .dev = dev ;
3194
- po -> ifindex = dev ? dev -> ifindex : 0 ;
3194
+ WRITE_ONCE ( po -> ifindex , dev ? dev -> ifindex : 0 ) ;
3195
3195
packet_cached_dev_assign (po , dev );
3196
3196
}
3197
3197
}
@@ -3505,7 +3505,7 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
3505
3505
uaddr -> sa_family = AF_PACKET ;
3506
3506
memset (uaddr -> sa_data , 0 , sizeof (uaddr -> sa_data ));
3507
3507
rcu_read_lock ();
3508
- dev = dev_get_by_index_rcu (sock_net (sk ), pkt_sk (sk )-> ifindex );
3508
+ dev = dev_get_by_index_rcu (sock_net (sk ), READ_ONCE ( pkt_sk (sk )-> ifindex ) );
3509
3509
if (dev )
3510
3510
strlcpy (uaddr -> sa_data , dev -> name , sizeof (uaddr -> sa_data ));
3511
3511
rcu_read_unlock ();
@@ -3520,16 +3520,18 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
3520
3520
struct sock * sk = sock -> sk ;
3521
3521
struct packet_sock * po = pkt_sk (sk );
3522
3522
DECLARE_SOCKADDR (struct sockaddr_ll * , sll , uaddr );
3523
+ int ifindex ;
3523
3524
3524
3525
if (peer )
3525
3526
return - EOPNOTSUPP ;
3526
3527
3528
+ ifindex = READ_ONCE (po -> ifindex );
3527
3529
sll -> sll_family = AF_PACKET ;
3528
- sll -> sll_ifindex = po -> ifindex ;
3529
- sll -> sll_protocol = po -> num ;
3530
+ sll -> sll_ifindex = ifindex ;
3531
+ sll -> sll_protocol = READ_ONCE ( po -> num ) ;
3530
3532
sll -> sll_pkttype = 0 ;
3531
3533
rcu_read_lock ();
3532
- dev = dev_get_by_index_rcu (sock_net (sk ), po -> ifindex );
3534
+ dev = dev_get_by_index_rcu (sock_net (sk ), ifindex );
3533
3535
if (dev ) {
3534
3536
sll -> sll_hatype = dev -> type ;
3535
3537
sll -> sll_halen = dev -> addr_len ;
@@ -4108,7 +4110,7 @@ static int packet_notifier(struct notifier_block *this,
4108
4110
}
4109
4111
if (msg == NETDEV_UNREGISTER ) {
4110
4112
packet_cached_dev_reset (po );
4111
- po -> ifindex = -1 ;
4113
+ WRITE_ONCE ( po -> ifindex , -1 ) ;
4112
4114
if (po -> prot_hook .dev )
4113
4115
dev_put (po -> prot_hook .dev );
4114
4116
po -> prot_hook .dev = NULL ;
@@ -4414,7 +4416,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4414
4416
was_running = po -> running ;
4415
4417
num = po -> num ;
4416
4418
if (was_running ) {
4417
- po -> num = 0 ;
4419
+ WRITE_ONCE ( po -> num , 0 ) ;
4418
4420
__unregister_prot_hook (sk , false);
4419
4421
}
4420
4422
spin_unlock (& po -> bind_lock );
@@ -4449,7 +4451,7 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
4449
4451
4450
4452
spin_lock (& po -> bind_lock );
4451
4453
if (was_running ) {
4452
- po -> num = num ;
4454
+ WRITE_ONCE ( po -> num , num ) ;
4453
4455
register_prot_hook (sk );
4454
4456
}
4455
4457
spin_unlock (& po -> bind_lock );
@@ -4619,8 +4621,8 @@ static int packet_seq_show(struct seq_file *seq, void *v)
4619
4621
s ,
4620
4622
refcount_read (& s -> sk_refcnt ),
4621
4623
s -> sk_type ,
4622
- ntohs (po -> num ),
4623
- po -> ifindex ,
4624
+ ntohs (READ_ONCE ( po -> num ) ),
4625
+ READ_ONCE ( po -> ifindex ) ,
4624
4626
po -> running ,
4625
4627
atomic_read (& s -> sk_rmem_alloc ),
4626
4628
from_kuid_munged (seq_user_ns (seq ), sock_i_uid (s )),
0 commit comments