]> git.baikalelectronics.ru Git - kernel.git/commit
net: check if protocol extracted by virtio_net_hdr_set_proto is correct
authorBalazs Nemeth <bnemeth@redhat.com>
Tue, 9 Mar 2021 11:31:00 +0000 (12:31 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 10 Mar 2021 00:12:20 +0000 (16:12 -0800)
commitd418c76abbe7e74bae99c564b0e67416b399ca06
tree39c880b0dd7a77a7c0c870f8e1b36f3dad6d46c4
parentbbeb008bbe2d801d6a82a0799e8f479723691ae8
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: 7b88ffe94ff5 ("net: stricter validation of untrusted gso packets")
Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/virtio_net.h