Skip to contentSkip to conversation

ipv6: more drop reason

PATCH Applied Eric Dumazet 3 participants 10 messages Feb 10, 2023 – Feb 14, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ipv6: more drop reason

Add more drop reasons to IPv6:

- IPV6_BAD_EXTHDR
- IPV6_NDISC_FRAG
- IPV6_NDISC_HOP_LIMIT
- IPV6_NDISC_BAD_CODE

Eric Dumazet (4):
net: dropreason: add SKB_DROP_REASON_IPV6_BAD_EXTHDR
net: add pskb_may_pull_reason() helper
ipv6: icmp6: add drop reason support to icmpv6_notify()
ipv6: icmp6: add drop reason support to ndisc_rcv()

 include/linux/skbuff.h   | 19 +++++++++++++++----
 include/net/dropreason.h | 12 ++++++++++++
 include/net/ipv6.h       |  3 ++-
 include/net/ndisc.h      |  2 +-
 net/ipv6/icmp.c          | 27 ++++++++++++++++++---------
 net/ipv6/ndisc.c         | 13 +++++++------
 6 files changed, 55 insertions(+), 21 deletions(-)
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
#1 lore raw

PATCH 1/4 net: dropreason: add SKB_DROP_REASON_IPV6_BAD_EXTHDR

This drop reason can be used whenever an IPv6 packet has a malformed extension header.

---
 include/net/dropreason.h | 3 +++
 1 file changed, 3 insertions(+)
include/net/dropreason.h +3 -0
index 94bc3d5d880305a8c968a1801dabef83d995c567..6c41e535175cfba44f1f948305c5a1ebc5be9a18 100644
@@ -72,6 +72,7 @@
 	FN(FRAG_REASM_TIMEOUT)		\
 	FN(FRAG_TOO_FAR)		\
 	FN(TCP_MINTTL)			\
+	FN(IPV6_BAD_EXTHDR)		\
 	FNe(MAX)
 
 /**
@@ -318,6 +319,8 @@ enum skb_drop_reason {
 	 * the threshold (IP_MINTTL or IPV6_MINHOPCOUNT).
 	 */
 	SKB_DROP_REASON_TCP_MINTTL,
+	/** @SKB_DROP_REASON_IPV6_BAD_EXTHDR: Bad IPv6 extension header. */
+	SKB_DROP_REASON_IPV6_BAD_EXTHDR,
 	/**
 	 * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
 	 * used as a real 'reason'
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH net-next 1/4] net: dropreason: add SKB_DROP_REASON_IPV6_BAD_EXTHDR

Quoted 8 lines · Eric Dumazet

This drop reason can be used whenever an IPv6 packet has a malformed extension header.

---
 include/net/dropreason.h | 3 +++
 1 file changed, 3 insertions(+)
#3 lore raw

PATCH 2/4 net: add pskb_may_pull_reason() helper

In reply to Eric Dumazet

pskb_may_pull() can fail for two different reasons.

Provide pskb_may_pull_reason() helper to distinguish between these reasons.

It returns:

SKB_NOT_DROPPED_YET : Success
SKB_DROP_REASON_PKT_TOO_SMALL : packet too small
SKB_DROP_REASON_NOMEM : skb->head could not be resized

---
 include/linux/skbuff.h | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
include/linux/skbuff.h +15 -4
index 47ab28a37f2f1f9fb25e575fffe2db1cfd884f65..d5602b15c714fa3bd67d56793857b2bb5c21542e 100644
@@ -2631,13 +2631,24 @@ void *skb_pull_data(struct sk_buff *skb, size_t len);
 
 void *__pskb_pull_tail(struct sk_buff *skb, int delta);
 
-static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
+static inline enum skb_drop_reason
+pskb_may_pull_reason(struct sk_buff *skb, unsigned int len)
 {
 	if (likely(len <= skb_headlen(skb)))
-		return true;
+		return SKB_NOT_DROPPED_YET;
+
 	if (unlikely(len > skb->len))
-		return false;
-	return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL;
+		return SKB_DROP_REASON_PKT_TOO_SMALL;
+
+	if (unlikely(!__pskb_pull_tail(skb, len - skb_headlen(skb))))
+		return SKB_DROP_REASON_NOMEM;
+
+	return SKB_NOT_DROPPED_YET;
+}
+
+static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
+{
+	return pskb_may_pull_reason(skb, len) == SKB_NOT_DROPPED_YET;
 }
 
 static inline void *pskb_pull(struct sk_buff *skb, unsigned int len)
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
maintainer Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH net-next 2/4] net: add pskb_may_pull_reason() helper

Quoted 7 lines · Eric Dumazet

pskb_may_pull() can fail for two different reasons.

Provide pskb_may_pull_reason() helper to distinguish between these reasons.

It returns:

Quoted 9 lines

SKB_NOT_DROPPED_YET : Success
SKB_DROP_REASON_PKT_TOO_SMALL : packet too small
SKB_DROP_REASON_NOMEM : skb->head could not be resized

---
 include/linux/skbuff.h | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
#5 lore raw

PATCH 3/4 ipv6: icmp6: add drop reason support to icmpv6_notify()

In reply to Eric Dumazet

Accurately reports what happened in icmpv6_notify() when handling a packet.

This makes use of the new IPV6_BAD_EXTHDR drop reason.

---
 include/net/ipv6.h |  3 ++-
 net/ipv6/icmp.c    | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)
include/net/ipv6.h +2 -1
index 03f3af02a9a645b49c1de1272caf5d8d8277d0c1..7332296eca44b84dca1bbecb545f6824a0e8ed3d 100644
@@ -436,7 +436,8 @@ static inline void fl6_sock_release(struct ip6_flowlabel *fl)
 		atomic_dec(&fl->users);
 }
 
-void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info);
+enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type,
+				   u8 code, __be32 info);
 
 void icmpv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
 				struct icmp6hdr *thdr, int len);
net/ipv6/icmp.c +17 -8
index c9346515e24dabce3aae642bfca4fb4eae4c3533..40bb5dedac09e4e4f3bd15944538c4324d028674 100644
@@ -813,16 +813,19 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
 	local_bh_enable();
 }
 
-void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
+enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type,
+				   u8 code, __be32 info)
 {
 	struct inet6_skb_parm *opt = IP6CB(skb);
+	struct net *net = dev_net(skb->dev);
 	const struct inet6_protocol *ipprot;
+	enum skb_drop_reason reason;
 	int inner_offset;
 	__be16 frag_off;
 	u8 nexthdr;
-	struct net *net = dev_net(skb->dev);
 
-	if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
+	reason = pskb_may_pull_reason(skb, sizeof(struct ipv6hdr));
+	if (reason != SKB_NOT_DROPPED_YET)
 		goto out;
 
 	seg6_icmp_srh(skb, opt);
@@ -832,14 +835,17 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
 		/* now skip over extension headers */
 		inner_offset = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr),
 						&nexthdr, &frag_off);
-		if (inner_offset < 0)
+		if (inner_offset < 0) {
+			SKB_DR_SET(reason, IPV6_BAD_EXTHDR);
 			goto out;
+		}
 	} else {
 		inner_offset = sizeof(struct ipv6hdr);
 	}
 
 	/* Checkin header including 8 bytes of inner protocol header. */
-	if (!pskb_may_pull(skb, inner_offset+8))
+	reason = pskb_may_pull_reason(skb, inner_offset + 8);
+	if (reason != SKB_NOT_DROPPED_YET)
 		goto out;
 
 	/* BUGGG_FUTURE: we should try to parse exthdrs in this packet.
@@ -854,10 +860,11 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)
 		ipprot->err_handler(skb, opt, type, code, inner_offset, info);
 
 	raw6_icmp_error(skb, nexthdr, type, code, inner_offset, info);
-	return;
+	return SKB_CONSUMED;
 
 out:
 	__ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
+	return reason;
 }
 
 /*
@@ -953,7 +960,8 @@ static int icmpv6_rcv(struct sk_buff *skb)
 	case ICMPV6_DEST_UNREACH:
 	case ICMPV6_TIME_EXCEED:
 	case ICMPV6_PARAMPROB:
-		icmpv6_notify(skb, type, hdr->icmp6_code, hdr->icmp6_mtu);
+		reason = icmpv6_notify(skb, type, hdr->icmp6_code,
+				       hdr->icmp6_mtu);
 		break;
 
 	case NDISC_ROUTER_SOLICITATION:
@@ -995,7 +1003,8 @@ static int icmpv6_rcv(struct sk_buff *skb)
 		 * must pass to upper level
 		 */
 
-		icmpv6_notify(skb, type, hdr->icmp6_code, hdr->icmp6_mtu);
+		reason = icmpv6_notify(skb, type, hdr->icmp6_code,
+				       hdr->icmp6_mtu);
 	}
 
 	/* until the v6 path can be better sorted assume failure and
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
maintainer Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH net-next 3/4] ipv6: icmp6: add drop reason support to icmpv6_notify()

Quoted 11 lines · Eric Dumazet

Accurately reports what happened in icmpv6_notify() when handling a packet.

This makes use of the new IPV6_BAD_EXTHDR drop reason.

---
 include/net/ipv6.h |  3 ++-
 net/ipv6/icmp.c    | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)
#7 lore raw

PATCH 4/4 ipv6: icmp6: add drop reason support to ndisc_rcv()

In reply to Eric Dumazet

Creates three new drop reasons:

SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc).

SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit.

SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code.

---
 include/net/dropreason.h |  9 +++++++++
 include/net/ndisc.h      |  2 +-
 net/ipv6/icmp.c          |  2 +-
 net/ipv6/ndisc.c         | 13 +++++++------
 4 files changed, 18 insertions(+), 8 deletions(-)
include/net/dropreason.h +9 -0
index 6c41e535175cfba44f1f948305c5a1ebc5be9a18..ef3f65d135d375920e88759890947ed0f6e87e10 100644
@@ -73,6 +73,9 @@
 	FN(FRAG_TOO_FAR)		\
 	FN(TCP_MINTTL)			\
 	FN(IPV6_BAD_EXTHDR)		\
+	FN(IPV6_NDISC_FRAG)		\
+	FN(IPV6_NDISC_HOP_LIMIT)	\
+	FN(IPV6_NDISC_BAD_CODE)		\
 	FNe(MAX)
 
 /**
@@ -321,6 +324,12 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_TCP_MINTTL,
 	/** @SKB_DROP_REASON_IPV6_BAD_EXTHDR: Bad IPv6 extension header. */
 	SKB_DROP_REASON_IPV6_BAD_EXTHDR,
+	/** @SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc). */
+	SKB_DROP_REASON_IPV6_NDISC_FRAG,
+	/** @SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit. */
+	SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT,
+	/** @SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code. */
+	SKB_DROP_REASON_IPV6_NDISC_BAD_CODE,
 	/**
 	 * @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
 	 * used as a real 'reason'
include/net/ndisc.h +1 -1
index da7eec8669ec4125b0b238f3af8627cd57a279b4..07e5168cdaf9a5a5a180a2d97c646552655982ce 100644
@@ -445,7 +445,7 @@ int ndisc_late_init(void);
 void ndisc_late_cleanup(void);
 void ndisc_cleanup(void);
 
-int ndisc_rcv(struct sk_buff *skb);
+enum skb_drop_reason ndisc_rcv(struct sk_buff *skb);
 
 struct sk_buff *ndisc_ns_create(struct net_device *dev, const struct in6_addr *solicit,
 				const struct in6_addr *saddr, u64 nonce);
net/ipv6/icmp.c +1 -1
index 40bb5dedac09e4e4f3bd15944538c4324d028674..f32bc98155bfb027dd3328eefd4a26a1d067c013 100644
@@ -969,7 +969,7 @@ static int icmpv6_rcv(struct sk_buff *skb)
 	case NDISC_NEIGHBOUR_SOLICITATION:
 	case NDISC_NEIGHBOUR_ADVERTISEMENT:
 	case NDISC_REDIRECT:
-		ndisc_rcv(skb);
+		reason = ndisc_rcv(skb);
 		break;
 
 	case ICMPV6_MGM_QUERY:
net/ipv6/ndisc.c +7 -6
index 3a553494ff16468401f88a384423729a673188b3..9548b5a44714f98975a8b7194bc81cbb0f72697f 100644
@@ -1804,15 +1804,16 @@ static bool ndisc_suppress_frag_ndisc(struct sk_buff *skb)
 	return false;
 }
 
-int ndisc_rcv(struct sk_buff *skb)
+enum skb_drop_reason ndisc_rcv(struct sk_buff *skb)
 {
 	struct nd_msg *msg;
+	SKB_DR(reason);
 
 	if (ndisc_suppress_frag_ndisc(skb))
-		return 0;
+		return SKB_DROP_REASON_IPV6_NDISC_FRAG;
 
 	if (skb_linearize(skb))
-		return 0;
+		return SKB_DROP_REASON_NOMEM;
 
 	msg = (struct nd_msg *)skb_transport_header(skb);
 
@@ -1821,13 +1822,13 @@ int ndisc_rcv(struct sk_buff *skb)
 	if (ipv6_hdr(skb)->hop_limit != 255) {
 		ND_PRINTK(2, warn, "NDISC: invalid hop-limit: %d\n",
 			  ipv6_hdr(skb)->hop_limit);
-		return 0;
+		return SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT;
 	}
 
 	if (msg->icmph.icmp6_code != 0) {
 		ND_PRINTK(2, warn, "NDISC: invalid ICMPv6 code: %d\n",
 			  msg->icmph.icmp6_code);
-		return 0;
+		return SKB_DROP_REASON_IPV6_NDISC_BAD_CODE;
 	}
 
 	switch (msg->icmph.icmp6_type) {
@@ -1853,7 +1854,7 @@ int ndisc_rcv(struct sk_buff *skb)
 		break;
 	}
 
-	return 0;
+	return reason;
 }
 
 static int ndisc_netdev_event(struct notifier_block *this, unsigned long event, void *ptr)
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
maintainer Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH net-next 4/4] ipv6: icmp6: add drop reason support to ndisc_rcv()

Quoted 8 lines · Eric Dumazet

Creates three new drop reasons:

SKB_DROP_REASON_IPV6_NDISC_FRAG: invalid frag (suppress_frag_ndisc).

SKB_DROP_REASON_IPV6_NDISC_HOP_LIMIT: invalid hop limit.

SKB_DROP_REASON_IPV6_NDISC_BAD_CODE: invalid NDISC icmp6 code.

Quoted 8 lines
---
 include/net/dropreason.h |  9 +++++++++
 include/net/ndisc.h      |  2 +-
 net/ipv6/icmp.c          |  2 +-
 net/ipv6/ndisc.c         | 13 +++++++------
 4 files changed, 18 insertions(+), 8 deletions(-)
#9 lore raw
In reply to Eric Dumazet
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Fri, 10 Feb 2023 18:47:04 +0000 you wrote:

Add more drop reasons to IPv6:

- IPV6_BAD_EXTHDR
- IPV6_NDISC_FRAG
- IPV6_NDISC_HOP_LIMIT
- IPV6_NDISC_BAD_CODE

[...]

Here is the summary with links:
- [net-next,1/4] net: dropreason: add SKB_DROP_REASON_IPV6_BAD_EXTHDR

    https://git.kernel.org/netdev/net-next/c/dc68eaf2c29f
  - [net-next,2/4] net: add pskb_may_pull_reason() helper
    https://git.kernel.org/netdev/net-next/c/1fb2d41501f3
  - [net-next,3/4] ipv6: icmp6: add drop reason support to icmpv6_notify()
    https://git.kernel.org/netdev/net-next/c/30c89bad3ea2
  - [net-next,4/4] ipv6: icmp6: add drop reason support to ndisc_rcv()
    https://git.kernel.org/netdev/net-next/c/545dbcd124b0

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html