net: sock_copy() fixes
commit12774fb9ee081777593aa3028012929bd8ff3f8b
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 29 Jul 2009 01:59:07 +0000 (28 18:59 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sun, 16 Aug 2009 21:18:13 +0000 (16 14:18 -0700)
treedc0610ee41d9b48c9aeb7ae09d1fd4f4f6b756d8
parent822b3dc1720ae478264c6dbed294d1bd9599da86
net: sock_copy() fixes

[ Upstream commit 4dc6dc7162c08b9965163c9ab3f9375d4adff2c7 ]

Commit e912b1142be8f1e2c71c71001dc992c6e5eb2ec1
(net: sk_prot_alloc() should not blindly overwrite memory)
took care of not zeroing whole new socket at allocation time.

sock_copy() is another spot where we should be very careful.
We should not set refcnt to a non null value, until
we are sure other fields are correctly setup, or
a lockless reader could catch this socket by mistake,
while not fully (re)initialized.

This patch puts sk_node & sk_refcnt to the very beginning
of struct sock to ease sock_copy() & sk_prot_alloc() job.

We add appropriate smp_wmb() before sk_refcnt initializations
to match our RCU requirements (changes to sock keys should
be committed to memory before sk_refcnt setting)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/net/sock.h
net/core/sock.c