Skip to content

Commit 924a9bc

Browse files
bn222davem330
authored andcommitted
net: check if protocol extracted by virtio_net_hdr_set_proto is correct
For gso packets, virtio_net_hdr_set_proto sets the protocol (if it isn't set) based on the type in the virtio net hdr, but the skb could contain anything since it could come from packet_snd through a raw socket. If there is a mismatch between what virtio_net_hdr_set_proto sets and the actual protocol, then the skb could be handled incorrectly later on. An example where this poses an issue is with the subsequent call to skb_flow_dissect_flow_keys_basic which relies on skb->protocol being set correctly. A specially crafted packet could fool skb_flow_dissect_flow_keys_basic preventing EINVAL to be returned. Avoid blindly trusting the information provided by the virtio net header by checking that the protocol in the packet actually matches the protocol set by virtio_net_hdr_set_proto. Note that since the protocol is only checked if skb->dev implements header_ops->parse_protocol, packets from devices without the implementation are not checked at this stage. Fixes: 9274124 ("net: stricter validation of untrusted gso packets") Signed-off-by: Balazs Nemeth <[email protected]> Acked-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 286a862 commit 924a9bc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

include/linux/virtio_net.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
7979
if (gso_type && skb->network_header) {
8080
struct flow_keys_basic keys;
8181

82-
if (!skb->protocol)
82+
if (!skb->protocol) {
83+
__be16 protocol = dev_parse_header_protocol(skb);
84+
8385
virtio_net_hdr_set_proto(skb, hdr);
86+
if (protocol && protocol != skb->protocol)
87+
return -EINVAL;
88+
}
8489
retry:
8590
if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
8691
NULL, 0, 0, 0,

0 commit comments

Comments
 (0)