Skip to content

Commit c37ccc0

Browse files
Eric Dumazetdavem330
authored andcommitted
udp: add a missing smp_wmb() in udp_lib_get_port()
Corey Minyard spotted a missing memory barrier in udp_lib_get_port() We need to make sure a reader cannot read the new 'sk->sk_next' value and previous value of 'sk->sk_hash'. Or else, an item could be deleted from a chain, and inserted into another chain. If new chain was empty before the move, 'next' pointer is NULL, and lockless reader can not detect it missed following items in original chain. This patch is temporary, since we expect an upcoming patch to introduce another way of handling the problem. Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7e3a42a commit c37ccc0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎net/ipv4/udp.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
189189
inet_sk(sk)->num = snum;
190190
sk->sk_hash = snum;
191191
if (sk_unhashed(sk)) {
192+
/*
193+
* We need that previous write to sk->sk_hash committed
194+
* before write to sk->next done in following add_node() variant
195+
*/
196+
smp_wmb();
192197
sk_add_node_rcu(sk, &hslot->head);
193198
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
194199
}

0 commit comments

Comments
 (0)