Commit 7d9dbdfb authored by Menglong Dong's avatar Menglong Dong Committed by David S. Miller

net: ipv6: add skb drop reasons to TLV parse

Replace kfree_skb() used in TLV encoded option header parsing with
kfree_skb_reason(). Following functions are involved:

ip6_parse_tlv()
ipv6_hop_ra()
ipv6_hop_ioam()
ipv6_hop_jumbo()
ipv6_hop_calipso()
ipv6_dest_hao()

Most skb drops during this process are regarded as 'InHdrErrors',
as 'IPSTATS_MIB_INHDRERRORS' is used when ip6_parse_tlv() fails,
which make we use 'SKB_DROP_REASON_IP_INHDR' correspondingly.

However, 'IP_INHDR' is a relatively general reason. Therefore, we
can use other reasons with higher priority in some cases. For example,
'SKB_DROP_REASON_UNHANDLED_PROTO' is used for unknown TLV options.
Signed-off-by: default avatarMenglong Dong <imagedong@tencent.com>
Reviewed-by: default avatarJiang Biao <benbjiang@tencent.com>
Reviewed-by: default avatarHao Peng <flyingpeng@tencent.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bba98083
...@@ -90,12 +90,13 @@ static bool ip6_tlvopt_unknown(struct sk_buff *skb, int optoff, ...@@ -90,12 +90,13 @@ static bool ip6_tlvopt_unknown(struct sk_buff *skb, int optoff,
break; break;
fallthrough; fallthrough;
case 2: /* send ICMP PARM PROB regardless and drop packet */ case 2: /* send ICMP PARM PROB regardless and drop packet */
icmpv6_param_prob(skb, ICMPV6_UNK_OPTION, optoff); icmpv6_param_prob_reason(skb, ICMPV6_UNK_OPTION, optoff,
SKB_DROP_REASON_UNHANDLED_PROTO);
return false; return false;
} }
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_UNHANDLED_PROTO);
return false; return false;
} }
...@@ -218,7 +219,7 @@ static bool ip6_parse_tlv(bool hopbyhop, ...@@ -218,7 +219,7 @@ static bool ip6_parse_tlv(bool hopbyhop,
if (len == 0) if (len == 0)
return true; return true;
bad: bad:
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
...@@ -232,6 +233,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) ...@@ -232,6 +233,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff)
struct ipv6_destopt_hao *hao; struct ipv6_destopt_hao *hao;
struct inet6_skb_parm *opt = IP6CB(skb); struct inet6_skb_parm *opt = IP6CB(skb);
struct ipv6hdr *ipv6h = ipv6_hdr(skb); struct ipv6hdr *ipv6h = ipv6_hdr(skb);
SKB_DR(reason);
int ret; int ret;
if (opt->dsthao) { if (opt->dsthao) {
...@@ -246,19 +248,23 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) ...@@ -246,19 +248,23 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff)
if (hao->length != 16) { if (hao->length != 16) {
net_dbg_ratelimited("hao invalid option length = %d\n", net_dbg_ratelimited("hao invalid option length = %d\n",
hao->length); hao->length);
SKB_DR_SET(reason, IP_INHDR);
goto discard; goto discard;
} }
if (!(ipv6_addr_type(&hao->addr) & IPV6_ADDR_UNICAST)) { if (!(ipv6_addr_type(&hao->addr) & IPV6_ADDR_UNICAST)) {
net_dbg_ratelimited("hao is not an unicast addr: %pI6\n", net_dbg_ratelimited("hao is not an unicast addr: %pI6\n",
&hao->addr); &hao->addr);
SKB_DR_SET(reason, INVALID_PROTO);
goto discard; goto discard;
} }
ret = xfrm6_input_addr(skb, (xfrm_address_t *)&ipv6h->daddr, ret = xfrm6_input_addr(skb, (xfrm_address_t *)&ipv6h->daddr,
(xfrm_address_t *)&hao->addr, IPPROTO_DSTOPTS); (xfrm_address_t *)&hao->addr, IPPROTO_DSTOPTS);
if (unlikely(ret < 0)) if (unlikely(ret < 0)) {
SKB_DR_SET(reason, XFRM_POLICY);
goto discard; goto discard;
}
if (skb_cloned(skb)) { if (skb_cloned(skb)) {
if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
...@@ -281,7 +287,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff) ...@@ -281,7 +287,7 @@ static bool ipv6_dest_hao(struct sk_buff *skb, int optoff)
return true; return true;
discard: discard:
kfree_skb(skb); kfree_skb_reason(skb, reason);
return false; return false;
} }
#endif #endif
...@@ -931,7 +937,7 @@ static bool ipv6_hop_ra(struct sk_buff *skb, int optoff) ...@@ -931,7 +937,7 @@ static bool ipv6_hop_ra(struct sk_buff *skb, int optoff)
} }
net_dbg_ratelimited("ipv6_hop_ra: wrong RA length %d\n", net_dbg_ratelimited("ipv6_hop_ra: wrong RA length %d\n",
nh[optoff + 1]); nh[optoff + 1]);
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
...@@ -985,7 +991,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) ...@@ -985,7 +991,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff)
return true; return true;
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
...@@ -994,26 +1000,32 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff) ...@@ -994,26 +1000,32 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff)
static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff) static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff)
{ {
const unsigned char *nh = skb_network_header(skb); const unsigned char *nh = skb_network_header(skb);
SKB_DR(reason);
u32 pkt_len; u32 pkt_len;
if (nh[optoff + 1] != 4 || (optoff & 3) != 2) { if (nh[optoff + 1] != 4 || (optoff & 3) != 2) {
net_dbg_ratelimited("ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n", net_dbg_ratelimited("ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n",
nh[optoff+1]); nh[optoff+1]);
SKB_DR_SET(reason, IP_INHDR);
goto drop; goto drop;
} }
pkt_len = ntohl(*(__be32 *)(nh + optoff + 2)); pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
if (pkt_len <= IPV6_MAXPLEN) { if (pkt_len <= IPV6_MAXPLEN) {
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2); icmpv6_param_prob_reason(skb, ICMPV6_HDR_FIELD, optoff + 2,
SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
if (ipv6_hdr(skb)->payload_len) { if (ipv6_hdr(skb)->payload_len) {
icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff); icmpv6_param_prob_reason(skb, ICMPV6_HDR_FIELD, optoff,
SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
if (pkt_len > skb->len - sizeof(struct ipv6hdr)) if (pkt_len > skb->len - sizeof(struct ipv6hdr)) {
SKB_DR_SET(reason, PKT_TOO_SMALL);
goto drop; goto drop;
}
if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
goto drop; goto drop;
...@@ -1022,7 +1034,7 @@ static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff) ...@@ -1022,7 +1034,7 @@ static bool ipv6_hop_jumbo(struct sk_buff *skb, int optoff)
return true; return true;
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, reason);
return false; return false;
} }
...@@ -1044,7 +1056,7 @@ static bool ipv6_hop_calipso(struct sk_buff *skb, int optoff) ...@@ -1044,7 +1056,7 @@ static bool ipv6_hop_calipso(struct sk_buff *skb, int optoff)
return true; return true;
drop: drop:
kfree_skb(skb); kfree_skb_reason(skb, SKB_DROP_REASON_IP_INHDR);
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment