packet: fix race condition in packet_set_ring
authorPhilip Pettersson <philip.pettersson@gmail.com>
Wed, 30 Nov 2016 22:55:36 +0000 (14:55 -0800)
committerManish Tuteja <mtuteja@nvidia.com>
Thu, 6 Apr 2017 00:59:58 +0000 (17:59 -0700)
commit3be264a961cfd7570ad4cd20e5003fa5d49c57d9
tree190e8eb0765b406247f3101ab226f77aaac14863
parent6f6a446cb3cb57e17703ac7da98bfe51f8e0db3a
packet: fix race condition in packet_set_ring

When packet_set_ring creates a ring buffer it will initialize a
struct timer_list if the packet version is TPACKET_V3. This value
can then be raced by a different thread calling setsockopt to
set the version to TPACKET_V1 before packet_set_ring has finished.

This leads to a use-after-free on a function pointer in the
struct timer_list when the socket is closed as the previously
initialized timer will not be deleted.

The bug is fixed by taking lock_sock(sk) in packet_setsockopt when
changing the packet version while also taking the lock at the start
of packet_set_ring.

Bug 1880704

Change-Id: I22d2920ff6c26877f671908ea683468aed693fec
Fixes: f6fb8f100b80 ("af-packet: TPACKET_V3 flexible buffer implementation.")
Signed-off-by: Philip Pettersson <philip.pettersson@gmail.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Gagan Grover <ggrover@nvidia.com>
Reviewed-on: http://git-master/r/1311860
(cherry picked from commit 41db91bad41df89ba1e8b3d32f935130f71ac78e)
Reviewed-on: http://git-master/r/1314068
(cherry picked from commit b4db8ee7615291eeb622024f5c3e9175bcea6d50)
Reviewed-on: http://git-master/r/1455428
Reviewed-by: Manish Tuteja <mtuteja@nvidia.com>
Tested-by: Manish Tuteja <mtuteja@nvidia.com>
net/packet/af_packet.c