ip: validate header length on virtual device xmit
KMSAN detected read beyond end of buffer in vti and sit devices when passing truncated packets with PF_PACKET. The issue affects additional ip tunnel devices. Extend commit76c0ddd8c3
("ip6_tunnel: be careful when accessing the inner header") and commitccfec9e5cb
("ip_tunnel: be careful when accessing the inner header"). Move the check to a separate helper and call at the start of each ndo_start_xmit function in net/ipv4 and net/ipv6. Minor changes: - convert dev_kfree_skb to kfree_skb on error path, as dev_kfree_skb calls consume_skb which is not for error paths. - use pskb_network_may_pull even though that is pedantic here, as the same as pskb_may_pull for devices without llheaders. - do not cache ipv6 hdrs if used only once (unsafe across pskb_may_pull, was more relevant to earlier patch) Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
8c76e77f90
commit
cb9f1b7838
@@ -308,6 +308,26 @@ int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,
|
||||
int ip_tunnel_encap_setup(struct ip_tunnel *t,
|
||||
struct ip_tunnel_encap *ipencap);
|
||||
|
||||
static inline bool pskb_inet_may_pull(struct sk_buff *skb)
|
||||
{
|
||||
int nhlen;
|
||||
|
||||
switch (skb->protocol) {
|
||||
#if IS_ENABLED(CONFIG_IPV6)
|
||||
case htons(ETH_P_IPV6):
|
||||
nhlen = sizeof(struct ipv6hdr);
|
||||
break;
|
||||
#endif
|
||||
case htons(ETH_P_IP):
|
||||
nhlen = sizeof(struct iphdr);
|
||||
break;
|
||||
default:
|
||||
nhlen = 0;
|
||||
}
|
||||
|
||||
return pskb_network_may_pull(skb, nhlen);
|
||||
}
|
||||
|
||||
static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
|
||||
{
|
||||
const struct ip_tunnel_encap_ops *ops;
|
||||
|
Reference in New Issue
Block a user