]> git.baikalelectronics.ru Git - kernel.git/commit
soreuseport: fix initialization race
authorCraig Gallek <kraig@google.com>
Thu, 19 Oct 2017 19:00:29 +0000 (15:00 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sun, 22 Oct 2017 01:03:51 +0000 (02:03 +0100)
commitc79b42696f6e8e6051235ea9d3c346a334498004
tree2f96c8a5f8251654c8aaf3874681cd04c02b24e8
parent5bb08191e267faf9a52597ed6b5b596cb6621553
soreuseport: fix initialization race

Syzkaller stumbled upon a way to trigger
WARNING: CPU: 1 PID: 13881 at net/core/sock_reuseport.c:41
reuseport_alloc+0x306/0x3b0 net/core/sock_reuseport.c:39

There are two initialization paths for the sock_reuseport structure in a
socket: Through the udp/tcp bind paths of SO_REUSEPORT sockets or through
SO_ATTACH_REUSEPORT_[CE]BPF before bind.  The existing implementation
assumedthat the socket lock protected both of these paths when it actually
only protects the SO_ATTACH_REUSEPORT path.  Syzkaller triggered this
double allocation by running these paths concurrently.

This patch moves the check for double allocation into the reuseport_alloc
function which is protected by a global spin lock.

Fixes: 19a6a54d7cdd ("soreuseport: fast reuseport UDP socket selection")
Fixes: 0f66db96d4c3 ("soreuseport: fast reuseport TCP socket selection")
Signed-off-by: Craig Gallek <kraig@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/sock_reuseport.c
net/ipv4/inet_hashtables.c
net/ipv4/udp.c