Skip to contentSkip to conversation

net/packet: rx_owner_map depends on pg_vec

PATCH New Willem de Bruijn 1 participant 1 message Dec 15, 2021

Subsystems (3)
lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

PATCH 1/1 net/packet: rx_owner_map depends on pg_vec

From: Willem de Bruijn <[email protected]>

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")
---
 net/packet/af_packet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/packet/af_packet.c +3 -2
index 46943a18a10d..76c2dca7f0a5 100644
@@ -4492,9 +4492,10 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
 	}
 
 out_free_pg_vec:
-	bitmap_free(rx_owner_map);
-	if (pg_vec)
+	if (pg_vec) {
+		bitmap_free(rx_owner_map);
 		free_pg_vec(pg_vec, order, req->tp_block_nr);
+	}
 out:
 	return err;
 }
Signature · 1 line
2.34.1.173.g76aa8bc2d0-goog