net/packet: rx_owner_map depends on pg_vec

[ Upstream commit ec6af094ea28f0f2dda1a6a33b14cd57e36a9755 ]

Packet sockets may switch ring versions. Avoid misinterpreting state
between versions, whose fields share a union. rx_owner_map is only
allocated with a packet ring (pg_vec) and both are swapped together.
If pg_vec is NULL, meaning no packet ring was allocated, then neither
was rx_owner_map. And the field may be old state from a tpacket_v3.

Fixes: 61fad6816fc1 ("net/packet: tpacket_rcv: avoid a producer race condition")
Reported-by: Syzbot <syzbot+1ac0994a0a0c55151121@syzkaller.appspotmail.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20211215143937.106178-1-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 7da349f07e457cad135df0920a3f670e423fb5e9)
Signed-off-by: Robert Kolchmeyer <rkolchmeyer@google.com>

BUG=b/213408300,b/213920404
TEST=presubmit
RELEASE_NOTE=Fixed a double-free issue in packet_set_ring in the Linux kernel.

cos-patch: bug
Change-Id: Ida77996f5bcbdf5441eb3bf8b15a9025809f2d35
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/27240
Reviewed-by: Vaibhav Rustagi <vaibhavrustagi@google.com>
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
Tested-by: Robert Kolchmeyer <rkolchmeyer@google.com>
1 file changed