packet: unconditionally free po->rollover
authorWillem de Bruijn <willemb@google.com>
Fri, 31 May 2019 16:37:23 +0000 (12:37 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jun 2019 10:20:49 +0000 (12:20 +0200)
[ Upstream commit afa0925c6fcc6a8f610e996ca09bc3215048033c ]

Rollover used to use a complex RCU mechanism for assignment, which had
a race condition. The below patch fixed the bug and greatly simplified
the logic.

The feature depends on fanout, but the state is private to the socket.
Fanout_release returns f only when the last member leaves and the
fanout struct is to be freed.

Destroy rollover unconditionally, regardless of fanout state.

Fixes: 57f015f5eccf2 ("packet: fix crash in fanout_demux_rollover()")
Reported-by: syzbot <syzkaller@googlegroups.com>
Diagnosed-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/packet/af_packet.c

index 18df3bce73daf39551efc1d0232debaf486afdc2..d98fcf926166f84e54b88d191f4f86e4a3b113b7 100644 (file)
@@ -3017,8 +3017,8 @@ static int packet_release(struct socket *sock)
 
        synchronize_net();
 
+       kfree(po->rollover);
        if (f) {
-               kfree(po->rollover);
                fanout_release_data(f);
                kfree(f);
        }