Unverified Commit b72cff81 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!8590 geneve: fix header validation in geneve[6

parents bed797c8 fecde54c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -893,7 +893,7 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
	__be16 sport;
	__be16 sport;
	int err;
	int err;


	if (!pskb_inet_may_pull(skb))
	if (!skb_vlan_inet_prepare(skb))
		return -EINVAL;
		return -EINVAL;


	sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
	sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
@@ -990,7 +990,7 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
	__be16 sport;
	__be16 sport;
	int err;
	int err;


	if (!pskb_inet_may_pull(skb))
	if (!skb_vlan_inet_prepare(skb))
		return -EINVAL;
		return -EINVAL;


	sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
	sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true);
+33 −0
Original line number Original line Diff line number Diff line
@@ -333,6 +333,39 @@ static inline bool pskb_inet_may_pull(struct sk_buff *skb)
	return pskb_network_may_pull(skb, nhlen);
	return pskb_network_may_pull(skb, nhlen);
}
}


/* Variant of pskb_inet_may_pull().
 */
static inline bool skb_vlan_inet_prepare(struct sk_buff *skb)
{
	int nhlen = 0, maclen = ETH_HLEN;
	__be16 type = skb->protocol;

	/* Essentially this is skb_protocol(skb, true)
	 * And we get MAC len.
	 */
	if (eth_type_vlan(type))
		type = __vlan_get_protocol(skb, type, &maclen);

	switch (type) {
#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;
	}
	/* For ETH_P_IPV6/ETH_P_IP we make sure to pull
	 * a base network header in skb->head.
	 */
	if (!pskb_may_pull(skb, maclen + nhlen))
		return false;

	skb_set_network_header(skb, maclen);
	return true;
}

static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
{
{
	const struct ip_tunnel_encap_ops *ops;
	const struct ip_tunnel_encap_ops *ops;