AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/01 05:54 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "KMSANReasoning": "",
  "NeedsKMSAN": false,
  "Reasoning": "The patch purely introduces new SKB drop reasons and updates IPv4 and IPv6 GRE and tunnel routines to pass specific drop reasons to kfree_skb_reason() (skb:kfree_skb tracepoint), along with a corresponding net selftest. It makes purely decorative/tracepoint changes without functionally altering execution flow.",
  "WorthFuzzing": false
}

1/1 2026/09/01 05:54 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit e1bd834e091e11b973d471fb96d5062a0a98e557\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 1 05:54:57 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h\nindex 2f312d1f67d69..2a2ac8767d68c 100644\n--- a/include/net/dropreason-core.h\n+++ b/include/net/dropreason-core.h\n@@ -128,6 +128,12 @@\n \tFN(PSP_INPUT)\t\t\t\\\n \tFN(PSP_OUTPUT)\t\t\t\\\n \tFN(RECURSION_LIMIT)\t\t\\\n+\tFN(IP_TUNNEL_CFG_OPTS_MISMATCH)\t\\\n+\tFN(IP_TUNNEL_OLD_SEQ)\t\t\\\n+\tFN(GRE_INVALID_HDR)\t\t\\\n+\tFN(GRE_CSUM)\t\t\t\\\n+\tFN(GRE_TUNNEL_NOT_FOUND)\t\\\n+\tFN(IP_TUNNEL_ENCAP)\t\t\\\n \tFNe(MAX)\n \n /**\n@@ -606,6 +612,38 @@ enum skb_drop_reason {\n \tSKB_DROP_REASON_PSP_OUTPUT,\n \t/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */\n \tSKB_DROP_REASON_RECURSION_LIMIT,\n+\t/**\n+\t * @SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH: the tunnel options\n+\t * carried by the packet do not match the tunnel configuration, e.g.\n+\t * a GRE tunnel configured with 'icsum' or 'iseq' received a packet\n+\t * with no checksum or no sequence number.\n+\t */\n+\tSKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH,\n+\t/**\n+\t * @SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ: the sequence number carried\n+\t * by the packet is older than the one expected by the tunnel, e.g.\n+\t * after the remote endpoint restarted and reset its sequence\n+\t * numbering.\n+\t */\n+\tSKB_DROP_REASON_IP_TUNNEL_OLD_SEQ,\n+\t/**\n+\t * @SKB_DROP_REASON_GRE_INVALID_HDR: the GRE header is invalid, e.g.\n+\t * an unsupported version or the routing bit is set.\n+\t */\n+\tSKB_DROP_REASON_GRE_INVALID_HDR,\n+\t/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */\n+\tSKB_DROP_REASON_GRE_CSUM,\n+\t/**\n+\t * @SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND: no GRE tunnel found for the\n+\t * endpoints and the key the packet carries.\n+\t */\n+\tSKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND,\n+\t/**\n+\t * @SKB_DROP_REASON_IP_TUNNEL_ENCAP: failed to build the\n+\t * encapsulation header of a tunnel, e.g. an unknown or\n+\t * unregistered encapsulation type.\n+\t */\n+\tSKB_DROP_REASON_IP_TUNNEL_ENCAP,\n \t/**\n \t * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which\n \t * shouldn't be used as a real 'reason' - only for tracing code gen\ndiff --git a/include/net/gre.h b/include/net/gre.h\nindex b55f67ecd2fc4..a63f26c3f78ed 100644\n--- a/include/net/gre.h\n+++ b/include/net/gre.h\n@@ -33,7 +33,7 @@ int gre_add_protocol(const struct gre_protocol *proto, u8 version);\n int gre_del_protocol(const struct gre_protocol *proto, u8 version);\n \n int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n-\t\t     bool *csum_err, __be16 proto, int nhs);\n+\t\t     enum skb_drop_reason *reason, __be16 proto, int nhs);\n \n static inline bool netif_is_gretap(const struct net_device *dev)\n {\ndiff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h\nindex b99805ee2fd14..95f6d12254df6 100644\n--- a/include/net/ip6_tunnel.h\n+++ b/include/net/ip6_tunnel.h\n@@ -143,7 +143,8 @@ int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,\n \t\t     const struct in6_addr *raddr);\n int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n-\t\t struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);\n+\t\t struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto,\n+\t\t enum skb_drop_reason *reason);\n __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);\n __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,\n \t\t\t     const struct in6_addr *raddr);\ndiff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c\nindex 96fd7dc6d82dd..598678f42ef5f 100644\n--- a/net/ipv4/gre_demux.c\n+++ b/net/ipv4/gre_demux.c\n@@ -58,26 +58,43 @@ EXPORT_SYMBOL_GPL(gre_del_protocol);\n \n /* Fills in tpi and returns header length to be pulled.\n  * Note that caller must use pskb_may_pull() before pulling GRE header.\n+ *\n+ * @reason is only written when the header is rejected, so the caller has\n+ * to initialise it before the call.\n+ *\n+ * A NULL @reason means that the caller is not interested in the drop\n+ * reason, and also that the checksum must not be verified.  This is what\n+ * the ICMP error handlers need, as they only get a part of the original\n+ * packet.\n  */\n int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n-\t\t     bool *csum_err, __be16 proto, int nhs)\n+\t\t     enum skb_drop_reason *reason, __be16 proto, int nhs)\n {\n \tconst struct gre_base_hdr *greh;\n \t__be32 *options;\n \tint hdr_len;\n \n-\tif (unlikely(!pskb_may_pull(skb, nhs + sizeof(struct gre_base_hdr))))\n+\tif (unlikely(!pskb_may_pull(skb, nhs + sizeof(struct gre_base_hdr)))) {\n+\t\tif (reason)\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\treturn -EINVAL;\n+\t}\n \n \tgreh = (struct gre_base_hdr *)(skb-\u003edata + nhs);\n-\tif (unlikely(greh-\u003eflags \u0026 (GRE_VERSION | GRE_ROUTING)))\n+\tif (unlikely(greh-\u003eflags \u0026 (GRE_VERSION | GRE_ROUTING))) {\n+\t\tif (reason)\n+\t\t\t*reason = SKB_DROP_REASON_GRE_INVALID_HDR;\n \t\treturn -EINVAL;\n+\t}\n \n \tgre_flags_to_tnl_flags(tpi-\u003eflags, greh-\u003eflags);\n \thdr_len = gre_calc_hlen(tpi-\u003eflags);\n \n-\tif (!pskb_may_pull(skb, nhs + hdr_len))\n+\tif (!pskb_may_pull(skb, nhs + hdr_len)) {\n+\t\tif (reason)\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\treturn -EINVAL;\n+\t}\n \n \tgreh = (struct gre_base_hdr *)(skb-\u003edata + nhs);\n \ttpi-\u003eproto = greh-\u003eprotocol;\n@@ -87,8 +104,8 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \t\tif (!skb_checksum_simple_validate(skb)) {\n \t\t\tskb_checksum_try_convert(skb, IPPROTO_GRE,\n \t\t\t\t\t\t null_compute_pseudo);\n-\t\t} else if (csum_err) {\n-\t\t\t*csum_err = true;\n+\t\t} else if (reason) {\n+\t\t\t*reason = SKB_DROP_REASON_GRE_CSUM;\n \t\t\treturn -EINVAL;\n \t\t}\n \n@@ -116,8 +133,11 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \n \t\tval = skb_header_pointer(skb, nhs + hdr_len,\n \t\t\t\t\t sizeof(_val), \u0026_val);\n-\t\tif (!val)\n+\t\tif (!val) {\n+\t\t\tif (reason)\n+\t\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn -EINVAL;\n+\t\t}\n \t\ttpi-\u003eproto = proto;\n \t\tif ((*val \u0026 0xF0) != 0x40)\n \t\t\thdr_len += 4;\n@@ -132,8 +152,11 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \t    greh-\u003eprotocol == htons(ETH_P_ERSPAN2)) {\n \t\tstruct erspan_base_hdr *ershdr;\n \n-\t\tif (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))\n+\t\tif (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr))) {\n+\t\t\tif (reason)\n+\t\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn -EINVAL;\n+\t\t}\n \n \t\tershdr = (struct erspan_base_hdr *)(skb-\u003edata + nhs + hdr_len);\n \t\ttpi-\u003ekey = cpu_to_be32(get_session_id(ershdr));\n@@ -146,15 +169,19 @@ EXPORT_SYMBOL(gre_parse_header);\n static int gre_rcv(struct sk_buff *skb)\n {\n \tconst struct gre_protocol *proto;\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tu8 ver;\n \tint ret;\n \n-\tif (!pskb_may_pull(skb, 12))\n+\treason = pskb_may_pull_reason(skb, 12);\n+\tif (reason)\n \t\tgoto drop;\n \n \tver = skb-\u003edata[1]\u00260x7f;\n-\tif (ver \u003e= GREPROTO_MAX)\n+\tif (ver \u003e= GREPROTO_MAX) {\n+\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\tgoto drop;\n+\t}\n \n \trcu_read_lock();\n \tproto = rcu_dereference(gre_proto[ver]);\n@@ -167,11 +194,11 @@ static int gre_rcv(struct sk_buff *skb)\n drop_nohandler:\n \trcu_read_unlock();\n \tdev_core_stats_rx_nohandler_inc(skb-\u003edev);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, SKB_DROP_REASON_UNHANDLED_PROTO);\n \treturn NET_RX_DROP;\n drop:\n \tdev_core_stats_rx_dropped_inc(skb-\u003edev);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn NET_RX_DROP;\n }\n \ndiff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c\nindex 82309efd417e0..c45e9590c94d5 100644\n--- a/net/ipv4/ip_gre.c\n+++ b/net/ipv4/ip_gre.c\n@@ -265,7 +265,7 @@ static bool is_erspan_type1(int gre_hdr_len)\n }\n \n static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n-\t\t      int gre_hdr_len)\n+\t\t      int gre_hdr_len, enum skb_drop_reason *reason)\n {\n \tstruct net *net = dev_net(skb-\u003edev);\n \tstruct metadata_dst *tun_dst = NULL;\n@@ -289,8 +289,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \t\t\t\t\t  iph-\u003esaddr, iph-\u003edaddr, 0);\n \t} else {\n \t\tif (unlikely(!pskb_may_pull(skb,\n-\t\t\t\t\t    gre_hdr_len + sizeof(*ershdr))))\n+\t\t\t\t\t    gre_hdr_len + sizeof(*ershdr)))) {\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn PACKET_REJECT;\n+\t\t}\n \n \t\tershdr = (struct erspan_base_hdr *)(skb-\u003edata + gre_hdr_len);\n \t\tver = ershdr-\u003ever;\n@@ -306,8 +308,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \t\telse\n \t\t\tlen = gre_hdr_len + erspan_hdr_len(ver);\n \n-\t\tif (unlikely(!pskb_may_pull(skb, len)))\n+\t\tif (unlikely(!pskb_may_pull(skb, len))) {\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn PACKET_REJECT;\n+\t\t}\n \n \t\tif (__iptunnel_pull_header(skb,\n \t\t\t\t\t   len,\n@@ -327,8 +331,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \n \t\t\ttun_dst = ip_tun_rx_dst(skb, flags,\n \t\t\t\t\t\ttun_id, sizeof(*md));\n-\t\t\tif (!tun_dst)\n+\t\t\tif (!tun_dst) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\t\treturn PACKET_REJECT;\n+\t\t\t}\n \n \t\t\t/* MUST set options_len before referencing options */\n \t\t\tinfo = \u0026tun_dst-\u003eu.tun_info;\n@@ -356,15 +362,17 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,\n \t\tip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);\n \t\treturn PACKET_RCVD;\n \t}\n+\t*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;\n \treturn PACKET_REJECT;\n \n drop:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);\n \treturn PACKET_RCVD;\n }\n \n static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,\n-\t\t       struct ip_tunnel_net *itn, int hdr_len, bool raw_proto)\n+\t\t       struct ip_tunnel_net *itn, int hdr_len, bool raw_proto,\n+\t\t       enum skb_drop_reason *reason)\n {\n \tstruct metadata_dst *tun_dst = NULL;\n \tconst struct iphdr *iph;\n@@ -400,22 +408,25 @@ static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,\n \n \t\t\ttun_id = key32_to_tunnel_id(tpi-\u003ekey);\n \t\t\ttun_dst = ip_tun_rx_dst(skb, flags, tun_id, 0);\n-\t\t\tif (!tun_dst)\n+\t\t\tif (!tun_dst) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\t\treturn PACKET_REJECT;\n+\t\t\t}\n \t\t}\n \n \t\tip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);\n \t\treturn PACKET_RCVD;\n \t}\n+\t*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;\n \treturn PACKET_NEXT;\n \n drop:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);\n \treturn PACKET_RCVD;\n }\n \n static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,\n-\t\t     int hdr_len)\n+\t\t     int hdr_len, enum skb_drop_reason *reason)\n {\n \tstruct net *net = dev_net(skb-\u003edev);\n \tstruct ip_tunnel_net *itn;\n@@ -426,21 +437,21 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,\n \telse\n \t\titn = net_generic(net, ipgre_net_id);\n \n-\tres = __ipgre_rcv(skb, tpi, itn, hdr_len, false);\n+\tres = __ipgre_rcv(skb, tpi, itn, hdr_len, false, reason);\n \tif (res == PACKET_NEXT \u0026\u0026 tpi-\u003eproto == htons(ETH_P_TEB)) {\n \t\t/* ipgre tunnels in collect metadata mode should receive\n \t\t * also ETH_P_TEB traffic.\n \t\t */\n \t\titn = net_generic(net, ipgre_net_id);\n-\t\tres = __ipgre_rcv(skb, tpi, itn, hdr_len, true);\n+\t\tres = __ipgre_rcv(skb, tpi, itn, hdr_len, true, reason);\n \t}\n \treturn res;\n }\n \n static int gre_rcv(struct sk_buff *skb)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct tnl_ptk_info tpi;\n-\tbool csum_err = false;\n \tint hdr_len;\n \n #ifdef CONFIG_NET_IPGRE_BROADCAST\n@@ -451,25 +462,25 @@ static int gre_rcv(struct sk_buff *skb)\n \t}\n #endif\n \n-\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026csum_err, htons(ETH_P_IP), 0);\n+\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026reason, htons(ETH_P_IP), 0);\n \tif (hdr_len \u003c 0)\n \t\tgoto drop;\n \n \tif (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||\n \t\t     tpi.proto == htons(ETH_P_ERSPAN2))) {\n-\t\tif (erspan_rcv(skb, \u0026tpi, hdr_len) == PACKET_RCVD)\n+\t\tif (erspan_rcv(skb, \u0026tpi, hdr_len, \u0026reason) == PACKET_RCVD)\n \t\t\treturn 0;\n \t\tgoto out;\n \t}\n \n-\tif (ipgre_rcv(skb, \u0026tpi, hdr_len) == PACKET_RCVD)\n+\tif (ipgre_rcv(skb, \u0026tpi, hdr_len, \u0026reason) == PACKET_RCVD)\n \t\treturn 0;\n \n out:\n \ticmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);\n drop:\n \tdev_core_stats_rx_dropped_inc(skb-\u003edev);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn 0;\n }\n \n@@ -500,23 +511,30 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,\n \tIP_TUNNEL_DECLARE_FLAGS(flags) = { };\n \tstruct ip_tunnel_info *tun_info;\n \tconst struct ip_tunnel_key *key;\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tint tunnel_hlen;\n \n \ttun_info = skb_tunnel_info(skb);\n \tif (unlikely(!tun_info || !(tun_info-\u003emode \u0026 IP_TUNNEL_INFO_TX) ||\n-\t\t     ip_tunnel_info_af(tun_info) != AF_INET))\n+\t\t     ip_tunnel_info_af(tun_info) != AF_INET)) {\n+\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\tgoto err_free_skb;\n+\t}\n \n \tkey = \u0026tun_info-\u003ekey;\n \ttunnel_hlen = gre_calc_hlen(key-\u003etun_flags);\n \n-\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\n+\tif (skb_cow_head(skb, dev-\u003eneeded_headroom)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto err_free_skb;\n+\t}\n \n \t/* Push Tunnel header. */\n \tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,\n-\t\t\t\t\t      tunnel-\u003eparms.o_flags)))\n+\t\t\t\t\t      tunnel-\u003eparms.o_flags))) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto err_free_skb;\n+\t}\n \n \t__set_bit(IP_TUNNEL_CSUM_BIT, flags);\n \t__set_bit(IP_TUNNEL_KEY_BIT, flags);\n@@ -533,7 +551,7 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,\n \treturn;\n \n err_free_skb:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \tDEV_STATS_INC(dev, tx_dropped);\n }\n \n@@ -543,6 +561,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)\n \tIP_TUNNEL_DECLARE_FLAGS(flags) = { };\n \tstruct ip_tunnel_info *tun_info;\n \tconst struct ip_tunnel_key *key;\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct erspan_metadata *md;\n \tbool truncate = false;\n \t__be16 proto;\n@@ -552,29 +571,41 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)\n \n \ttun_info = skb_tunnel_info(skb);\n \tif (unlikely(!tun_info || !(tun_info-\u003emode \u0026 IP_TUNNEL_INFO_TX) ||\n-\t\t     ip_tunnel_info_af(tun_info) != AF_INET))\n+\t\t     ip_tunnel_info_af(tun_info) != AF_INET)) {\n+\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\tgoto err_free_skb;\n+\t}\n \n \tkey = \u0026tun_info-\u003ekey;\n-\tif (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT, tun_info-\u003ekey.tun_flags))\n+\tif (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT, tun_info-\u003ekey.tun_flags)) {\n+\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\tgoto err_free_skb;\n-\tif (tun_info-\u003eoptions_len \u003c sizeof(*md))\n+\t}\n+\tif (tun_info-\u003eoptions_len \u003c sizeof(*md)) {\n+\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\tgoto err_free_skb;\n+\t}\n \tmd = ip_tunnel_info_opts(tun_info);\n \n \t/* ERSPAN has fixed 8 byte GRE header */\n \tversion = md-\u003eversion;\n \ttunnel_hlen = 8 + erspan_hdr_len(version);\n \n-\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\n+\tif (skb_cow_head(skb, dev-\u003eneeded_headroom)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto err_free_skb;\n+\t}\n \n-\tif (gre_handle_offloads(skb, false))\n+\tif (gre_handle_offloads(skb, false)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto err_free_skb;\n+\t}\n \n \tif (skb-\u003elen \u003e dev-\u003emtu + dev-\u003ehard_header_len) {\n-\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len))\n+\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len)) {\n+\t\t\treason = SKB_DROP_REASON_NOMEM;\n \t\t\tgoto err_free_skb;\n+\t\t}\n \t\ttruncate = true;\n \t}\n \n@@ -606,6 +637,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)\n \t\t\t\t       truncate, true);\n \t\tproto = htons(ETH_P_ERSPAN2);\n \t} else {\n+\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\tgoto err_free_skb;\n \t}\n \n@@ -618,7 +650,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)\n \treturn;\n \n err_free_skb:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \tDEV_STATS_INC(dev, tx_dropped);\n }\n \n@@ -652,8 +684,10 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\n \tIP_TUNNEL_DECLARE_FLAGS(flags);\n \tconst struct iphdr *tnl_params;\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto free_skb;\n \n \tif (tunnel-\u003ecollect_md) {\n@@ -664,10 +698,13 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,\n \tif (dev-\u003eheader_ops) {\n \t\tint pull_len = tunnel-\u003ehlen + sizeof(struct iphdr);\n \n-\t\tif (skb_cow_head(skb, 0))\n+\t\tif (skb_cow_head(skb, 0)) {\n+\t\t\treason = SKB_DROP_REASON_NOMEM;\n \t\t\tgoto free_skb;\n+\t\t}\n \n-\t\tif (!pskb_may_pull(skb, pull_len))\n+\t\treason = pskb_may_pull_reason(skb, pull_len);\n+\t\tif (reason)\n \t\t\tgoto free_skb;\n \n \t\ttnl_params = (const struct iphdr *)skb-\u003edata;\n@@ -677,25 +714,31 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,\n \t\tskb_reset_mac_header(skb);\n \n \t\tif (skb-\u003eip_summed == CHECKSUM_PARTIAL \u0026\u0026\n-\t\t    skb_checksum_start(skb) \u003c skb-\u003edata)\n+\t\t    skb_checksum_start(skb) \u003c skb-\u003edata) {\n+\t\t\treason = SKB_DROP_REASON_SKB_CSUM;\n \t\t\tgoto free_skb;\n+\t\t}\n \t} else {\n-\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\n+\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom)) {\n+\t\t\treason = SKB_DROP_REASON_NOMEM;\n \t\t\tgoto free_skb;\n+\t\t}\n \n \t\ttnl_params = \u0026tunnel-\u003eparms.iph;\n \t}\n \n \tip_tunnel_flags_copy(flags, tunnel-\u003eparms.o_flags);\n \n-\tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags)))\n+\tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags))) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto free_skb;\n+\t}\n \n \t__gre_xmit(skb, dev, tnl_params, skb-\u003eprotocol, flags);\n \treturn NETDEV_TX_OK;\n \n free_skb:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \tDEV_STATS_INC(dev, tx_dropped);\n \treturn NETDEV_TX_OK;\n }\n@@ -705,10 +748,12 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,\n {\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\n \tIP_TUNNEL_DECLARE_FLAGS(flags);\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tbool truncate = false;\n \t__be16 proto;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto free_skb;\n \n \tif (tunnel-\u003ecollect_md) {\n@@ -716,15 +761,21 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,\n \t\treturn NETDEV_TX_OK;\n \t}\n \n-\tif (gre_handle_offloads(skb, false))\n+\tif (gre_handle_offloads(skb, false)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto free_skb;\n+\t}\n \n-\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\n+\tif (skb_cow_head(skb, dev-\u003eneeded_headroom)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto free_skb;\n+\t}\n \n \tif (skb-\u003elen \u003e dev-\u003emtu + dev-\u003ehard_header_len) {\n-\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len))\n+\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len)) {\n+\t\t\treason = SKB_DROP_REASON_NOMEM;\n \t\t\tgoto free_skb;\n+\t\t}\n \t\ttruncate = true;\n \t}\n \n@@ -745,6 +796,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,\n \t\t\t\t       truncate, true);\n \t\tproto = htons(ETH_P_ERSPAN2);\n \t} else {\n+\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\tgoto free_skb;\n \t}\n \n@@ -753,7 +805,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,\n \treturn NETDEV_TX_OK;\n \n free_skb:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \tDEV_STATS_INC(dev, tx_dropped);\n \treturn NETDEV_TX_OK;\n }\n@@ -763,8 +815,10 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,\n {\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\n \tIP_TUNNEL_DECLARE_FLAGS(flags);\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto free_skb;\n \n \tif (tunnel-\u003ecollect_md) {\n@@ -774,17 +828,21 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,\n \n \tip_tunnel_flags_copy(flags, tunnel-\u003eparms.o_flags);\n \n-\tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags)))\n+\tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags))) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto free_skb;\n+\t}\n \n-\tif (skb_cow_head(skb, dev-\u003eneeded_headroom))\n+\tif (skb_cow_head(skb, dev-\u003eneeded_headroom)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto free_skb;\n+\t}\n \n \t__gre_xmit(skb, dev, \u0026tunnel-\u003eparms.iph, htons(ETH_P_TEB), flags);\n \treturn NETDEV_TX_OK;\n \n free_skb:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \tDEV_STATS_INC(dev, tx_dropped);\n \treturn NETDEV_TX_OK;\n }\ndiff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c\nindex e6bcf01411d0b..12d45f69c4d82 100644\n--- a/net/ipv4/ip_tunnel.c\n+++ b/net/ipv4/ip_tunnel.c\n@@ -379,6 +379,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,\n \t\t  bool log_ecn_error)\n {\n \tconst struct iphdr *iph = ip_hdr(skb);\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tint nh, err;\n \n #ifdef CONFIG_NET_IPGRE_BROADCAST\n@@ -392,14 +393,22 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,\n \t    test_bit(IP_TUNNEL_CSUM_BIT, tpi-\u003eflags)) {\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_crc_errors);\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\treason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;\n \t\tgoto drop;\n \t}\n \n \tif (test_bit(IP_TUNNEL_SEQ_BIT, tunnel-\u003eparms.i_flags)) {\n-\t\tif (!test_bit(IP_TUNNEL_SEQ_BIT, tpi-\u003eflags) ||\n-\t\t    (tunnel-\u003ei_seqno \u0026\u0026 (s32)(ntohl(tpi-\u003eseq) - tunnel-\u003ei_seqno) \u003c 0)) {\n+\t\tif (!test_bit(IP_TUNNEL_SEQ_BIT, tpi-\u003eflags)) {\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_fifo_errors);\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;\n+\t\t\tgoto drop;\n+\t\t}\n+\t\tif (tunnel-\u003ei_seqno \u0026\u0026\n+\t\t    (s32)(ntohl(tpi-\u003eseq) - tunnel-\u003ei_seqno) \u003c 0) {\n+\t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_fifo_errors);\n+\t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ;\n \t\t\tgoto drop;\n \t\t}\n \t\ttunnel-\u003ei_seqno = ntohl(tpi-\u003eseq) + 1;\n@@ -413,7 +422,8 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,\n \n \tskb_set_network_header(skb, (tunnel-\u003edev-\u003etype == ARPHRD_ETHER) ? ETH_HLEN : 0);\n \n-\tif (!pskb_inet_may_pull(skb)) {\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason) {\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_length_errors);\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n \t\tgoto drop;\n@@ -428,6 +438,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,\n \t\tif (err \u003e 1) {\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_frame_errors);\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_ECN;\n \t\t\tgoto drop;\n \t\t}\n \t}\n@@ -451,7 +462,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,\n drop:\n \tif (tun_dst)\n \t\tdst_release((struct dst_entry *)tun_dst);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn 0;\n }\n EXPORT_SYMBOL_GPL(ip_tunnel_rcv);\n@@ -571,6 +582,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,\n void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t       u8 proto, int tunnel_hlen)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\n \tu32 headroom = sizeof(struct iphdr);\n \tstruct ip_tunnel_info *tun_info;\n@@ -584,8 +596,10 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \ttun_info = skb_tunnel_info(skb);\n \tif (unlikely(!tun_info || !(tun_info-\u003emode \u0026 IP_TUNNEL_INFO_TX) ||\n-\t\t     ip_tunnel_info_af(tun_info) != AF_INET))\n+\t\t     ip_tunnel_info_af(tun_info) != AF_INET)) {\n+\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\tgoto tx_error;\n+\t}\n \tkey = \u0026tun_info-\u003ekey;\n \tmemset(\u0026(IPCB(skb)-\u003eopt), 0, sizeof(IPCB(skb)-\u003eopt));\n \tinner_iph = (const struct iphdr *)skb_inner_network_header(skb);\n@@ -604,8 +618,10 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \tif (!tunnel_hlen)\n \t\ttunnel_hlen = ip_encap_hlen(\u0026tun_info-\u003eencap);\n \n-\tif (ip_tunnel_encap(skb, \u0026tun_info-\u003eencap, \u0026proto, \u0026fl4) \u003c 0)\n+\tif (ip_tunnel_encap(skb, \u0026tun_info-\u003eencap, \u0026proto, \u0026fl4) \u003c 0) {\n+\t\treason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;\n \t\tgoto tx_error;\n+\t}\n \n \tuse_cache = ip_tunnel_dst_cache_usable(skb, tun_info);\n \tif (use_cache)\n@@ -614,6 +630,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\trt = ip_route_output_key(tunnel-\u003enet, \u0026fl4);\n \t\tif (IS_ERR(rt)) {\n \t\t\tDEV_STATS_INC(dev, tx_carrier_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_OUTNOROUTES;\n \t\t\tgoto tx_error;\n \t\t}\n \t\tif (use_cache)\n@@ -623,6 +640,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \tif (rt-\u003edst.dev == dev) {\n \t\tip_rt_put(rt);\n \t\tDEV_STATS_INC(dev, collisions);\n+\t\treason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\tgoto tx_error;\n \t}\n \n@@ -631,6 +649,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \tif (tnl_update_pmtu(dev, skb, rt, df, inner_iph, tunnel_hlen,\n \t\t\t    key-\u003eu.ipv4.dst, true)) {\n \t\tip_rt_put(rt);\n+\t\treason = SKB_DROP_REASON_PKT_TOO_BIG;\n \t\tgoto tx_error;\n \t}\n \n@@ -648,6 +667,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \theadroom += LL_RESERVED_SPACE(rt-\u003edst.dev) + rt-\u003edst.header_len;\n \tif (skb_cow_head(skb, headroom)) {\n \t\tip_rt_put(rt);\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto tx_dropped;\n \t}\n \n@@ -662,13 +682,14 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n tx_dropped:\n \tDEV_STATS_INC(dev, tx_dropped);\n kfree:\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n }\n EXPORT_SYMBOL_GPL(ip_md_tunnel_xmit);\n \n void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t    const struct iphdr *tnl_params, u8 protocol)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct ip_tunnel *tunnel = netdev_priv(dev);\n \tstruct ip_tunnel_info *tun_info = NULL;\n \tconst struct iphdr *inner_iph;\n@@ -696,9 +717,15 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \t\tif (!skb_dst(skb)) {\n \t\t\tDEV_STATS_INC(dev, tx_fifo_errors);\n+\t\t\treason = SKB_DROP_REASON_NO_TX_TARGET;\n \t\t\tgoto tx_error;\n \t\t}\n \n+\t\t/* Only the branches below can derive a destination.  If\n+\t\t * none of them matches, the payload protocol is not one\n+\t\t * this tunnel can carry.\n+\t\t */\n+\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\ttun_info = skb_tunnel_info(skb);\n \t\tif (tun_info \u0026\u0026 (tun_info-\u003emode \u0026 IP_TUNNEL_INFO_TX) \u0026\u0026\n \t\t    ip_tunnel_info_af(tun_info) == AF_INET \u0026\u0026\n@@ -719,8 +746,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \t\t\tneigh = dst_neigh_lookup(skb_dst(skb),\n \t\t\t\t\t\t \u0026ipv6_hdr(skb)-\u003edaddr);\n-\t\t\tif (!neigh)\n+\t\t\tif (!neigh) {\n+\t\t\t\treason = SKB_DROP_REASON_NEIGH_CREATEFAIL;\n \t\t\t\tgoto tx_error;\n+\t\t\t}\n \n \t\t\taddr6 = (const struct in6_addr *)\u0026neigh-\u003eprimary_key;\n \t\t\taddr_type = ipv6_addr_type(addr6);\n@@ -737,8 +766,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t\t\tdst = addr6-\u003es6_addr32[3];\n \t\t\t}\n \t\t\tneigh_release(neigh);\n-\t\t\tif (do_tx_error_icmp)\n+\t\t\tif (do_tx_error_icmp) {\n+\t\t\t\treason = SKB_DROP_REASON_NO_TX_TARGET;\n \t\t\t\tgoto tx_error_icmp;\n+\t\t\t}\n \t\t}\n #endif\n \t\telse\n@@ -765,8 +796,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t\t    tunnel-\u003enet, READ_ONCE(tunnel-\u003eparms.link),\n \t\t\t    tunnel-\u003efwmark, skb_get_hash(skb), 0);\n \n-\tif (ip_tunnel_encap(skb, \u0026tunnel-\u003eencap, \u0026protocol, \u0026fl4) \u003c 0)\n+\tif (ip_tunnel_encap(skb, \u0026tunnel-\u003eencap, \u0026protocol, \u0026fl4) \u003c 0) {\n+\t\treason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;\n \t\tgoto tx_error;\n+\t}\n \n \tif (connected \u0026\u0026 md) {\n \t\tuse_cache = ip_tunnel_dst_cache_usable(skb, tun_info);\n@@ -783,6 +816,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \t\tif (IS_ERR(rt)) {\n \t\t\tDEV_STATS_INC(dev, tx_carrier_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_OUTNOROUTES;\n \t\t\tgoto tx_error;\n \t\t}\n \t\tif (use_cache)\n@@ -796,6 +830,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \tif (rt-\u003edst.dev == dev) {\n \t\tip_rt_put(rt);\n \t\tDEV_STATS_INC(dev, collisions);\n+\t\treason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\tgoto tx_error;\n \t}\n \n@@ -805,6 +840,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \tif (tnl_update_pmtu(dev, skb, rt, df, inner_iph, 0, 0, false)) {\n \t\tip_rt_put(rt);\n+\t\treason = SKB_DROP_REASON_PKT_TOO_BIG;\n \t\tgoto tx_error;\n \t}\n \n@@ -839,7 +875,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n \tif (skb_cow_head(skb, max_headroom)) {\n \t\tip_rt_put(rt);\n \t\tDEV_STATS_INC(dev, tx_dropped);\n-\t\tkfree_skb(skb);\n+\t\tkfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);\n \t\treturn;\n \t}\n \n@@ -855,7 +891,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,\n #endif\n tx_error:\n \tDEV_STATS_INC(dev, tx_errors);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n }\n EXPORT_SYMBOL_GPL(ip_tunnel_xmit);\n \ndiff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c\nindex 69c51f1a5bf08..42a0336407163 100644\n--- a/net/ipv6/ip6_gre.c\n+++ b/net/ipv6/ip6_gre.c\n@@ -454,7 +454,8 @@ static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,\n \treturn 0;\n }\n \n-static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)\n+static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,\n+\t\t      enum skb_drop_reason *reason)\n {\n \tconst struct ipv6hdr *ipv6h;\n \tstruct ip6_tnl *tunnel;\n@@ -473,8 +474,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)\n \t\t\ttun_id = key32_to_tunnel_id(tpi-\u003ekey);\n \n \t\t\ttun_dst = ipv6_tun_rx_dst(skb, flags, tun_id, 0);\n-\t\t\tif (!tun_dst)\n+\t\t\tif (!tun_dst) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\t\treturn PACKET_REJECT;\n+\t\t\t}\n \n \t\t\tip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);\n \t\t} else {\n@@ -484,12 +487,14 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)\n \t\treturn PACKET_RCVD;\n \t}\n \n+\t*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;\n \treturn PACKET_REJECT;\n }\n \n static int ip6erspan_rcv(struct sk_buff *skb,\n \t\t\t struct tnl_ptk_info *tpi,\n-\t\t\t int gre_hdr_len)\n+\t\t\t int gre_hdr_len,\n+\t\t\t enum skb_drop_reason *reason)\n {\n \tstruct erspan_base_hdr *ershdr;\n \tconst struct ipv6hdr *ipv6h;\n@@ -497,8 +502,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,\n \tstruct ip6_tnl *tunnel;\n \tu8 ver;\n \n-\tif (unlikely(!pskb_may_pull(skb, sizeof(*ershdr))))\n+\tif (unlikely(!pskb_may_pull(skb, sizeof(*ershdr)))) {\n+\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\treturn PACKET_REJECT;\n+\t}\n \n \tipv6h = ipv6_hdr(skb);\n \tershdr = (struct erspan_base_hdr *)skb-\u003edata;\n@@ -510,13 +517,17 @@ static int ip6erspan_rcv(struct sk_buff *skb,\n \tif (tunnel) {\n \t\tint len = erspan_hdr_len(ver);\n \n-\t\tif (unlikely(!pskb_may_pull(skb, len)))\n+\t\tif (unlikely(!pskb_may_pull(skb, len))) {\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn PACKET_REJECT;\n+\t\t}\n \n \t\tif (__iptunnel_pull_header(skb, len,\n \t\t\t\t\t   htons(ETH_P_TEB),\n-\t\t\t\t\t   false, false) \u003c 0)\n+\t\t\t\t\t   false, false) \u003c 0) {\n+\t\t\t*reason = SKB_DROP_REASON_HDR_TRUNC;\n \t\t\treturn PACKET_REJECT;\n+\t\t}\n \n \t\tif (tunnel-\u003eparms.collect_md) {\n \t\t\tstruct erspan_metadata *pkt_md, *md;\n@@ -532,8 +543,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,\n \n \t\t\ttun_dst = ipv6_tun_rx_dst(skb, flags, tun_id,\n \t\t\t\t\t\t  sizeof(*md));\n-\t\t\tif (!tun_dst)\n+\t\t\tif (!tun_dst) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\t\treturn PACKET_REJECT;\n+\t\t\t}\n \n \t\t\t/* MUST set options_len before referencing options */\n \t\t\tinfo = \u0026tun_dst-\u003eu.tun_info;\n@@ -564,37 +577,40 @@ static int ip6erspan_rcv(struct sk_buff *skb,\n \t\treturn PACKET_RCVD;\n \t}\n \n+\t*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;\n \treturn PACKET_REJECT;\n }\n \n static int gre_rcv(struct sk_buff *skb)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct tnl_ptk_info tpi;\n-\tbool csum_err = false;\n \tint hdr_len;\n \n-\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026csum_err, htons(ETH_P_IPV6), 0);\n+\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026reason, htons(ETH_P_IPV6), 0);\n \tif (hdr_len \u003c 0)\n \t\tgoto drop;\n \n-\tif (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))\n+\tif (iptunnel_pull_header(skb, hdr_len, tpi.proto, false)) {\n+\t\treason = SKB_DROP_REASON_HDR_TRUNC;\n \t\tgoto drop;\n+\t}\n \n \tif (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||\n \t\t     tpi.proto == htons(ETH_P_ERSPAN2))) {\n-\t\tif (ip6erspan_rcv(skb, \u0026tpi, hdr_len) == PACKET_RCVD)\n+\t\tif (ip6erspan_rcv(skb, \u0026tpi, hdr_len, \u0026reason) == PACKET_RCVD)\n \t\t\treturn 0;\n \t\tgoto out;\n \t}\n \n-\tif (ip6gre_rcv(skb, \u0026tpi) == PACKET_RCVD)\n+\tif (ip6gre_rcv(skb, \u0026tpi, \u0026reason) == PACKET_RCVD)\n \t\treturn 0;\n \n out:\n \ticmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);\n drop:\n \tdev_core_stats_rx_dropped_inc(skb-\u003edev);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn 0;\n }\n \n@@ -718,7 +734,8 @@ static struct ip_tunnel_info *skb_tunnel_info_txcheck(struct sk_buff *skb)\n static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n \t\t\t       struct net_device *dev, __u8 dsfield,\n \t\t\t       struct flowi6 *fl6, int encap_limit,\n-\t\t\t       __u32 *pmtu, __be16 proto)\n+\t\t\t       __u32 *pmtu, __be16 proto,\n+\t\t\t       enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *tunnel = netdev_priv(dev);\n \tIP_TUNNEL_DECLARE_FLAGS(flags);\n@@ -742,8 +759,10 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n \n \t\ttun_info = skb_tunnel_info_txcheck(skb);\n \t\tif (IS_ERR(tun_info) ||\n-\t\t    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))\n+\t\t    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6)) {\n+\t\t\t*reason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\t\treturn -EINVAL;\n+\t\t}\n \n \t\tkey = \u0026tun_info-\u003ekey;\n \t\tmemset(fl6, 0, sizeof(*fl6));\n@@ -761,8 +780,11 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n \t\tip_tunnel_flags_and(flags, flags, key-\u003etun_flags);\n \t\ttun_hlen = gre_calc_hlen(flags);\n \n-\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: tun_hlen + tunnel-\u003eencap_hlen))\n+\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?:\n+\t\t\t\t tun_hlen + tunnel-\u003eencap_hlen)) {\n+\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\treturn -ENOMEM;\n+\t\t}\n \n \t\tgre_build_header(skb, tun_hlen,\n \t\t\t\t flags, protocol,\n@@ -772,8 +794,10 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n \t\t\t\t 0);\n \n \t} else {\n-\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: tunnel-\u003ehlen))\n+\t\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: tunnel-\u003ehlen)) {\n+\t\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\t\treturn -ENOMEM;\n+\t\t}\n \n \t\tip_tunnel_flags_copy(flags, tunnel-\u003eparms.o_flags);\n \n@@ -785,10 +809,11 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n \t}\n \n \treturn ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,\n-\t\t\t    NEXTHDR_GRE);\n+\t\t\t    NEXTHDR_GRE, reason);\n }\n \n-static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)\n+static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev,\n+\t\t\t\t   enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tint encap_limit = -1;\n@@ -805,11 +830,13 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)\n \n \terr = gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,\n \t\t\t\t\t\tt-\u003eparms.o_flags));\n-\tif (err)\n+\tif (err) {\n+\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\treturn -1;\n+\t}\n \n \terr = __gre6_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\n-\t\t\t  skb-\u003eprotocol);\n+\t\t\t  skb-\u003eprotocol, reason);\n \tif (err != 0) {\n \t\t/* XXX: send ICMP error even if DF is not set. */\n \t\tif (err == -EMSGSIZE)\n@@ -821,7 +848,8 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)\n \treturn 0;\n }\n \n-static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)\n+static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev,\n+\t\t\t\t   enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tstruct ipv6hdr *ipv6h = ipv6_hdr(skb);\n@@ -831,19 +859,25 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)\n \t__u32 mtu;\n \tint err;\n \n-\tif (ipv6_addr_equal(\u0026t-\u003eparms.raddr, \u0026ipv6h-\u003esaddr))\n+\tif (ipv6_addr_equal(\u0026t-\u003eparms.raddr, \u0026ipv6h-\u003esaddr)) {\n+\t\t*reason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\treturn -1;\n+\t}\n \n \tif (!t-\u003eparms.collect_md \u0026\u0026\n-\t    prepare_ip6gre_xmit_ipv6(skb, dev, \u0026fl6, \u0026dsfield, \u0026encap_limit))\n+\t    prepare_ip6gre_xmit_ipv6(skb, dev, \u0026fl6, \u0026dsfield, \u0026encap_limit)) {\n+\t\t*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;\n \t\treturn -1;\n+\t}\n \n \tif (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,\n-\t\t\t\t\t      t-\u003eparms.o_flags)))\n+\t\t\t\t\t      t-\u003eparms.o_flags))) {\n+\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\treturn -1;\n+\t}\n \n \terr = __gre6_xmit(skb, dev, dsfield, \u0026fl6, encap_limit,\n-\t\t\t  \u0026mtu, skb-\u003eprotocol);\n+\t\t\t  \u0026mtu, skb-\u003eprotocol, reason);\n \tif (err != 0) {\n \t\tif (err == -EMSGSIZE)\n \t\t\ticmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);\n@@ -853,7 +887,8 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)\n \treturn 0;\n }\n \n-static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)\n+static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev,\n+\t\t\t     enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tint encap_limit = -1;\n@@ -863,14 +898,19 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)\n \tint err;\n \n \tif (!t-\u003eparms.collect_md \u0026\u0026\n-\t    prepare_ip6gre_xmit_other(skb, dev, \u0026fl6, \u0026dsfield, \u0026encap_limit))\n+\t    prepare_ip6gre_xmit_other(skb, dev, \u0026fl6, \u0026dsfield, \u0026encap_limit)) {\n+\t\t*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;\n \t\treturn -1;\n+\t}\n \n \terr = gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,\n \t\t\t\t\t\tt-\u003eparms.o_flags));\n-\tif (err)\n+\tif (err) {\n+\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\treturn err;\n-\terr = __gre6_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu, skb-\u003eprotocol);\n+\t}\n+\terr = __gre6_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\n+\t\t\t  skb-\u003eprotocol, reason);\n \n \treturn err;\n }\n@@ -878,26 +918,30 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)\n static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,\n \tstruct net_device *dev)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \t__be16 payload_protocol;\n \tint ret;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto tx_err;\n \n-\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr))\n+\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr)) {\n+\t\treason = SKB_DROP_REASON_DEV_READY;\n \t\tgoto tx_err;\n+\t}\n \n \tpayload_protocol = skb_protocol(skb, true);\n \tswitch (payload_protocol) {\n \tcase htons(ETH_P_IP):\n-\t\tret = ip6gre_xmit_ipv4(skb, dev);\n+\t\tret = ip6gre_xmit_ipv4(skb, dev, \u0026reason);\n \t\tbreak;\n \tcase htons(ETH_P_IPV6):\n-\t\tret = ip6gre_xmit_ipv6(skb, dev);\n+\t\tret = ip6gre_xmit_ipv6(skb, dev, \u0026reason);\n \t\tbreak;\n \tdefault:\n-\t\tret = ip6gre_xmit_other(skb, dev);\n+\t\tret = ip6gre_xmit_other(skb, dev, \u0026reason);\n \t\tbreak;\n \t}\n \n@@ -910,7 +954,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,\n \tif (!t-\u003eparms.collect_md || !IS_ERR(skb_tunnel_info_txcheck(skb)))\n \t\tDEV_STATS_INC(dev, tx_errors);\n \tDEV_STATS_INC(dev, tx_dropped);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn NETDEV_TX_OK;\n }\n \n@@ -921,6 +965,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tstruct dst_entry *dst = skb_dst(skb);\n \tIP_TUNNEL_DECLARE_FLAGS(flags) = { };\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tbool truncate = false;\n \tint encap_limit = -1;\n \t__u8 dsfield = false;\n@@ -930,18 +975,25 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t__u32 mtu;\n \tint nhoff;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto tx_err;\n \n-\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr))\n+\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr)) {\n+\t\treason = SKB_DROP_REASON_DEV_READY;\n \t\tgoto tx_err;\n+\t}\n \n-\tif (gre_handle_offloads(skb, false))\n+\tif (gre_handle_offloads(skb, false)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto tx_err;\n+\t}\n \n \tif (skb-\u003elen \u003e dev-\u003emtu + dev-\u003ehard_header_len) {\n-\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len))\n+\t\tif (pskb_trim(skb, dev-\u003emtu + dev-\u003ehard_header_len)) {\n+\t\t\treason = SKB_DROP_REASON_NOMEM;\n \t\t\tgoto tx_err;\n+\t\t}\n \t\ttruncate = true;\n \t}\n \n@@ -961,8 +1013,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t\t\ttruncate = true;\n \t}\n \n-\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: t-\u003ehlen))\n+\tif (skb_cow_head(skb, dev-\u003eneeded_headroom ?: t-\u003ehlen)) {\n+\t\treason = SKB_DROP_REASON_NOMEM;\n \t\tgoto tx_err;\n+\t}\n \n \tIPCB(skb)-\u003eflags = 0;\n \n@@ -976,8 +1030,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \n \t\ttun_info = skb_tunnel_info_txcheck(skb);\n \t\tif (IS_ERR(tun_info) ||\n-\t\t    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))\n+\t\t    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6)) {\n+\t\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\t\tgoto tx_err;\n+\t\t}\n \n \t\tkey = \u0026tun_info-\u003ekey;\n \t\tmemset(\u0026fl6, 0, sizeof(fl6));\n@@ -989,10 +1045,14 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \n \t\tdsfield = key-\u003etos;\n \t\tif (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT,\n-\t\t\t      tun_info-\u003ekey.tun_flags))\n+\t\t\t      tun_info-\u003ekey.tun_flags)) {\n+\t\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\t\tgoto tx_err;\n-\t\tif (tun_info-\u003eoptions_len \u003c sizeof(*md))\n+\t\t}\n+\t\tif (tun_info-\u003eoptions_len \u003c sizeof(*md)) {\n+\t\t\treason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\t\tgoto tx_err;\n+\t\t}\n \t\tmd = ip_tunnel_info_opts(tun_info);\n \n \t\ttun_id = tunnel_id_to_key32(key-\u003etun_id);\n@@ -1010,6 +1070,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t\t\t\t\t       truncate, false);\n \t\t\tproto = htons(ETH_P_ERSPAN2);\n \t\t} else {\n+\t\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\t\tgoto tx_err;\n \t\t}\n \t} else {\n@@ -1020,11 +1081,16 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t\t\t\t\t\t \u0026dsfield, \u0026encap_limit);\n \t\t\tbreak;\n \t\tcase htons(ETH_P_IPV6):\n-\t\t\tif (ipv6_addr_equal(\u0026t-\u003eparms.raddr, \u0026ipv6_hdr(skb)-\u003esaddr))\n+\t\t\tif (ipv6_addr_equal(\u0026t-\u003eparms.raddr,\n+\t\t\t\t\t    \u0026ipv6_hdr(skb)-\u003esaddr)) {\n+\t\t\t\treason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\t\t\tgoto tx_err;\n+\t\t\t}\n \t\t\tif (prepare_ip6gre_xmit_ipv6(skb, dev, \u0026fl6,\n-\t\t\t\t\t\t     \u0026dsfield, \u0026encap_limit))\n+\t\t\t\t\t\t     \u0026dsfield, \u0026encap_limit)) {\n+\t\t\t\treason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;\n \t\t\t\tgoto tx_err;\n+\t\t\t}\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tmemcpy(\u0026fl6, \u0026t-\u003efl.u.ip6, sizeof(fl6));\n@@ -1043,6 +1109,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t\t\t\t\t       truncate, false);\n \t\t\tproto = htons(ETH_P_ERSPAN2);\n \t\t} else {\n+\t\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\t\tgoto tx_err;\n \t\t}\n \n@@ -1061,7 +1128,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \t\t\tdst-\u003eops-\u003eupdate_pmtu(dst, NULL, skb, mtu, false);\n \t}\n \terr = ip6_tnl_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\n-\t\t\t   NEXTHDR_GRE);\n+\t\t\t   NEXTHDR_GRE, \u0026reason);\n \tif (err != 0) {\n \t\t/* XXX: send ICMP error even if DF is not set. */\n \t\tif (err == -EMSGSIZE) {\n@@ -1080,7 +1147,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n \tif (!IS_ERR(tun_info))\n \t\tDEV_STATS_INC(dev, tx_errors);\n \tDEV_STATS_INC(dev, tx_dropped);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn NETDEV_TX_OK;\n }\n \ndiff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c\nindex d5ff50a2ac017..ab45601b2a68e 100644\n--- a/net/ipv6/ip6_tunnel.c\n+++ b/net/ipv6/ip6_tunnel.c\n@@ -814,21 +814,29 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n \t\t\t bool log_ecn_err)\n {\n \tconst struct ipv6hdr *ipv6h;\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tint nh, err;\n \n \tif (test_bit(IP_TUNNEL_CSUM_BIT, tunnel-\u003eparms.i_flags) !=\n \t    test_bit(IP_TUNNEL_CSUM_BIT, tpi-\u003eflags)) {\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_crc_errors);\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\treason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;\n \t\tgoto drop;\n \t}\n \n \tif (test_bit(IP_TUNNEL_SEQ_BIT, tunnel-\u003eparms.i_flags)) {\n-\t\tif (!test_bit(IP_TUNNEL_SEQ_BIT, tpi-\u003eflags) ||\n-\t\t    (tunnel-\u003ei_seqno \u0026\u0026\n-\t\t     (s32)(ntohl(tpi-\u003eseq) - tunnel-\u003ei_seqno) \u003c 0)) {\n+\t\tif (!test_bit(IP_TUNNEL_SEQ_BIT, tpi-\u003eflags)) {\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_fifo_errors);\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;\n+\t\t\tgoto drop;\n+\t\t}\n+\t\tif (tunnel-\u003ei_seqno \u0026\u0026\n+\t\t    (s32)(ntohl(tpi-\u003eseq) - tunnel-\u003ei_seqno) \u003c 0) {\n+\t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_fifo_errors);\n+\t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ;\n \t\t\tgoto drop;\n \t\t}\n \t\ttunnel-\u003ei_seqno = ntohl(tpi-\u003eseq) + 1;\n@@ -838,7 +846,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n \n \t/* Warning: All skb pointers will be invalidated! */\n \tif (tunnel-\u003edev-\u003etype == ARPHRD_ETHER) {\n-\t\tif (!pskb_may_pull(skb, ETH_HLEN)) {\n+\t\treason = pskb_may_pull_reason(skb, ETH_HLEN);\n+\t\tif (reason) {\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_length_errors);\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n \t\t\tgoto drop;\n@@ -859,7 +868,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n \n \tskb_reset_network_header(skb);\n \n-\tif (skb_vlan_inet_prepare(skb, true)) {\n+\treason = skb_vlan_inet_prepare(skb, true);\n+\tif (reason) {\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_length_errors);\n \t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n \t\tgoto drop;\n@@ -881,6 +891,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n \t\tif (err \u003e 1) {\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_frame_errors);\n \t\t\tDEV_STATS_INC(tunnel-\u003edev, rx_errors);\n+\t\t\treason = SKB_DROP_REASON_IP_TUNNEL_ECN;\n \t\t\tgoto drop;\n \t\t}\n \t}\n@@ -898,7 +909,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n drop:\n \tif (tun_dst)\n \t\tdst_release((struct dst_entry *)tun_dst);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn 0;\n }\n \n@@ -1099,7 +1110,7 @@ EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);\n \n int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \t\t struct flowi6 *fl6, int encap_limit, __u32 *pmtu,\n-\t\t __u8 proto)\n+\t\t __u8 proto, enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tstruct net *net = t-\u003enet;\n@@ -1132,13 +1143,17 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \t\t\tstruct neighbour *neigh;\n \t\t\tint addr_type;\n \n-\t\t\tif (!skb_dst(skb))\n+\t\t\tif (!skb_dst(skb)) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NO_TX_TARGET;\n \t\t\t\tgoto tx_err_link_failure;\n+\t\t\t}\n \n \t\t\tneigh = dst_neigh_lookup(skb_dst(skb),\n \t\t\t\t\t\t \u0026ipv6_hdr(skb)-\u003edaddr);\n-\t\t\tif (!neigh)\n+\t\t\tif (!neigh) {\n+\t\t\t\t*reason = SKB_DROP_REASON_NEIGH_CREATEFAIL;\n \t\t\t\tgoto tx_err_link_failure;\n+\t\t\t}\n \n \t\t\taddr6 = (struct in6_addr *)\u0026neigh-\u003eprimary_key;\n \t\t\taddr_type = ipv6_addr_type(addr6);\n@@ -1151,8 +1166,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \t\t} else if (payload_protocol == htons(ETH_P_IP)) {\n \t\t\tconst struct rtable *rt = skb_rtable(skb);\n \n-\t\t\tif (!rt)\n+\t\t\tif (!rt) {\n+\t\t\t\t*reason = SKB_DROP_REASON_IP_OUTNOROUTES;\n \t\t\t\tgoto tx_err_link_failure;\n+\t\t\t}\n \n \t\t\tif (rt-\u003ert_gw_family == AF_INET6)\n \t\t\t\tmemcpy(\u0026fl6-\u003edaddr, \u0026rt-\u003ert_gw6, sizeof(fl6-\u003edaddr));\n@@ -1169,8 +1186,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \tif (use_cache)\n \t\tdst = dst_cache_get(\u0026t-\u003edst_cache);\n \n-\tif (!ip6_tnl_xmit_ctl(t, \u0026fl6-\u003esaddr, \u0026fl6-\u003edaddr))\n+\tif (!ip6_tnl_xmit_ctl(t, \u0026fl6-\u003esaddr, \u0026fl6-\u003edaddr)) {\n+\t\t*reason = SKB_DROP_REASON_DEV_READY;\n \t\tgoto tx_err_link_failure;\n+\t}\n \n \tif (!dst) {\n route_lookup:\n@@ -1179,18 +1198,23 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \n \t\tdst = ip6_route_output(net, NULL, fl6);\n \n-\t\tif (dst-\u003eerror)\n+\t\tif (dst-\u003eerror) {\n+\t\t\t*reason = SKB_DROP_REASON_IP_OUTNOROUTES;\n \t\t\tgoto tx_err_link_failure;\n+\t\t}\n \t\tdst = xfrm_lookup(net, dst, flowi6_to_flowi(fl6), NULL, 0);\n \t\tif (IS_ERR(dst)) {\n \t\t\terr = PTR_ERR(dst);\n \t\t\tdst = NULL;\n+\t\t\t*reason = SKB_DROP_REASON_IP_OUTNOROUTES;\n \t\t\tgoto tx_err_link_failure;\n \t\t}\n \t\tif (t-\u003eparms.collect_md \u0026\u0026 ipv6_addr_any(\u0026fl6-\u003esaddr) \u0026\u0026\n \t\t    ipv6_dev_get_saddr(net, ip6_dst_idev(dst)-\u003edev,\n-\t\t\t\t       \u0026fl6-\u003edaddr, 0, \u0026fl6-\u003esaddr))\n+\t\t\t\t       \u0026fl6-\u003edaddr, 0, \u0026fl6-\u003esaddr)) {\n+\t\t\t*reason = SKB_DROP_REASON_NO_TX_TARGET;\n \t\t\tgoto tx_err_link_failure;\n+\t\t}\n \t\tndst = dst;\n \t}\n \n@@ -1200,6 +1224,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \t\tDEV_STATS_INC(dev, collisions);\n \t\tnet_warn_ratelimited(\"%s: Local routing loop detected!\\n\",\n \t\t\t\t     t-\u003eparms.name);\n+\t\t*reason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\tgoto tx_err_dst_release;\n \t}\n \tmtu = dst6_mtu(dst) - eth_hlen - psh_hlen - t-\u003etun_hlen;\n@@ -1214,6 +1239,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \tif (skb-\u003elen - t-\u003etun_hlen - eth_hlen \u003e mtu \u0026\u0026 !skb_is_gso(skb)) {\n \t\t*pmtu = mtu;\n \t\terr = -EMSGSIZE;\n+\t\t*reason = SKB_DROP_REASON_PKT_TOO_BIG;\n \t\tgoto tx_err_dst_release;\n \t}\n \n@@ -1236,12 +1262,16 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \t */\n \tmax_headroom += LL_RESERVED_SPACE(tdev);\n \n-\tif (skb_cow_head(skb, max_headroom))\n+\tif (skb_cow_head(skb, max_headroom)) {\n+\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\tgoto tx_err_dst_release;\n+\t}\n \n \tif (t-\u003eparms.collect_md) {\n-\t\tif (t-\u003eencap.type != TUNNEL_ENCAP_NONE)\n+\t\tif (t-\u003eencap.type != TUNNEL_ENCAP_NONE) {\n+\t\t\t*reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;\n \t\t\tgoto tx_err_dst_release;\n+\t\t}\n \t} else {\n \t\tif (use_cache \u0026\u0026 ndst)\n \t\t\tdst_cache_set_ip6(\u0026t-\u003edst_cache, ndst, \u0026fl6-\u003esaddr);\n@@ -1265,8 +1295,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\n \tip_tunnel_adj_headroom(dev, max_headroom);\n \n \terr = ip6_tnl_encap(skb, t, \u0026proto, fl6);\n-\tif (err)\n+\tif (err) {\n+\t\t*reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;\n \t\treturn err;\n+\t}\n \n \tif (encap_limit \u003e= 0) {\n \t\tinit_tel_txopt(\u0026opt, encap_limit);\n@@ -1295,7 +1327,7 @@ EXPORT_SYMBOL(ip6_tnl_xmit);\n \n static inline int\n ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n-\t\tu8 protocol)\n+\t\tu8 protocol, enum skb_drop_reason *reason)\n {\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tstruct ipv6hdr *ipv6h;\n@@ -1309,8 +1341,10 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n \tint err;\n \n \ttproto = READ_ONCE(t-\u003eparms.proto);\n-\tif (tproto != protocol \u0026\u0026 tproto != 0)\n+\tif (tproto != protocol \u0026\u0026 tproto != 0) {\n+\t\t*reason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\treturn -1;\n+\t}\n \n \tif (t-\u003eparms.collect_md) {\n \t\tstruct ip_tunnel_info *tun_info;\n@@ -1318,8 +1352,10 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n \n \t\ttun_info = skb_tunnel_info(skb);\n \t\tif (unlikely(!tun_info || !(tun_info-\u003emode \u0026 IP_TUNNEL_INFO_TX) ||\n-\t\t\t     ip_tunnel_info_af(tun_info) != AF_INET6))\n+\t\t\t     ip_tunnel_info_af(tun_info) != AF_INET6)) {\n+\t\t\t*reason = SKB_DROP_REASON_TUNNEL_TXINFO;\n \t\t\treturn -1;\n+\t\t}\n \t\tkey = \u0026tun_info-\u003ekey;\n \t\tmemset(\u0026fl6, 0, sizeof(fl6));\n \t\tfl6.flowi6_proto = protocol;\n@@ -1356,6 +1392,7 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t\t\tif (tel-\u003eencap_limit == 0) {\n \t\t\t\t\ticmpv6_ndo_send(skb, ICMPV6_PARAMPROB,\n \t\t\t\t\t\t\tICMPV6_HDR_FIELD, offset + 2);\n+\t\t\t\t\t*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;\n \t\t\t\t\treturn -1;\n \t\t\t\t}\n \t\t\t\tencap_limit = tel-\u003eencap_limit - 1;\n@@ -1397,13 +1434,15 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n \tfl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);\n \tdsfield = INET_ECN_encapsulate(dsfield, orig_dsfield);\n \n-\tif (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))\n+\tif (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6)) {\n+\t\t*reason = SKB_DROP_REASON_NOMEM;\n \t\treturn -1;\n+\t}\n \n \tskb_set_inner_ipproto(skb, protocol);\n \n \terr = ip6_tnl_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\n-\t\t\t   protocol);\n+\t\t\t   protocol, reason);\n \tif (err != 0) {\n \t\t/* XXX: send ICMP error even if DF is not set. */\n \t\tif (err == -EMSGSIZE)\n@@ -1418,6 +1457,7 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n \t\t\tdefault:\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t*reason = SKB_DROP_REASON_PKT_TOO_BIG;\n \t\treturn -1;\n \t}\n \n@@ -1427,11 +1467,13 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\n static netdev_tx_t\n ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)\n {\n+\tenum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;\n \tstruct ip6_tnl *t = netdev_priv(dev);\n \tu8 ipproto;\n \tint ret;\n \n-\tif (!pskb_inet_may_pull(skb))\n+\treason = pskb_inet_may_pull_reason(skb);\n+\tif (reason)\n \t\tgoto tx_err;\n \n \tswitch (skb-\u003eprotocol) {\n@@ -1439,18 +1481,21 @@ ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)\n \t\tipproto = IPPROTO_IPIP;\n \t\tbreak;\n \tcase htons(ETH_P_IPV6):\n-\t\tif (ip6_tnl_addr_conflict(t, ipv6_hdr(skb)))\n+\t\tif (ip6_tnl_addr_conflict(t, ipv6_hdr(skb))) {\n+\t\t\treason = SKB_DROP_REASON_RECURSION_LIMIT;\n \t\t\tgoto tx_err;\n+\t\t}\n \t\tipproto = IPPROTO_IPV6;\n \t\tbreak;\n \tcase htons(ETH_P_MPLS_UC):\n \t\tipproto = IPPROTO_MPLS;\n \t\tbreak;\n \tdefault:\n+\t\treason = SKB_DROP_REASON_UNHANDLED_PROTO;\n \t\tgoto tx_err;\n \t}\n \n-\tret = ipxip6_tnl_xmit(skb, dev, ipproto);\n+\tret = ipxip6_tnl_xmit(skb, dev, ipproto, \u0026reason);\n \tif (ret \u003c 0)\n \t\tgoto tx_err;\n \n@@ -1459,7 +1504,7 @@ ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)\n tx_err:\n \tDEV_STATS_INC(dev, tx_errors);\n \tDEV_STATS_INC(dev, tx_dropped);\n-\tkfree_skb(skb);\n+\tkfree_skb_reason(skb, reason);\n \treturn NETDEV_TX_OK;\n }\n \ndiff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile\nindex 0f5c178bc224b..9acf364e8919e 100644\n--- a/tools/testing/selftests/net/Makefile\n+++ b/tools/testing/selftests/net/Makefile\n@@ -117,6 +117,7 @@ TEST_PROGS := \\\n \ttest_vxlan_vnifiltering.sh \\\n \ttfo_passive.sh \\\n \ttraceroute.sh \\\n+\ttunnel_drop_reasons.sh \\\n \ttxtimestamp.sh \\\n \tudpgro.sh \\\n \tudpgro_bench.sh \\\ndiff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config\nindex 30d5fcb09a831..281633ff3aa9d 100644\n--- a/tools/testing/selftests/net/config\n+++ b/tools/testing/selftests/net/config\n@@ -14,6 +14,7 @@ CONFIG_CRYPTO_SM4_GENERIC=y\n CONFIG_DEBUG_INFO_BTF=y\n CONFIG_DEBUG_INFO_BTF_MODULES=n\n CONFIG_DUMMY=y\n+CONFIG_ENABLE_DEFAULT_TRACERS=y\n CONFIG_GENEVE=m\n CONFIG_IFB=y\n CONFIG_INET_DIAG=y\ndiff --git a/tools/testing/selftests/net/tunnel_drop_reasons.sh b/tools/testing/selftests/net/tunnel_drop_reasons.sh\nnew file mode 100755\nindex 0000000000000..5639e29365a4a\n--- /dev/null\n+++ b/tools/testing/selftests/net/tunnel_drop_reasons.sh\n@@ -0,0 +1,346 @@\n+#!/bin/bash\n+# SPDX-License-Identifier: GPL-2.0\n+#\n+# Test the drop reasons reported by the generic tunnel RX path,\n+# ip_tunnel_rcv() and __ip6_tnl_rcv().\n+#\n+# Two situations are checked, for both GRE and ip6gre:\n+#\n+#  - the options carried by the packet do not match the tunnel\n+#    configuration, which is reported as IP_TUNNEL_CFG_OPTS_MISMATCH.\n+#    It is triggered here by configuring the receiver with 'iseq' or\n+#    'icsum' while the sender emits neither.\n+#\n+#  - the sequence number of the packet is older than the one expected by\n+#    the tunnel, which is reported as IP_TUNNEL_OLD_SEQ.  It is\n+#    triggered here by recreating the tunnel device on the sender, which\n+#    resets its outgoing sequence number the same way a peer reboot\n+#    would.\n+#\n+# A control case, where both endpoints agree on the options, makes sure\n+# that no tunnel drop reason is reported when packets are accepted.\n+#\n+# The GRE specific reasons are checked as well:\n+#\n+#  - a packet that matches no tunnel is reported as\n+#    GRE_TUNNEL_NOT_FOUND.  It is triggered here by giving the two\n+#    endpoints different keys.\n+#\n+# On the transmit side, the reasons reported while encapsulating are\n+# checked too: a packet that does not fit the path MTU, a device in\n+# external mode that receives no metadata, and a tunnel whose remote\n+# endpoint has no route.\n+#\n+#  - a header with the routing bit set is reported as GRE_INVALID_HDR,\n+#    and a header announcing a GRE version nobody handles is reported as\n+#    UNHANDLED_PROTO.  Both are triggered by corrupting the GRE header\n+#    on ingress with tc pedit, and are skipped if that is not available.\n+#\n+# Drop reasons are read from the skb:kfree_skb tracepoint.  A dedicated\n+# trace instance is used so that the test does not disturb, and is not\n+# disturbed by, anything else using the tracing facility.\n+\n+source lib.sh\n+\n+NS_SND=\"\"\n+NS_RCV=\"\"\n+TRACE_DIR=\"\"\n+TR=\"\"\n+\n+SND_V4=10.0.0.1\n+RCV_V4=10.0.0.2\n+SND_V6=2001:db8::1\n+RCV_V6=2001:db8::2\n+TUN_SND=192.168.1.1\n+TUN_RCV=192.168.1.2\n+\n+cleanup()\n+{\n+\tif [ -n \"$TR\" ]; then\n+\t\techo 0 \u003e \"$TR/events/skb/kfree_skb/enable\" 2\u003e/dev/null\n+\t\trmdir \"$TR\" 2\u003e/dev/null\n+\tfi\n+\tcleanup_all_ns\n+}\n+\n+trap cleanup EXIT\n+\n+setup_tracing()\n+{\n+\tlocal dir\n+\n+\tfor dir in /sys/kernel/tracing /sys/kernel/debug/tracing; do\n+\t\tif [ -f \"$dir/trace\" ]; then\n+\t\t\tTRACE_DIR=\"$dir\"\n+\t\t\tbreak\n+\t\tfi\n+\tdone\n+\t[ -n \"$TRACE_DIR\" ] || return 1\n+\t[ -d \"$TRACE_DIR/instances\" ] || return 1\n+\t[ -e \"$TRACE_DIR/events/skb/kfree_skb\" ] || return 1\n+\n+\tTR=\"$TRACE_DIR/instances/tunnel_drop_reasons\"\n+\tmkdir \"$TR\" 2\u003e/dev/null || return 1\n+\techo 1 \u003e \"$TR/events/skb/kfree_skb/enable\" || return 1\n+}\n+\n+setup_ns_pair()\n+{\n+\tPING_ARGS=\"\"\n+\tcleanup_all_ns\n+\tsetup_ns NS_SND NS_RCV\n+\n+\tip link add veth_s netns \"$NS_SND\" type veth \\\n+\t\tpeer name veth_r netns \"$NS_RCV\"\n+\tip -n \"$NS_SND\" link set veth_s up\n+\tip -n \"$NS_RCV\" link set veth_r up\n+\n+\tip -n \"$NS_SND\" addr add \"$SND_V4/24\" dev veth_s\n+\tip -n \"$NS_RCV\" addr add \"$RCV_V4/24\" dev veth_r\n+\tip -n \"$NS_SND\" addr add \"$SND_V6/64\" dev veth_s nodad\n+\tip -n \"$NS_RCV\" addr add \"$RCV_V6/64\" dev veth_r nodad\n+}\n+\n+# $1: namespace, $2: local, $3: remote, $4...: tunnel options\n+add_gre()\n+{\n+\tlocal ns=$1 loc=$2 rem=$3\n+\n+\tshift 3\n+\tip -n \"$ns\" link add gre_test type gre local \"$loc\" remote \"$rem\" \"$@\"\n+\tip -n \"$ns\" link set gre_test up\n+}\n+\n+# $1: namespace, $2: local, $3: remote, $4...: tunnel options\n+add_ip6gre()\n+{\n+\tlocal ns=$1 loc=$2 rem=$3\n+\n+\tshift 3\n+\tip -n \"$ns\" link add gre_test type ip6gre local \"$loc\" remote \"$rem\" \\\n+\t\t\"$@\"\n+\tip -n \"$ns\" link set gre_test up\n+}\n+\n+addr_tunnels()\n+{\n+\tip -n \"$NS_SND\" addr add \"$TUN_SND/24\" dev gre_test\n+\tip -n \"$NS_RCV\" addr add \"$TUN_RCV/24\" dev gre_test\n+}\n+\n+# Traffic used by check_reason().  Tests that need something else set\n+# PING_ARGS before calling it.\n+PING_ARGS=\"\"\n+\n+send_traffic()\n+{\n+\t# shellcheck disable=SC2086\n+\tip netns exec \"$NS_SND\" ping -c 2 -W 1 $PING_ARGS \"$TUN_RCV\" \\\n+\t\t\u003e/dev/null 2\u003e\u00261\n+\t# Let the tracepoint records reach the trace buffer.\n+\tsleep 1\n+}\n+\n+# $1: test name, $2: expected reason, empty if none is expected\n+check_reason()\n+{\n+\tlocal name=$1 want=$2 count\n+\n+\techo \u003e \"$TR/trace\"\n+\tsend_traffic\n+\n+\tif [ -n \"$want\" ]; then\n+\t\tcount=$(grep -c \"reason: $want\" \"$TR/trace\")\n+\t\tif [ \"$count\" -gt 0 ]; then\n+\t\t\tRET=$ksft_pass\n+\t\telse\n+\t\t\tRET=$ksft_fail\n+\t\tfi\n+\t\tlog_test \"$name\" \"$count dropped\"\n+\telse\n+\t\tcount=$(grep -c \"reason: IP_TUNNEL_\" \"$TR/trace\")\n+\t\tif [ \"$count\" -eq 0 ]; then\n+\t\t\tRET=$ksft_pass\n+\t\telse\n+\t\t\tRET=$ksft_fail\n+\t\tfi\n+\t\tlog_test \"$name\" \"$count dropped\"\n+\tfi\n+}\n+\n+test_opts_mismatch()\n+{\n+\tlocal proto=$1 opt=$2\n+\tlocal add=add_gre loc=$SND_V4 rem=$RCV_V4\n+\n+\tif [ \"$proto\" = \"ip6gre\" ]; then\n+\t\tadd=add_ip6gre\n+\t\tloc=$SND_V6\n+\t\trem=$RCV_V6\n+\tfi\n+\n+\tsetup_ns_pair\n+\t# The sender emits no option, the receiver expects one.\n+\t$add \"$NS_SND\" \"$loc\" \"$rem\"\n+\t$add \"$NS_RCV\" \"$rem\" \"$loc\" \"$opt\"\n+\taddr_tunnels\n+\n+\tcheck_reason \"$proto: $opt option mismatch\" \\\n+\t\tIP_TUNNEL_CFG_OPTS_MISMATCH\n+}\n+\n+test_old_seq()\n+{\n+\tlocal proto=$1\n+\tlocal add=add_gre loc=$SND_V4 rem=$RCV_V4\n+\n+\tif [ \"$proto\" = \"ip6gre\" ]; then\n+\t\tadd=add_ip6gre\n+\t\tloc=$SND_V6\n+\t\trem=$RCV_V6\n+\tfi\n+\n+\tsetup_ns_pair\n+\t$add \"$NS_SND\" \"$loc\" \"$rem\" oseq\n+\t$add \"$NS_RCV\" \"$rem\" \"$loc\" iseq\n+\taddr_tunnels\n+\n+\t# Raise the sequence number expected by the receiver, then reset the\n+\t# one used by the sender, as a peer reboot would do.\n+\tsend_traffic\n+\tip -n \"$NS_SND\" link del gre_test\n+\t$add \"$NS_SND\" \"$loc\" \"$rem\" oseq\n+\tip -n \"$NS_SND\" addr add \"$TUN_SND/24\" dev gre_test\n+\n+\tcheck_reason \"$proto: old sequence number\" IP_TUNNEL_OLD_SEQ\n+}\n+\n+test_control()\n+{\n+\tsetup_ns_pair\n+\tadd_gre \"$NS_SND\" \"$SND_V4\" \"$RCV_V4\" oseq ocsum\n+\tadd_gre \"$NS_RCV\" \"$RCV_V4\" \"$SND_V4\" iseq icsum\n+\taddr_tunnels\n+\n+\tcheck_reason \"gre: matching configuration (control)\" \"\"\n+}\n+\n+# Corrupt one field of the GRE header of every IPv4 packet received by\n+# the receiver.  $1 is a tc pedit munge expression, with offsets counted\n+# from the start of the IPv4 header.\n+corrupt_gre_header()\n+{\n+\tip netns exec \"$NS_RCV\" tc qdisc add dev veth_r ingress || return 1\n+\tip netns exec \"$NS_RCV\" tc filter add dev veth_r ingress \\\n+\t\tprotocol ip matchall action pedit ex munge \"$@\" || return 1\n+}\n+\n+test_tunnel_not_found()\n+{\n+\tsetup_ns_pair\n+\t# The two endpoints use different keys, so the lookup on the\n+\t# receiver finds no tunnel for the incoming packets.\n+\tadd_gre \"$NS_SND\" \"$SND_V4\" \"$RCV_V4\" okey 1 ikey 1\n+\tadd_gre \"$NS_RCV\" \"$RCV_V4\" \"$SND_V4\" okey 2 ikey 2\n+\taddr_tunnels\n+\n+\tcheck_reason \"gre: tunnel not found\" GRE_TUNNEL_NOT_FOUND\n+}\n+\n+# $1: test name, $2: expected reason, $3...: tc pedit munge expression\n+test_corrupted_header()\n+{\n+\tlocal name=$1 want=$2\n+\n+\tshift 2\n+\tsetup_ns_pair\n+\tadd_gre \"$NS_SND\" \"$SND_V4\" \"$RCV_V4\"\n+\tadd_gre \"$NS_RCV\" \"$RCV_V4\" \"$SND_V4\"\n+\taddr_tunnels\n+\n+\tif ! corrupt_gre_header \"$@\" 2\u003e/dev/null; then\n+\t\tlog_test_skip \"$name\"\n+\t\treturn\n+\tfi\n+\n+\tcheck_reason \"$name\" \"$want\"\n+}\n+\n+test_tx_pkt_too_big()\n+{\n+\tsetup_ns_pair\n+\t# The underlay cannot carry what the tunnel advertises, so the\n+\t# encapsulated packet does not fit the path MTU.  The kernel sends\n+\t# an ICMP fragmentation needed back and drops it, which is path MTU\n+\t# discovery working as intended.\n+\tip -n \"$NS_SND\" link set veth_s mtu 1280\n+\tip -n \"$NS_RCV\" link set veth_r mtu 1280\n+\tadd_gre \"$NS_SND\" \"$SND_V4\" \"$RCV_V4\"\n+\tadd_gre \"$NS_RCV\" \"$RCV_V4\" \"$SND_V4\"\n+\tip -n \"$NS_SND\" link set gre_test mtu 1500\n+\taddr_tunnels\n+\n+\tPING_ARGS=\"-s 1400 -M do\"\n+\tcheck_reason \"gre: packet does not fit the path MTU\" PKT_TOO_BIG\n+}\n+\n+test_tx_no_metadata()\n+{\n+\tsetup_ns_pair\n+\t# A device in external mode expects the destination to come from\n+\t# the tunnel metadata, which plain traffic does not carry.\n+\tip -n \"$NS_SND\" link add gre_test type gre external\n+\tip -n \"$NS_SND\" link set gre_test up\n+\tip -n \"$NS_SND\" addr add \"$TUN_SND/24\" dev gre_test\n+\n+\tcheck_reason \"gre: external mode without metadata\" TUNNEL_TXINFO\n+}\n+\n+test_tx_no_route()\n+{\n+\tsetup_ns_pair\n+\t# Nothing knows how to reach the remote endpoint of the tunnel.\n+\tadd_gre \"$NS_SND\" \"$SND_V4\" 172.31.255.254\n+\tip -n \"$NS_SND\" addr add \"$TUN_SND/24\" dev gre_test\n+\n+\tcheck_reason \"gre: no route to the remote endpoint\" IP_OUTNOROUTES\n+}\n+\n+if [ \"$(id -u)\" -ne 0 ]; then\n+\techo \"SKIP: need root\"\n+\texit \"$ksft_skip\"\n+fi\n+\n+if ! setup_tracing; then\n+\techo \"SKIP: could not set up a trace instance for skb:kfree_skb\"\n+\texit \"$ksft_skip\"\n+fi\n+\n+test_opts_mismatch gre iseq\n+test_opts_mismatch gre icsum\n+test_control\n+test_old_seq gre\n+\n+test_tunnel_not_found\n+# The routing bit is the second most significant bit of the first byte\n+# of the GRE header, which follows the 20 byte IPv4 header.\n+test_corrupted_header \"gre: routing bit set\" GRE_INVALID_HDR \\\n+\toffset 20 u8 set 0x40\n+# The GRE version sits in the low bits of the next byte.  Version 1 is\n+# PPTP, which has no handler here.\n+test_corrupted_header \"gre: unhandled GRE version\" UNHANDLED_PROTO \\\n+\toffset 21 u8 set 0x01\n+\n+test_tx_pkt_too_big\n+test_tx_no_metadata\n+test_tx_no_route\n+\n+if [ -e /proc/sys/net/ipv6 ]; then\n+\ttest_opts_mismatch ip6gre iseq\n+\ttest_old_seq ip6gre\n+else\n+\tlog_test_skip \"ip6gre: iseq option mismatch\"\n+\tlog_test_skip \"ip6gre: old sequence number\"\n+fi\n+\n+exit \"$EXIT_STATUS\"\n"
}

2/1 2026/09/01 05:55 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch purely introduces new SKB drop reasons and updates IPv4 and IPv6 GRE and tunnel routines to pass specific drop reasons to kfree_skb_reason() (skb:kfree_skb tracepoint), along with a corresponding net selftest. It makes purely decorative/tracepoint changes without functionally altering execution flow.",
  "WorthFuzzing": false
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
  even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).
- Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed,
  ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU.
- Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove)
  that are executed only during PCI hot-unplug or sysfs driver unbind operations.

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
   Prefer non-static, non-inlined API entrypoint functions over internal static helper functions
   (which are inlined by the compiler and do not have distinct symbol addresses).
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs
   needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs
   output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit e1bd834e091e11b973d471fb96d5062a0a98e557
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 1 05:54:57 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 2f312d1f67d69..2a2ac8767d68c 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -128,6 +128,12 @@
 	FN(PSP_INPUT)			\
 	FN(PSP_OUTPUT)			\
 	FN(RECURSION_LIMIT)		\
+	FN(IP_TUNNEL_CFG_OPTS_MISMATCH)	\
+	FN(IP_TUNNEL_OLD_SEQ)		\
+	FN(GRE_INVALID_HDR)		\
+	FN(GRE_CSUM)			\
+	FN(GRE_TUNNEL_NOT_FOUND)	\
+	FN(IP_TUNNEL_ENCAP)		\
 	FNe(MAX)
 
 /**
@@ -606,6 +612,38 @@ enum skb_drop_reason {
 	SKB_DROP_REASON_PSP_OUTPUT,
 	/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */
 	SKB_DROP_REASON_RECURSION_LIMIT,
+	/**
+	 * @SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH: the tunnel options
+	 * carried by the packet do not match the tunnel configuration, e.g.
+	 * a GRE tunnel configured with 'icsum' or 'iseq' received a packet
+	 * with no checksum or no sequence number.
+	 */
+	SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH,
+	/**
+	 * @SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ: the sequence number carried
+	 * by the packet is older than the one expected by the tunnel, e.g.
+	 * after the remote endpoint restarted and reset its sequence
+	 * numbering.
+	 */
+	SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ,
+	/**
+	 * @SKB_DROP_REASON_GRE_INVALID_HDR: the GRE header is invalid, e.g.
+	 * an unsupported version or the routing bit is set.
+	 */
+	SKB_DROP_REASON_GRE_INVALID_HDR,
+	/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */
+	SKB_DROP_REASON_GRE_CSUM,
+	/**
+	 * @SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND: no GRE tunnel found for the
+	 * endpoints and the key the packet carries.
+	 */
+	SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND,
+	/**
+	 * @SKB_DROP_REASON_IP_TUNNEL_ENCAP: failed to build the
+	 * encapsulation header of a tunnel, e.g. an unknown or
+	 * unregistered encapsulation type.
+	 */
+	SKB_DROP_REASON_IP_TUNNEL_ENCAP,
 	/**
 	 * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
 	 * shouldn't be used as a real 'reason' - only for tracing code gen
diff --git a/include/net/gre.h b/include/net/gre.h
index b55f67ecd2fc4..a63f26c3f78ed 100644
--- a/include/net/gre.h
+++ b/include/net/gre.h
@@ -33,7 +33,7 @@ int gre_add_protocol(const struct gre_protocol *proto, u8 version);
 int gre_del_protocol(const struct gre_protocol *proto, u8 version);
 
 int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
-		     bool *csum_err, __be16 proto, int nhs);
+		     enum skb_drop_reason *reason, __be16 proto, int nhs);
 
 static inline bool netif_is_gretap(const struct net_device *dev)
 {
diff --git a/include/net/ip6_tunnel.h b/include/net/ip6_tunnel.h
index b99805ee2fd14..95f6d12254df6 100644
--- a/include/net/ip6_tunnel.h
+++ b/include/net/ip6_tunnel.h
@@ -143,7 +143,8 @@ int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,
 		     const struct in6_addr *raddr);
 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
-		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto);
+		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto,
+		 enum skb_drop_reason *reason);
 __u16 ip6_tnl_parse_tlv_enc_lim(struct sk_buff *skb, __u8 *raw);
 __u32 ip6_tnl_get_cap(struct ip6_tnl *t, const struct in6_addr *laddr,
 			     const struct in6_addr *raddr);
diff --git a/net/ipv4/gre_demux.c b/net/ipv4/gre_demux.c
index 96fd7dc6d82dd..598678f42ef5f 100644
--- a/net/ipv4/gre_demux.c
+++ b/net/ipv4/gre_demux.c
@@ -58,26 +58,43 @@ EXPORT_SYMBOL_GPL(gre_del_protocol);
 
 /* Fills in tpi and returns header length to be pulled.
  * Note that caller must use pskb_may_pull() before pulling GRE header.
+ *
+ * @reason is only written when the header is rejected, so the caller has
+ * to initialise it before the call.
+ *
+ * A NULL @reason means that the caller is not interested in the drop
+ * reason, and also that the checksum must not be verified.  This is what
+ * the ICMP error handlers need, as they only get a part of the original
+ * packet.
  */
 int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
-		     bool *csum_err, __be16 proto, int nhs)
+		     enum skb_drop_reason *reason, __be16 proto, int nhs)
 {
 	const struct gre_base_hdr *greh;
 	__be32 *options;
 	int hdr_len;
 
-	if (unlikely(!pskb_may_pull(skb, nhs + sizeof(struct gre_base_hdr))))
+	if (unlikely(!pskb_may_pull(skb, nhs + sizeof(struct gre_base_hdr)))) {
+		if (reason)
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 		return -EINVAL;
+	}
 
 	greh = (struct gre_base_hdr *)(skb->data + nhs);
-	if (unlikely(greh->flags & (GRE_VERSION | GRE_ROUTING)))
+	if (unlikely(greh->flags & (GRE_VERSION | GRE_ROUTING))) {
+		if (reason)
+			*reason = SKB_DROP_REASON_GRE_INVALID_HDR;
 		return -EINVAL;
+	}
 
 	gre_flags_to_tnl_flags(tpi->flags, greh->flags);
 	hdr_len = gre_calc_hlen(tpi->flags);
 
-	if (!pskb_may_pull(skb, nhs + hdr_len))
+	if (!pskb_may_pull(skb, nhs + hdr_len)) {
+		if (reason)
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 		return -EINVAL;
+	}
 
 	greh = (struct gre_base_hdr *)(skb->data + nhs);
 	tpi->proto = greh->protocol;
@@ -87,8 +104,8 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		if (!skb_checksum_simple_validate(skb)) {
 			skb_checksum_try_convert(skb, IPPROTO_GRE,
 						 null_compute_pseudo);
-		} else if (csum_err) {
-			*csum_err = true;
+		} else if (reason) {
+			*reason = SKB_DROP_REASON_GRE_CSUM;
 			return -EINVAL;
 		}
 
@@ -116,8 +133,11 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 
 		val = skb_header_pointer(skb, nhs + hdr_len,
 					 sizeof(_val), &_val);
-		if (!val)
+		if (!val) {
+			if (reason)
+				*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return -EINVAL;
+		}
 		tpi->proto = proto;
 		if ((*val & 0xF0) != 0x40)
 			hdr_len += 4;
@@ -132,8 +152,11 @@ int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	    greh->protocol == htons(ETH_P_ERSPAN2)) {
 		struct erspan_base_hdr *ershdr;
 
-		if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr)))
+		if (!pskb_may_pull(skb, nhs + hdr_len + sizeof(*ershdr))) {
+			if (reason)
+				*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return -EINVAL;
+		}
 
 		ershdr = (struct erspan_base_hdr *)(skb->data + nhs + hdr_len);
 		tpi->key = cpu_to_be32(get_session_id(ershdr));
@@ -146,15 +169,19 @@ EXPORT_SYMBOL(gre_parse_header);
 static int gre_rcv(struct sk_buff *skb)
 {
 	const struct gre_protocol *proto;
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	u8 ver;
 	int ret;
 
-	if (!pskb_may_pull(skb, 12))
+	reason = pskb_may_pull_reason(skb, 12);
+	if (reason)
 		goto drop;
 
 	ver = skb->data[1]&0x7f;
-	if (ver >= GREPROTO_MAX)
+	if (ver >= GREPROTO_MAX) {
+		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		goto drop;
+	}
 
 	rcu_read_lock();
 	proto = rcu_dereference(gre_proto[ver]);
@@ -167,11 +194,11 @@ static int gre_rcv(struct sk_buff *skb)
 drop_nohandler:
 	rcu_read_unlock();
 	dev_core_stats_rx_nohandler_inc(skb->dev);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_UNHANDLED_PROTO);
 	return NET_RX_DROP;
 drop:
 	dev_core_stats_rx_dropped_inc(skb->dev);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return NET_RX_DROP;
 }
 
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 82309efd417e0..c45e9590c94d5 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -265,7 +265,7 @@ static bool is_erspan_type1(int gre_hdr_len)
 }
 
 static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
-		      int gre_hdr_len)
+		      int gre_hdr_len, enum skb_drop_reason *reason)
 {
 	struct net *net = dev_net(skb->dev);
 	struct metadata_dst *tun_dst = NULL;
@@ -289,8 +289,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 					  iph->saddr, iph->daddr, 0);
 	} else {
 		if (unlikely(!pskb_may_pull(skb,
-					    gre_hdr_len + sizeof(*ershdr))))
+					    gre_hdr_len + sizeof(*ershdr)))) {
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return PACKET_REJECT;
+		}
 
 		ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len);
 		ver = ershdr->ver;
@@ -306,8 +308,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		else
 			len = gre_hdr_len + erspan_hdr_len(ver);
 
-		if (unlikely(!pskb_may_pull(skb, len)))
+		if (unlikely(!pskb_may_pull(skb, len))) {
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return PACKET_REJECT;
+		}
 
 		if (__iptunnel_pull_header(skb,
 					   len,
@@ -327,8 +331,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 
 			tun_dst = ip_tun_rx_dst(skb, flags,
 						tun_id, sizeof(*md));
-			if (!tun_dst)
+			if (!tun_dst) {
+				*reason = SKB_DROP_REASON_NOMEM;
 				return PACKET_REJECT;
+			}
 
 			/* MUST set options_len before referencing options */
 			info = &tun_dst->u.tun_info;
@@ -356,15 +362,17 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 		ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
 		return PACKET_RCVD;
 	}
+	*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
 	return PACKET_REJECT;
 
 drop:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);
 	return PACKET_RCVD;
 }
 
 static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
-		       struct ip_tunnel_net *itn, int hdr_len, bool raw_proto)
+		       struct ip_tunnel_net *itn, int hdr_len, bool raw_proto,
+		       enum skb_drop_reason *reason)
 {
 	struct metadata_dst *tun_dst = NULL;
 	const struct iphdr *iph;
@@ -400,22 +408,25 @@ static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
 
 			tun_id = key32_to_tunnel_id(tpi->key);
 			tun_dst = ip_tun_rx_dst(skb, flags, tun_id, 0);
-			if (!tun_dst)
+			if (!tun_dst) {
+				*reason = SKB_DROP_REASON_NOMEM;
 				return PACKET_REJECT;
+			}
 		}
 
 		ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
 		return PACKET_RCVD;
 	}
+	*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
 	return PACKET_NEXT;
 
 drop:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);
 	return PACKET_RCVD;
 }
 
 static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
-		     int hdr_len)
+		     int hdr_len, enum skb_drop_reason *reason)
 {
 	struct net *net = dev_net(skb->dev);
 	struct ip_tunnel_net *itn;
@@ -426,21 +437,21 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
 	else
 		itn = net_generic(net, ipgre_net_id);
 
-	res = __ipgre_rcv(skb, tpi, itn, hdr_len, false);
+	res = __ipgre_rcv(skb, tpi, itn, hdr_len, false, reason);
 	if (res == PACKET_NEXT && tpi->proto == htons(ETH_P_TEB)) {
 		/* ipgre tunnels in collect metadata mode should receive
 		 * also ETH_P_TEB traffic.
 		 */
 		itn = net_generic(net, ipgre_net_id);
-		res = __ipgre_rcv(skb, tpi, itn, hdr_len, true);
+		res = __ipgre_rcv(skb, tpi, itn, hdr_len, true, reason);
 	}
 	return res;
 }
 
 static int gre_rcv(struct sk_buff *skb)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct tnl_ptk_info tpi;
-	bool csum_err = false;
 	int hdr_len;
 
 #ifdef CONFIG_NET_IPGRE_BROADCAST
@@ -451,25 +462,25 @@ static int gre_rcv(struct sk_buff *skb)
 	}
 #endif
 
-	hdr_len = gre_parse_header(skb, &tpi, &csum_err, htons(ETH_P_IP), 0);
+	hdr_len = gre_parse_header(skb, &tpi, &reason, htons(ETH_P_IP), 0);
 	if (hdr_len < 0)
 		goto drop;
 
 	if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
 		     tpi.proto == htons(ETH_P_ERSPAN2))) {
-		if (erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+		if (erspan_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
 			return 0;
 		goto out;
 	}
 
-	if (ipgre_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+	if (ipgre_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
 		return 0;
 
 out:
 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
 drop:
 	dev_core_stats_rx_dropped_inc(skb->dev);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return 0;
 }
 
@@ -500,23 +511,30 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
 	IP_TUNNEL_DECLARE_FLAGS(flags) = { };
 	struct ip_tunnel_info *tun_info;
 	const struct ip_tunnel_key *key;
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	int tunnel_hlen;
 
 	tun_info = skb_tunnel_info(skb);
 	if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
-		     ip_tunnel_info_af(tun_info) != AF_INET))
+		     ip_tunnel_info_af(tun_info) != AF_INET)) {
+		reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 		goto err_free_skb;
+	}
 
 	key = &tun_info->key;
 	tunnel_hlen = gre_calc_hlen(key->tun_flags);
 
-	if (skb_cow_head(skb, dev->needed_headroom))
+	if (skb_cow_head(skb, dev->needed_headroom)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto err_free_skb;
+	}
 
 	/* Push Tunnel header. */
 	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,
-					      tunnel->parms.o_flags)))
+					      tunnel->parms.o_flags))) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto err_free_skb;
+	}
 
 	__set_bit(IP_TUNNEL_CSUM_BIT, flags);
 	__set_bit(IP_TUNNEL_KEY_BIT, flags);
@@ -533,7 +551,7 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,
 	return;
 
 err_free_skb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	DEV_STATS_INC(dev, tx_dropped);
 }
 
@@ -543,6 +561,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
 	IP_TUNNEL_DECLARE_FLAGS(flags) = { };
 	struct ip_tunnel_info *tun_info;
 	const struct ip_tunnel_key *key;
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct erspan_metadata *md;
 	bool truncate = false;
 	__be16 proto;
@@ -552,29 +571,41 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	tun_info = skb_tunnel_info(skb);
 	if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
-		     ip_tunnel_info_af(tun_info) != AF_INET))
+		     ip_tunnel_info_af(tun_info) != AF_INET)) {
+		reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 		goto err_free_skb;
+	}
 
 	key = &tun_info->key;
-	if (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT, tun_info->key.tun_flags))
+	if (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT, tun_info->key.tun_flags)) {
+		reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 		goto err_free_skb;
-	if (tun_info->options_len < sizeof(*md))
+	}
+	if (tun_info->options_len < sizeof(*md)) {
+		reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 		goto err_free_skb;
+	}
 	md = ip_tunnel_info_opts(tun_info);
 
 	/* ERSPAN has fixed 8 byte GRE header */
 	version = md->version;
 	tunnel_hlen = 8 + erspan_hdr_len(version);
 
-	if (skb_cow_head(skb, dev->needed_headroom))
+	if (skb_cow_head(skb, dev->needed_headroom)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto err_free_skb;
+	}
 
-	if (gre_handle_offloads(skb, false))
+	if (gre_handle_offloads(skb, false)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto err_free_skb;
+	}
 
 	if (skb->len > dev->mtu + dev->hard_header_len) {
-		if (pskb_trim(skb, dev->mtu + dev->hard_header_len))
+		if (pskb_trim(skb, dev->mtu + dev->hard_header_len)) {
+			reason = SKB_DROP_REASON_NOMEM;
 			goto err_free_skb;
+		}
 		truncate = true;
 	}
 
@@ -606,6 +637,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
 				       truncate, true);
 		proto = htons(ETH_P_ERSPAN2);
 	} else {
+		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		goto err_free_skb;
 	}
 
@@ -618,7 +650,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
 	return;
 
 err_free_skb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	DEV_STATS_INC(dev, tx_dropped);
 }
 
@@ -652,8 +684,10 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
 	struct ip_tunnel *tunnel = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags);
 	const struct iphdr *tnl_params;
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto free_skb;
 
 	if (tunnel->collect_md) {
@@ -664,10 +698,13 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
 	if (dev->header_ops) {
 		int pull_len = tunnel->hlen + sizeof(struct iphdr);
 
-		if (skb_cow_head(skb, 0))
+		if (skb_cow_head(skb, 0)) {
+			reason = SKB_DROP_REASON_NOMEM;
 			goto free_skb;
+		}
 
-		if (!pskb_may_pull(skb, pull_len))
+		reason = pskb_may_pull_reason(skb, pull_len);
+		if (reason)
 			goto free_skb;
 
 		tnl_params = (const struct iphdr *)skb->data;
@@ -677,25 +714,31 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,
 		skb_reset_mac_header(skb);
 
 		if (skb->ip_summed == CHECKSUM_PARTIAL &&
-		    skb_checksum_start(skb) < skb->data)
+		    skb_checksum_start(skb) < skb->data) {
+			reason = SKB_DROP_REASON_SKB_CSUM;
 			goto free_skb;
+		}
 	} else {
-		if (skb_cow_head(skb, dev->needed_headroom))
+		if (skb_cow_head(skb, dev->needed_headroom)) {
+			reason = SKB_DROP_REASON_NOMEM;
 			goto free_skb;
+		}
 
 		tnl_params = &tunnel->parms.iph;
 	}
 
 	ip_tunnel_flags_copy(flags, tunnel->parms.o_flags);
 
-	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags)))
+	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags))) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto free_skb;
+	}
 
 	__gre_xmit(skb, dev, tnl_params, skb->protocol, flags);
 	return NETDEV_TX_OK;
 
 free_skb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	DEV_STATS_INC(dev, tx_dropped);
 	return NETDEV_TX_OK;
 }
@@ -705,10 +748,12 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 {
 	struct ip_tunnel *tunnel = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags);
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	bool truncate = false;
 	__be16 proto;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto free_skb;
 
 	if (tunnel->collect_md) {
@@ -716,15 +761,21 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 		return NETDEV_TX_OK;
 	}
 
-	if (gre_handle_offloads(skb, false))
+	if (gre_handle_offloads(skb, false)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto free_skb;
+	}
 
-	if (skb_cow_head(skb, dev->needed_headroom))
+	if (skb_cow_head(skb, dev->needed_headroom)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto free_skb;
+	}
 
 	if (skb->len > dev->mtu + dev->hard_header_len) {
-		if (pskb_trim(skb, dev->mtu + dev->hard_header_len))
+		if (pskb_trim(skb, dev->mtu + dev->hard_header_len)) {
+			reason = SKB_DROP_REASON_NOMEM;
 			goto free_skb;
+		}
 		truncate = true;
 	}
 
@@ -745,6 +796,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 				       truncate, true);
 		proto = htons(ETH_P_ERSPAN2);
 	} else {
+		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		goto free_skb;
 	}
 
@@ -753,7 +805,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
 	return NETDEV_TX_OK;
 
 free_skb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	DEV_STATS_INC(dev, tx_dropped);
 	return NETDEV_TX_OK;
 }
@@ -763,8 +815,10 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,
 {
 	struct ip_tunnel *tunnel = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags);
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto free_skb;
 
 	if (tunnel->collect_md) {
@@ -774,17 +828,21 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,
 
 	ip_tunnel_flags_copy(flags, tunnel->parms.o_flags);
 
-	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags)))
+	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT, flags))) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto free_skb;
+	}
 
-	if (skb_cow_head(skb, dev->needed_headroom))
+	if (skb_cow_head(skb, dev->needed_headroom)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto free_skb;
+	}
 
 	__gre_xmit(skb, dev, &tunnel->parms.iph, htons(ETH_P_TEB), flags);
 	return NETDEV_TX_OK;
 
 free_skb:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	DEV_STATS_INC(dev, tx_dropped);
 	return NETDEV_TX_OK;
 }
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index e6bcf01411d0b..12d45f69c4d82 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -379,6 +379,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 		  bool log_ecn_error)
 {
 	const struct iphdr *iph = ip_hdr(skb);
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	int nh, err;
 
 #ifdef CONFIG_NET_IPGRE_BROADCAST
@@ -392,14 +393,22 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 	    test_bit(IP_TUNNEL_CSUM_BIT, tpi->flags)) {
 		DEV_STATS_INC(tunnel->dev, rx_crc_errors);
 		DEV_STATS_INC(tunnel->dev, rx_errors);
+		reason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;
 		goto drop;
 	}
 
 	if (test_bit(IP_TUNNEL_SEQ_BIT, tunnel->parms.i_flags)) {
-		if (!test_bit(IP_TUNNEL_SEQ_BIT, tpi->flags) ||
-		    (tunnel->i_seqno && (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0)) {
+		if (!test_bit(IP_TUNNEL_SEQ_BIT, tpi->flags)) {
 			DEV_STATS_INC(tunnel->dev, rx_fifo_errors);
 			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;
+			goto drop;
+		}
+		if (tunnel->i_seqno &&
+		    (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0) {
+			DEV_STATS_INC(tunnel->dev, rx_fifo_errors);
+			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ;
 			goto drop;
 		}
 		tunnel->i_seqno = ntohl(tpi->seq) + 1;
@@ -413,7 +422,8 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 
 	skb_set_network_header(skb, (tunnel->dev->type == ARPHRD_ETHER) ? ETH_HLEN : 0);
 
-	if (!pskb_inet_may_pull(skb)) {
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason) {
 		DEV_STATS_INC(tunnel->dev, rx_length_errors);
 		DEV_STATS_INC(tunnel->dev, rx_errors);
 		goto drop;
@@ -428,6 +438,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 		if (err > 1) {
 			DEV_STATS_INC(tunnel->dev, rx_frame_errors);
 			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_ECN;
 			goto drop;
 		}
 	}
@@ -451,7 +462,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,
 drop:
 	if (tun_dst)
 		dst_release((struct dst_entry *)tun_dst);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ip_tunnel_rcv);
@@ -571,6 +582,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
 void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 		       u8 proto, int tunnel_hlen)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct ip_tunnel *tunnel = netdev_priv(dev);
 	u32 headroom = sizeof(struct iphdr);
 	struct ip_tunnel_info *tun_info;
@@ -584,8 +596,10 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 	tun_info = skb_tunnel_info(skb);
 	if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
-		     ip_tunnel_info_af(tun_info) != AF_INET))
+		     ip_tunnel_info_af(tun_info) != AF_INET)) {
+		reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 		goto tx_error;
+	}
 	key = &tun_info->key;
 	memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
 	inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
@@ -604,8 +618,10 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (!tunnel_hlen)
 		tunnel_hlen = ip_encap_hlen(&tun_info->encap);
 
-	if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0)
+	if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0) {
+		reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;
 		goto tx_error;
+	}
 
 	use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
 	if (use_cache)
@@ -614,6 +630,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 		rt = ip_route_output_key(tunnel->net, &fl4);
 		if (IS_ERR(rt)) {
 			DEV_STATS_INC(dev, tx_carrier_errors);
+			reason = SKB_DROP_REASON_IP_OUTNOROUTES;
 			goto tx_error;
 		}
 		if (use_cache)
@@ -623,6 +640,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (rt->dst.dev == dev) {
 		ip_rt_put(rt);
 		DEV_STATS_INC(dev, collisions);
+		reason = SKB_DROP_REASON_RECURSION_LIMIT;
 		goto tx_error;
 	}
 
@@ -631,6 +649,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, tunnel_hlen,
 			    key->u.ipv4.dst, true)) {
 		ip_rt_put(rt);
+		reason = SKB_DROP_REASON_PKT_TOO_BIG;
 		goto tx_error;
 	}
 
@@ -648,6 +667,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	headroom += LL_RESERVED_SPACE(rt->dst.dev) + rt->dst.header_len;
 	if (skb_cow_head(skb, headroom)) {
 		ip_rt_put(rt);
+		reason = SKB_DROP_REASON_NOMEM;
 		goto tx_dropped;
 	}
 
@@ -662,13 +682,14 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 tx_dropped:
 	DEV_STATS_INC(dev, tx_dropped);
 kfree:
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 }
 EXPORT_SYMBOL_GPL(ip_md_tunnel_xmit);
 
 void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 		    const struct iphdr *tnl_params, u8 protocol)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct ip_tunnel *tunnel = netdev_priv(dev);
 	struct ip_tunnel_info *tun_info = NULL;
 	const struct iphdr *inner_iph;
@@ -696,9 +717,15 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 		if (!skb_dst(skb)) {
 			DEV_STATS_INC(dev, tx_fifo_errors);
+			reason = SKB_DROP_REASON_NO_TX_TARGET;
 			goto tx_error;
 		}
 
+		/* Only the branches below can derive a destination.  If
+		 * none of them matches, the payload protocol is not one
+		 * this tunnel can carry.
+		 */
+		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		tun_info = skb_tunnel_info(skb);
 		if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
 		    ip_tunnel_info_af(tun_info) == AF_INET &&
@@ -719,8 +746,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 			neigh = dst_neigh_lookup(skb_dst(skb),
 						 &ipv6_hdr(skb)->daddr);
-			if (!neigh)
+			if (!neigh) {
+				reason = SKB_DROP_REASON_NEIGH_CREATEFAIL;
 				goto tx_error;
+			}
 
 			addr6 = (const struct in6_addr *)&neigh->primary_key;
 			addr_type = ipv6_addr_type(addr6);
@@ -737,8 +766,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 				dst = addr6->s6_addr32[3];
 			}
 			neigh_release(neigh);
-			if (do_tx_error_icmp)
+			if (do_tx_error_icmp) {
+				reason = SKB_DROP_REASON_NO_TX_TARGET;
 				goto tx_error_icmp;
+			}
 		}
 #endif
 		else
@@ -765,8 +796,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 			    tunnel->net, READ_ONCE(tunnel->parms.link),
 			    tunnel->fwmark, skb_get_hash(skb), 0);
 
-	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0)
+	if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) {
+		reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;
 		goto tx_error;
+	}
 
 	if (connected && md) {
 		use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
@@ -783,6 +816,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 		if (IS_ERR(rt)) {
 			DEV_STATS_INC(dev, tx_carrier_errors);
+			reason = SKB_DROP_REASON_IP_OUTNOROUTES;
 			goto tx_error;
 		}
 		if (use_cache)
@@ -796,6 +830,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (rt->dst.dev == dev) {
 		ip_rt_put(rt);
 		DEV_STATS_INC(dev, collisions);
+		reason = SKB_DROP_REASON_RECURSION_LIMIT;
 		goto tx_error;
 	}
 
@@ -805,6 +840,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 
 	if (tnl_update_pmtu(dev, skb, rt, df, inner_iph, 0, 0, false)) {
 		ip_rt_put(rt);
+		reason = SKB_DROP_REASON_PKT_TOO_BIG;
 		goto tx_error;
 	}
 
@@ -839,7 +875,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 	if (skb_cow_head(skb, max_headroom)) {
 		ip_rt_put(rt);
 		DEV_STATS_INC(dev, tx_dropped);
-		kfree_skb(skb);
+		kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
 		return;
 	}
 
@@ -855,7 +891,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
 #endif
 tx_error:
 	DEV_STATS_INC(dev, tx_errors);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 }
 EXPORT_SYMBOL_GPL(ip_tunnel_xmit);
 
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 69c51f1a5bf08..42a0336407163 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -454,7 +454,8 @@ static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 	return 0;
 }
 
-static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
+static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
+		      enum skb_drop_reason *reason)
 {
 	const struct ipv6hdr *ipv6h;
 	struct ip6_tnl *tunnel;
@@ -473,8 +474,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
 			tun_id = key32_to_tunnel_id(tpi->key);
 
 			tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id, 0);
-			if (!tun_dst)
+			if (!tun_dst) {
+				*reason = SKB_DROP_REASON_NOMEM;
 				return PACKET_REJECT;
+			}
 
 			ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
 		} else {
@@ -484,12 +487,14 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
 		return PACKET_RCVD;
 	}
 
+	*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
 	return PACKET_REJECT;
 }
 
 static int ip6erspan_rcv(struct sk_buff *skb,
 			 struct tnl_ptk_info *tpi,
-			 int gre_hdr_len)
+			 int gre_hdr_len,
+			 enum skb_drop_reason *reason)
 {
 	struct erspan_base_hdr *ershdr;
 	const struct ipv6hdr *ipv6h;
@@ -497,8 +502,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,
 	struct ip6_tnl *tunnel;
 	u8 ver;
 
-	if (unlikely(!pskb_may_pull(skb, sizeof(*ershdr))))
+	if (unlikely(!pskb_may_pull(skb, sizeof(*ershdr)))) {
+		*reason = SKB_DROP_REASON_HDR_TRUNC;
 		return PACKET_REJECT;
+	}
 
 	ipv6h = ipv6_hdr(skb);
 	ershdr = (struct erspan_base_hdr *)skb->data;
@@ -510,13 +517,17 @@ static int ip6erspan_rcv(struct sk_buff *skb,
 	if (tunnel) {
 		int len = erspan_hdr_len(ver);
 
-		if (unlikely(!pskb_may_pull(skb, len)))
+		if (unlikely(!pskb_may_pull(skb, len))) {
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return PACKET_REJECT;
+		}
 
 		if (__iptunnel_pull_header(skb, len,
 					   htons(ETH_P_TEB),
-					   false, false) < 0)
+					   false, false) < 0) {
+			*reason = SKB_DROP_REASON_HDR_TRUNC;
 			return PACKET_REJECT;
+		}
 
 		if (tunnel->parms.collect_md) {
 			struct erspan_metadata *pkt_md, *md;
@@ -532,8 +543,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,
 
 			tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id,
 						  sizeof(*md));
-			if (!tun_dst)
+			if (!tun_dst) {
+				*reason = SKB_DROP_REASON_NOMEM;
 				return PACKET_REJECT;
+			}
 
 			/* MUST set options_len before referencing options */
 			info = &tun_dst->u.tun_info;
@@ -564,37 +577,40 @@ static int ip6erspan_rcv(struct sk_buff *skb,
 		return PACKET_RCVD;
 	}
 
+	*reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
 	return PACKET_REJECT;
 }
 
 static int gre_rcv(struct sk_buff *skb)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct tnl_ptk_info tpi;
-	bool csum_err = false;
 	int hdr_len;
 
-	hdr_len = gre_parse_header(skb, &tpi, &csum_err, htons(ETH_P_IPV6), 0);
+	hdr_len = gre_parse_header(skb, &tpi, &reason, htons(ETH_P_IPV6), 0);
 	if (hdr_len < 0)
 		goto drop;
 
-	if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
+	if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false)) {
+		reason = SKB_DROP_REASON_HDR_TRUNC;
 		goto drop;
+	}
 
 	if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
 		     tpi.proto == htons(ETH_P_ERSPAN2))) {
-		if (ip6erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+		if (ip6erspan_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
 			return 0;
 		goto out;
 	}
 
-	if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
+	if (ip6gre_rcv(skb, &tpi, &reason) == PACKET_RCVD)
 		return 0;
 
 out:
 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
 drop:
 	dev_core_stats_rx_dropped_inc(skb->dev);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return 0;
 }
 
@@ -718,7 +734,8 @@ static struct ip_tunnel_info *skb_tunnel_info_txcheck(struct sk_buff *skb)
 static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 			       struct net_device *dev, __u8 dsfield,
 			       struct flowi6 *fl6, int encap_limit,
-			       __u32 *pmtu, __be16 proto)
+			       __u32 *pmtu, __be16 proto,
+			       enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *tunnel = netdev_priv(dev);
 	IP_TUNNEL_DECLARE_FLAGS(flags);
@@ -742,8 +759,10 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 
 		tun_info = skb_tunnel_info_txcheck(skb);
 		if (IS_ERR(tun_info) ||
-		    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))
+		    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6)) {
+			*reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 			return -EINVAL;
+		}
 
 		key = &tun_info->key;
 		memset(fl6, 0, sizeof(*fl6));
@@ -761,8 +780,11 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 		ip_tunnel_flags_and(flags, flags, key->tun_flags);
 		tun_hlen = gre_calc_hlen(flags);
 
-		if (skb_cow_head(skb, dev->needed_headroom ?: tun_hlen + tunnel->encap_hlen))
+		if (skb_cow_head(skb, dev->needed_headroom ?:
+				 tun_hlen + tunnel->encap_hlen)) {
+			*reason = SKB_DROP_REASON_NOMEM;
 			return -ENOMEM;
+		}
 
 		gre_build_header(skb, tun_hlen,
 				 flags, protocol,
@@ -772,8 +794,10 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 				 0);
 
 	} else {
-		if (skb_cow_head(skb, dev->needed_headroom ?: tunnel->hlen))
+		if (skb_cow_head(skb, dev->needed_headroom ?: tunnel->hlen)) {
+			*reason = SKB_DROP_REASON_NOMEM;
 			return -ENOMEM;
+		}
 
 		ip_tunnel_flags_copy(flags, tunnel->parms.o_flags);
 
@@ -785,10 +809,11 @@ static netdev_tx_t __gre6_xmit(struct sk_buff *skb,
 	}
 
 	return ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,
-			    NEXTHDR_GRE);
+			    NEXTHDR_GRE, reason);
 }
 
-static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
+static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev,
+				   enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	int encap_limit = -1;
@@ -805,11 +830,13 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
 
 	err = gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,
 						t->parms.o_flags));
-	if (err)
+	if (err) {
+		*reason = SKB_DROP_REASON_NOMEM;
 		return -1;
+	}
 
 	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			  skb->protocol);
+			  skb->protocol, reason);
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE)
@@ -821,7 +848,8 @@ static inline int ip6gre_xmit_ipv4(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
-static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
+static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev,
+				   enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct ipv6hdr *ipv6h = ipv6_hdr(skb);
@@ -831,19 +859,25 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
 	__u32 mtu;
 	int err;
 
-	if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr))
+	if (ipv6_addr_equal(&t->parms.raddr, &ipv6h->saddr)) {
+		*reason = SKB_DROP_REASON_RECURSION_LIMIT;
 		return -1;
+	}
 
 	if (!t->parms.collect_md &&
-	    prepare_ip6gre_xmit_ipv6(skb, dev, &fl6, &dsfield, &encap_limit))
+	    prepare_ip6gre_xmit_ipv6(skb, dev, &fl6, &dsfield, &encap_limit)) {
+		*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;
 		return -1;
+	}
 
 	if (gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,
-					      t->parms.o_flags)))
+					      t->parms.o_flags))) {
+		*reason = SKB_DROP_REASON_NOMEM;
 		return -1;
+	}
 
 	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit,
-			  &mtu, skb->protocol);
+			  &mtu, skb->protocol, reason);
 	if (err != 0) {
 		if (err == -EMSGSIZE)
 			icmpv6_ndo_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
@@ -853,7 +887,8 @@ static inline int ip6gre_xmit_ipv6(struct sk_buff *skb, struct net_device *dev)
 	return 0;
 }
 
-static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
+static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev,
+			     enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	int encap_limit = -1;
@@ -863,14 +898,19 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
 	int err;
 
 	if (!t->parms.collect_md &&
-	    prepare_ip6gre_xmit_other(skb, dev, &fl6, &dsfield, &encap_limit))
+	    prepare_ip6gre_xmit_other(skb, dev, &fl6, &dsfield, &encap_limit)) {
+		*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;
 		return -1;
+	}
 
 	err = gre_handle_offloads(skb, test_bit(IP_TUNNEL_CSUM_BIT,
 						t->parms.o_flags));
-	if (err)
+	if (err) {
+		*reason = SKB_DROP_REASON_NOMEM;
 		return err;
-	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu, skb->protocol);
+	}
+	err = __gre6_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
+			  skb->protocol, reason);
 
 	return err;
 }
@@ -878,26 +918,30 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)
 static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 	struct net_device *dev)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct ip6_tnl *t = netdev_priv(dev);
 	__be16 payload_protocol;
 	int ret;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto tx_err;
 
-	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
+	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr)) {
+		reason = SKB_DROP_REASON_DEV_READY;
 		goto tx_err;
+	}
 
 	payload_protocol = skb_protocol(skb, true);
 	switch (payload_protocol) {
 	case htons(ETH_P_IP):
-		ret = ip6gre_xmit_ipv4(skb, dev);
+		ret = ip6gre_xmit_ipv4(skb, dev, &reason);
 		break;
 	case htons(ETH_P_IPV6):
-		ret = ip6gre_xmit_ipv6(skb, dev);
+		ret = ip6gre_xmit_ipv6(skb, dev, &reason);
 		break;
 	default:
-		ret = ip6gre_xmit_other(skb, dev);
+		ret = ip6gre_xmit_other(skb, dev, &reason);
 		break;
 	}
 
@@ -910,7 +954,7 @@ static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,
 	if (!t->parms.collect_md || !IS_ERR(skb_tunnel_info_txcheck(skb)))
 		DEV_STATS_INC(dev, tx_errors);
 	DEV_STATS_INC(dev, tx_dropped);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return NETDEV_TX_OK;
 }
 
@@ -921,6 +965,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct dst_entry *dst = skb_dst(skb);
 	IP_TUNNEL_DECLARE_FLAGS(flags) = { };
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	bool truncate = false;
 	int encap_limit = -1;
 	__u8 dsfield = false;
@@ -930,18 +975,25 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	__u32 mtu;
 	int nhoff;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto tx_err;
 
-	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
+	if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr)) {
+		reason = SKB_DROP_REASON_DEV_READY;
 		goto tx_err;
+	}
 
-	if (gre_handle_offloads(skb, false))
+	if (gre_handle_offloads(skb, false)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto tx_err;
+	}
 
 	if (skb->len > dev->mtu + dev->hard_header_len) {
-		if (pskb_trim(skb, dev->mtu + dev->hard_header_len))
+		if (pskb_trim(skb, dev->mtu + dev->hard_header_len)) {
+			reason = SKB_DROP_REASON_NOMEM;
 			goto tx_err;
+		}
 		truncate = true;
 	}
 
@@ -961,8 +1013,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			truncate = true;
 	}
 
-	if (skb_cow_head(skb, dev->needed_headroom ?: t->hlen))
+	if (skb_cow_head(skb, dev->needed_headroom ?: t->hlen)) {
+		reason = SKB_DROP_REASON_NOMEM;
 		goto tx_err;
+	}
 
 	IPCB(skb)->flags = 0;
 
@@ -976,8 +1030,10 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 
 		tun_info = skb_tunnel_info_txcheck(skb);
 		if (IS_ERR(tun_info) ||
-		    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6))
+		    unlikely(ip_tunnel_info_af(tun_info) != AF_INET6)) {
+			reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 			goto tx_err;
+		}
 
 		key = &tun_info->key;
 		memset(&fl6, 0, sizeof(fl6));
@@ -989,10 +1045,14 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 
 		dsfield = key->tos;
 		if (!test_bit(IP_TUNNEL_ERSPAN_OPT_BIT,
-			      tun_info->key.tun_flags))
+			      tun_info->key.tun_flags)) {
+			reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 			goto tx_err;
-		if (tun_info->options_len < sizeof(*md))
+		}
+		if (tun_info->options_len < sizeof(*md)) {
+			reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 			goto tx_err;
+		}
 		md = ip_tunnel_info_opts(tun_info);
 
 		tun_id = tunnel_id_to_key32(key->tun_id);
@@ -1010,6 +1070,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 					       truncate, false);
 			proto = htons(ETH_P_ERSPAN2);
 		} else {
+			reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 			goto tx_err;
 		}
 	} else {
@@ -1020,11 +1081,16 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 						 &dsfield, &encap_limit);
 			break;
 		case htons(ETH_P_IPV6):
-			if (ipv6_addr_equal(&t->parms.raddr, &ipv6_hdr(skb)->saddr))
+			if (ipv6_addr_equal(&t->parms.raddr,
+					    &ipv6_hdr(skb)->saddr)) {
+				reason = SKB_DROP_REASON_RECURSION_LIMIT;
 				goto tx_err;
+			}
 			if (prepare_ip6gre_xmit_ipv6(skb, dev, &fl6,
-						     &dsfield, &encap_limit))
+						     &dsfield, &encap_limit)) {
+				reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;
 				goto tx_err;
+			}
 			break;
 		default:
 			memcpy(&fl6, &t->fl.u.ip6, sizeof(fl6));
@@ -1043,6 +1109,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 					       truncate, false);
 			proto = htons(ETH_P_ERSPAN2);
 		} else {
+			reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 			goto tx_err;
 		}
 
@@ -1061,7 +1128,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 			dst->ops->update_pmtu(dst, NULL, skb, mtu, false);
 	}
 	err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			   NEXTHDR_GRE);
+			   NEXTHDR_GRE, &reason);
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE) {
@@ -1080,7 +1147,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
 	if (!IS_ERR(tun_info))
 		DEV_STATS_INC(dev, tx_errors);
 	DEV_STATS_INC(dev, tx_dropped);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return NETDEV_TX_OK;
 }
 
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index d5ff50a2ac017..ab45601b2a68e 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -814,21 +814,29 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 			 bool log_ecn_err)
 {
 	const struct ipv6hdr *ipv6h;
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	int nh, err;
 
 	if (test_bit(IP_TUNNEL_CSUM_BIT, tunnel->parms.i_flags) !=
 	    test_bit(IP_TUNNEL_CSUM_BIT, tpi->flags)) {
 		DEV_STATS_INC(tunnel->dev, rx_crc_errors);
 		DEV_STATS_INC(tunnel->dev, rx_errors);
+		reason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;
 		goto drop;
 	}
 
 	if (test_bit(IP_TUNNEL_SEQ_BIT, tunnel->parms.i_flags)) {
-		if (!test_bit(IP_TUNNEL_SEQ_BIT, tpi->flags) ||
-		    (tunnel->i_seqno &&
-		     (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0)) {
+		if (!test_bit(IP_TUNNEL_SEQ_BIT, tpi->flags)) {
 			DEV_STATS_INC(tunnel->dev, rx_fifo_errors);
 			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH;
+			goto drop;
+		}
+		if (tunnel->i_seqno &&
+		    (s32)(ntohl(tpi->seq) - tunnel->i_seqno) < 0) {
+			DEV_STATS_INC(tunnel->dev, rx_fifo_errors);
+			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ;
 			goto drop;
 		}
 		tunnel->i_seqno = ntohl(tpi->seq) + 1;
@@ -838,7 +846,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 
 	/* Warning: All skb pointers will be invalidated! */
 	if (tunnel->dev->type == ARPHRD_ETHER) {
-		if (!pskb_may_pull(skb, ETH_HLEN)) {
+		reason = pskb_may_pull_reason(skb, ETH_HLEN);
+		if (reason) {
 			DEV_STATS_INC(tunnel->dev, rx_length_errors);
 			DEV_STATS_INC(tunnel->dev, rx_errors);
 			goto drop;
@@ -859,7 +868,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 
 	skb_reset_network_header(skb);
 
-	if (skb_vlan_inet_prepare(skb, true)) {
+	reason = skb_vlan_inet_prepare(skb, true);
+	if (reason) {
 		DEV_STATS_INC(tunnel->dev, rx_length_errors);
 		DEV_STATS_INC(tunnel->dev, rx_errors);
 		goto drop;
@@ -881,6 +891,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 		if (err > 1) {
 			DEV_STATS_INC(tunnel->dev, rx_frame_errors);
 			DEV_STATS_INC(tunnel->dev, rx_errors);
+			reason = SKB_DROP_REASON_IP_TUNNEL_ECN;
 			goto drop;
 		}
 	}
@@ -898,7 +909,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,
 drop:
 	if (tun_dst)
 		dst_release((struct dst_entry *)tun_dst);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return 0;
 }
 
@@ -1099,7 +1110,7 @@ EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);
 
 int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		 struct flowi6 *fl6, int encap_limit, __u32 *pmtu,
-		 __u8 proto)
+		 __u8 proto, enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct net *net = t->net;
@@ -1132,13 +1143,17 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 			struct neighbour *neigh;
 			int addr_type;
 
-			if (!skb_dst(skb))
+			if (!skb_dst(skb)) {
+				*reason = SKB_DROP_REASON_NO_TX_TARGET;
 				goto tx_err_link_failure;
+			}
 
 			neigh = dst_neigh_lookup(skb_dst(skb),
 						 &ipv6_hdr(skb)->daddr);
-			if (!neigh)
+			if (!neigh) {
+				*reason = SKB_DROP_REASON_NEIGH_CREATEFAIL;
 				goto tx_err_link_failure;
+			}
 
 			addr6 = (struct in6_addr *)&neigh->primary_key;
 			addr_type = ipv6_addr_type(addr6);
@@ -1151,8 +1166,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		} else if (payload_protocol == htons(ETH_P_IP)) {
 			const struct rtable *rt = skb_rtable(skb);
 
-			if (!rt)
+			if (!rt) {
+				*reason = SKB_DROP_REASON_IP_OUTNOROUTES;
 				goto tx_err_link_failure;
+			}
 
 			if (rt->rt_gw_family == AF_INET6)
 				memcpy(&fl6->daddr, &rt->rt_gw6, sizeof(fl6->daddr));
@@ -1169,8 +1186,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	if (use_cache)
 		dst = dst_cache_get(&t->dst_cache);
 
-	if (!ip6_tnl_xmit_ctl(t, &fl6->saddr, &fl6->daddr))
+	if (!ip6_tnl_xmit_ctl(t, &fl6->saddr, &fl6->daddr)) {
+		*reason = SKB_DROP_REASON_DEV_READY;
 		goto tx_err_link_failure;
+	}
 
 	if (!dst) {
 route_lookup:
@@ -1179,18 +1198,23 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 
 		dst = ip6_route_output(net, NULL, fl6);
 
-		if (dst->error)
+		if (dst->error) {
+			*reason = SKB_DROP_REASON_IP_OUTNOROUTES;
 			goto tx_err_link_failure;
+		}
 		dst = xfrm_lookup(net, dst, flowi6_to_flowi(fl6), NULL, 0);
 		if (IS_ERR(dst)) {
 			err = PTR_ERR(dst);
 			dst = NULL;
+			*reason = SKB_DROP_REASON_IP_OUTNOROUTES;
 			goto tx_err_link_failure;
 		}
 		if (t->parms.collect_md && ipv6_addr_any(&fl6->saddr) &&
 		    ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
-				       &fl6->daddr, 0, &fl6->saddr))
+				       &fl6->daddr, 0, &fl6->saddr)) {
+			*reason = SKB_DROP_REASON_NO_TX_TARGET;
 			goto tx_err_link_failure;
+		}
 		ndst = dst;
 	}
 
@@ -1200,6 +1224,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 		DEV_STATS_INC(dev, collisions);
 		net_warn_ratelimited("%s: Local routing loop detected!\n",
 				     t->parms.name);
+		*reason = SKB_DROP_REASON_RECURSION_LIMIT;
 		goto tx_err_dst_release;
 	}
 	mtu = dst6_mtu(dst) - eth_hlen - psh_hlen - t->tun_hlen;
@@ -1214,6 +1239,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	if (skb->len - t->tun_hlen - eth_hlen > mtu && !skb_is_gso(skb)) {
 		*pmtu = mtu;
 		err = -EMSGSIZE;
+		*reason = SKB_DROP_REASON_PKT_TOO_BIG;
 		goto tx_err_dst_release;
 	}
 
@@ -1236,12 +1262,16 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	 */
 	max_headroom += LL_RESERVED_SPACE(tdev);
 
-	if (skb_cow_head(skb, max_headroom))
+	if (skb_cow_head(skb, max_headroom)) {
+		*reason = SKB_DROP_REASON_NOMEM;
 		goto tx_err_dst_release;
+	}
 
 	if (t->parms.collect_md) {
-		if (t->encap.type != TUNNEL_ENCAP_NONE)
+		if (t->encap.type != TUNNEL_ENCAP_NONE) {
+			*reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;
 			goto tx_err_dst_release;
+		}
 	} else {
 		if (use_cache && ndst)
 			dst_cache_set_ip6(&t->dst_cache, ndst, &fl6->saddr);
@@ -1265,8 +1295,10 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	ip_tunnel_adj_headroom(dev, max_headroom);
 
 	err = ip6_tnl_encap(skb, t, &proto, fl6);
-	if (err)
+	if (err) {
+		*reason = SKB_DROP_REASON_IP_TUNNEL_ENCAP;
 		return err;
+	}
 
 	if (encap_limit >= 0) {
 		init_tel_txopt(&opt, encap_limit);
@@ -1295,7 +1327,7 @@ EXPORT_SYMBOL(ip6_tnl_xmit);
 
 static inline int
 ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
-		u8 protocol)
+		u8 protocol, enum skb_drop_reason *reason)
 {
 	struct ip6_tnl *t = netdev_priv(dev);
 	struct ipv6hdr *ipv6h;
@@ -1309,8 +1341,10 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 	int err;
 
 	tproto = READ_ONCE(t->parms.proto);
-	if (tproto != protocol && tproto != 0)
+	if (tproto != protocol && tproto != 0) {
+		*reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		return -1;
+	}
 
 	if (t->parms.collect_md) {
 		struct ip_tunnel_info *tun_info;
@@ -1318,8 +1352,10 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 
 		tun_info = skb_tunnel_info(skb);
 		if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) ||
-			     ip_tunnel_info_af(tun_info) != AF_INET6))
+			     ip_tunnel_info_af(tun_info) != AF_INET6)) {
+			*reason = SKB_DROP_REASON_TUNNEL_TXINFO;
 			return -1;
+		}
 		key = &tun_info->key;
 		memset(&fl6, 0, sizeof(fl6));
 		fl6.flowi6_proto = protocol;
@@ -1356,6 +1392,7 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 				if (tel->encap_limit == 0) {
 					icmpv6_ndo_send(skb, ICMPV6_PARAMPROB,
 							ICMPV6_HDR_FIELD, offset + 2);
+					*reason = SKB_DROP_REASON_IPV6_BAD_EXTHDR;
 					return -1;
 				}
 				encap_limit = tel->encap_limit - 1;
@@ -1397,13 +1434,15 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 	fl6.flowi6_uid = sock_net_uid(dev_net(dev), NULL);
 	dsfield = INET_ECN_encapsulate(dsfield, orig_dsfield);
 
-	if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6))
+	if (iptunnel_handle_offloads(skb, SKB_GSO_IPXIP6)) {
+		*reason = SKB_DROP_REASON_NOMEM;
 		return -1;
+	}
 
 	skb_set_inner_ipproto(skb, protocol);
 
 	err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
-			   protocol);
+			   protocol, reason);
 	if (err != 0) {
 		/* XXX: send ICMP error even if DF is not set. */
 		if (err == -EMSGSIZE)
@@ -1418,6 +1457,7 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 			default:
 				break;
 			}
+		*reason = SKB_DROP_REASON_PKT_TOO_BIG;
 		return -1;
 	}
 
@@ -1427,11 +1467,13 @@ ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,
 static netdev_tx_t
 ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
+	enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;
 	struct ip6_tnl *t = netdev_priv(dev);
 	u8 ipproto;
 	int ret;
 
-	if (!pskb_inet_may_pull(skb))
+	reason = pskb_inet_may_pull_reason(skb);
+	if (reason)
 		goto tx_err;
 
 	switch (skb->protocol) {
@@ -1439,18 +1481,21 @@ ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		ipproto = IPPROTO_IPIP;
 		break;
 	case htons(ETH_P_IPV6):
-		if (ip6_tnl_addr_conflict(t, ipv6_hdr(skb)))
+		if (ip6_tnl_addr_conflict(t, ipv6_hdr(skb))) {
+			reason = SKB_DROP_REASON_RECURSION_LIMIT;
 			goto tx_err;
+		}
 		ipproto = IPPROTO_IPV6;
 		break;
 	case htons(ETH_P_MPLS_UC):
 		ipproto = IPPROTO_MPLS;
 		break;
 	default:
+		reason = SKB_DROP_REASON_UNHANDLED_PROTO;
 		goto tx_err;
 	}
 
-	ret = ipxip6_tnl_xmit(skb, dev, ipproto);
+	ret = ipxip6_tnl_xmit(skb, dev, ipproto, &reason);
 	if (ret < 0)
 		goto tx_err;
 
@@ -1459,7 +1504,7 @@ ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)
 tx_err:
 	DEV_STATS_INC(dev, tx_errors);
 	DEV_STATS_INC(dev, tx_dropped);
-	kfree_skb(skb);
+	kfree_skb_reason(skb, reason);
 	return NETDEV_TX_OK;
 }
 
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 0f5c178bc224b..9acf364e8919e 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -117,6 +117,7 @@ TEST_PROGS := \
 	test_vxlan_vnifiltering.sh \
 	tfo_passive.sh \
 	traceroute.sh \
+	tunnel_drop_reasons.sh \
 	txtimestamp.sh \
 	udpgro.sh \
 	udpgro_bench.sh \
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index 30d5fcb09a831..281633ff3aa9d 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -14,6 +14,7 @@ CONFIG_CRYPTO_SM4_GENERIC=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
 CONFIG_DUMMY=y
+CONFIG_ENABLE_DEFAULT_TRACERS=y
 CONFIG_GENEVE=m
 CONFIG_IFB=y
 CONFIG_INET_DIAG=y
diff --git a/tools/testing/selftests/net/tunnel_drop_reasons.sh b/tools/testing/selftests/net/tunnel_drop_reasons.sh
new file mode 100755
index 0000000000000..5639e29365a4a
--- /dev/null
+++ b/tools/testing/selftests/net/tunnel_drop_reasons.sh
@@ -0,0 +1,346 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Test the drop reasons reported by the generic tunnel RX path,
+# ip_tunnel_rcv() and __ip6_tnl_rcv().
+#
+# Two situations are checked, for both GRE and ip6gre:
+#
+#  - the options carried by the packet do not match the tunnel
+#    configuration, which is reported as IP_TUNNEL_CFG_OPTS_MISMATCH.
+#    It is triggered here by configuring the receiver with 'iseq' or
+#    'icsum' while the sender emits neither.
+#
+#  - the sequence number of the packet is older than the one expected by
+#    the tunnel, which is reported as IP_TUNNEL_OLD_SEQ.  It is
+#    triggered here by recreating the tunnel device on the sender, which
+#    resets its outgoing sequence number the same way a peer reboot
+#    would.
+#
+# A control case, where both endpoints agree on the options, makes sure
+# that no tunnel drop reason is reported when packets are accepted.
+#
+# The GRE specific reasons are checked as well:
+#
+#  - a packet that matches no tunnel is reported as
+#    GRE_TUNNEL_NOT_FOUND.  It is triggered here by giving the two
+#    endpoints different keys.
+#
+# On the transmit side, the reasons reported while encapsulating are
+# checked too: a packet that does not fit the path MTU, a device in
+# external mode that receives no metadata, and a tunnel whose remote
+# endpoint has no route.
+#
+#  - a header with the routing bit set is reported as GRE_INVALID_HDR,
+#    and a header announcing a GRE version nobody handles is reported as
+#    UNHANDLED_PROTO.  Both are triggered by corrupting the GRE header
+#    on ingress with tc pedit, and are skipped if that is not available.
+#
+# Drop reasons are read from the skb:kfree_skb tracepoint.  A dedicated
+# trace instance is used so that the test does not disturb, and is not
+# disturbed by, anything else using the tracing facility.
+
+source lib.sh
+
+NS_SND=""
+NS_RCV=""
+TRACE_DIR=""
+TR=""
+
+SND_V4=10.0.0.1
+RCV_V4=10.0.0.2
+SND_V6=2001:db8::1
+RCV_V6=2001:db8::2
+TUN_SND=192.168.1.1
+TUN_RCV=192.168.1.2
+
+cleanup()
+{
+	if [ -n "$TR" ]; then
+		echo 0 > "$TR/events/skb/kfree_skb/enable" 2>/dev/null
+		rmdir "$TR" 2>/dev/null
+	fi
+	cleanup_all_ns
+}
+
+trap cleanup EXIT
+
+setup_tracing()
+{
+	local dir
+
+	for dir in /sys/kernel/tracing /sys/kernel/debug/tracing; do
+		if [ -f "$dir/trace" ]; then
+			TRACE_DIR="$dir"
+			break
+		fi
+	done
+	[ -n "$TRACE_DIR" ] || return 1
+	[ -d "$TRACE_DIR/instances" ] || return 1
+	[ -e "$TRACE_DIR/events/skb/kfree_skb" ] || return 1
+
+	TR="$TRACE_DIR/instances/tunnel_drop_reasons"
+	mkdir "$TR" 2>/dev/null || return 1
+	echo 1 > "$TR/events/skb/kfree_skb/enable" || return 1
+}
+
+setup_ns_pair()
+{
+	PING_ARGS=""
+	cleanup_all_ns
+	setup_ns NS_SND NS_RCV
+
+	ip link add veth_s netns "$NS_SND" type veth \
+		peer name veth_r netns "$NS_RCV"
+	ip -n "$NS_SND" link set veth_s up
+	ip -n "$NS_RCV" link set veth_r up
+
+	ip -n "$NS_SND" addr add "$SND_V4/24" dev veth_s
+	ip -n "$NS_RCV" addr add "$RCV_V4/24" dev veth_r
+	ip -n "$NS_SND" addr add "$SND_V6/64" dev veth_s nodad
+	ip -n "$NS_RCV" addr add "$RCV_V6/64" dev veth_r nodad
+}
+
+# $1: namespace, $2: local, $3: remote, $4...: tunnel options
+add_gre()
+{
+	local ns=$1 loc=$2 rem=$3
+
+	shift 3
+	ip -n "$ns" link add gre_test type gre local "$loc" remote "$rem" "$@"
+	ip -n "$ns" link set gre_test up
+}
+
+# $1: namespace, $2: local, $3: remote, $4...: tunnel options
+add_ip6gre()
+{
+	local ns=$1 loc=$2 rem=$3
+
+	shift 3
+	ip -n "$ns" link add gre_test type ip6gre local "$loc" remote "$rem" \
+		"$@"
+	ip -n "$ns" link set gre_test up
+}
+
+addr_tunnels()
+{
+	ip -n "$NS_SND" addr add "$TUN_SND/24" dev gre_test
+	ip -n "$NS_RCV" addr add "$TUN_RCV/24" dev gre_test
+}
+
+# Traffic used by check_reason().  Tests that need something else set
+# PING_ARGS before calling it.
+PING_ARGS=""
+
+send_traffic()
+{
+	# shellcheck disable=SC2086
+	ip netns exec "$NS_SND" ping -c 2 -W 1 $PING_ARGS "$TUN_RCV" \
+		>/dev/null 2>&1
+	# Let the tracepoint records reach the trace buffer.
+	sleep 1
+}
+
+# $1: test name, $2: expected reason, empty if none is expected
+check_reason()
+{
+	local name=$1 want=$2 count
+
+	echo > "$TR/trace"
+	send_traffic
+
+	if [ -n "$want" ]; then
+		count=$(grep -c "reason: $want" "$TR/trace")
+		if [ "$count" -gt 0 ]; then
+			RET=$ksft_pass
+		else
+			RET=$ksft_fail
+		fi
+		log_test "$name" "$count dropped"
+	else
+		count=$(grep -c "reason: IP_TUNNEL_" "$TR/trace")
+		if [ "$count" -eq 0 ]; then
+			RET=$ksft_pass
+		else
+			RET=$ksft_fail
+		fi
+		log_test "$name" "$count dropped"
+	fi
+}
+
+test_opts_mismatch()
+{
+	local proto=$1 opt=$2
+	local add=add_gre loc=$SND_V4 rem=$RCV_V4
+
+	if [ "$proto" = "ip6gre" ]; then
+		add=add_ip6gre
+		loc=$SND_V6
+		rem=$RCV_V6
+	fi
+
+	setup_ns_pair
+	# The sender emits no option, the receiver expects one.
+	$add "$NS_SND" "$loc" "$rem"
+	$add "$NS_RCV" "$rem" "$loc" "$opt"
+	addr_tunnels
+
+	check_reason "$proto: $opt option mismatch" \
+		IP_TUNNEL_CFG_OPTS_MISMATCH
+}
+
+test_old_seq()
+{
+	local proto=$1
+	local add=add_gre loc=$SND_V4 rem=$RCV_V4
+
+	if [ "$proto" = "ip6gre" ]; then
+		add=add_ip6gre
+		loc=$SND_V6
+		rem=$RCV_V6
+	fi
+
+	setup_ns_pair
+	$add "$NS_SND" "$loc" "$rem" oseq
+	$add "$NS_RCV" "$rem" "$loc" iseq
+	addr_tunnels
+
+	# Raise the sequence number expected by the receiver, then reset the
+	# one used by the sender, as a peer reboot would do.
+	send_traffic
+	ip -n "$NS_SND" link del gre_test
+	$add "$NS_SND" "$loc" "$rem" oseq
+	ip -n "$NS_SND" addr add "$TUN_SND/24" dev gre_test
+
+	check_reason "$proto: old sequence number" IP_TUNNEL_OLD_SEQ
+}
+
+test_control()
+{
+	setup_ns_pair
+	add_gre "$NS_SND" "$SND_V4" "$RCV_V4" oseq ocsum
+	add_gre "$NS_RCV" "$RCV_V4" "$SND_V4" iseq icsum
+	addr_tunnels
+
+	check_reason "gre: matching configuration (control)" ""
+}
+
+# Corrupt one field of the GRE header of every IPv4 packet received by
+# the receiver.  $1 is a tc pedit munge expression, with offsets counted
+# from the start of the IPv4 header.
+corrupt_gre_header()
+{
+	ip netns exec "$NS_RCV" tc qdisc add dev veth_r ingress || return 1
+	ip netns exec "$NS_RCV" tc filter add dev veth_r ingress \
+		protocol ip matchall action pedit ex munge "$@" || return 1
+}
+
+test_tunnel_not_found()
+{
+	setup_ns_pair
+	# The two endpoints use different keys, so the lookup on the
+	# receiver finds no tunnel for the incoming packets.
+	add_gre "$NS_SND" "$SND_V4" "$RCV_V4" okey 1 ikey 1
+	add_gre "$NS_RCV" "$RCV_V4" "$SND_V4" okey 2 ikey 2
+	addr_tunnels
+
+	check_reason "gre: tunnel not found" GRE_TUNNEL_NOT_FOUND
+}
+
+# $1: test name, $2: expected reason, $3...: tc pedit munge expression
+test_corrupted_header()
+{
+	local name=$1 want=$2
+
+	shift 2
+	setup_ns_pair
+	add_gre "$NS_SND" "$SND_V4" "$RCV_V4"
+	add_gre "$NS_RCV" "$RCV_V4" "$SND_V4"
+	addr_tunnels
+
+	if ! corrupt_gre_header "$@" 2>/dev/null; then
+		log_test_skip "$name"
+		return
+	fi
+
+	check_reason "$name" "$want"
+}
+
+test_tx_pkt_too_big()
+{
+	setup_ns_pair
+	# The underlay cannot carry what the tunnel advertises, so the
+	# encapsulated packet does not fit the path MTU.  The kernel sends
+	# an ICMP fragmentation needed back and drops it, which is path MTU
+	# discovery working as intended.
+	ip -n "$NS_SND" link set veth_s mtu 1280
+	ip -n "$NS_RCV" link set veth_r mtu 1280
+	add_gre "$NS_SND" "$SND_V4" "$RCV_V4"
+	add_gre "$NS_RCV" "$RCV_V4" "$SND_V4"
+	ip -n "$NS_SND" link set gre_test mtu 1500
+	addr_tunnels
+
+	PING_ARGS="-s 1400 -M do"
+	check_reason "gre: packet does not fit the path MTU" PKT_TOO_BIG
+}
+
+test_tx_no_metadata()
+{
+	setup_ns_pair
+	# A device in external mode expects the destination to come from
+	# the tunnel metadata, which plain traffic does not carry.
+	ip -n "$NS_SND" link add gre_test type gre external
+	ip -n "$NS_SND" link set gre_test up
+	ip -n "$NS_SND" addr add "$TUN_SND/24" dev gre_test
+
+	check_reason "gre: external mode without metadata" TUNNEL_TXINFO
+}
+
+test_tx_no_route()
+{
+	setup_ns_pair
+	# Nothing knows how to reach the remote endpoint of the tunnel.
+	add_gre "$NS_SND" "$SND_V4" 172.31.255.254
+	ip -n "$NS_SND" addr add "$TUN_SND/24" dev gre_test
+
+	check_reason "gre: no route to the remote endpoint" IP_OUTNOROUTES
+}
+
+if [ "$(id -u)" -ne 0 ]; then
+	echo "SKIP: need root"
+	exit "$ksft_skip"
+fi
+
+if ! setup_tracing; then
+	echo "SKIP: could not set up a trace instance for skb:kfree_skb"
+	exit "$ksft_skip"
+fi
+
+test_opts_mismatch gre iseq
+test_opts_mismatch gre icsum
+test_control
+test_old_seq gre
+
+test_tunnel_not_found
+# The routing bit is the second most significant bit of the first byte
+# of the GRE header, which follows the 20 byte IPv4 header.
+test_corrupted_header "gre: routing bit set" GRE_INVALID_HDR \
+	offset 20 u8 set 0x40
+# The GRE version sits in the low bits of the next byte.  Version 1 is
+# PPTP, which has no handler here.
+test_corrupted_header "gre: unhandled GRE version" UNHANDLED_PROTO \
+	offset 21 u8 set 0x01
+
+test_tx_pkt_too_big
+test_tx_no_metadata
+test_tx_no_route
+
+if [ -e /proc/sys/net/ipv6 ]; then
+	test_opts_mismatch ip6gre iseq
+	test_old_seq ip6gre
+else
+	log_test_skip "ip6gre: iseq option mismatch"
+	log_test_skip "ip6gre: old sequence number"
+fi
+
+exit "$EXIT_STATUS"

3/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 30470
							output: 19
							thoughts: 1224
						

Thoughts:
**Analyzing the Patch for Fuzzing Potential**

Okay, let's break this patch down and figure out if it's worth fuzzing. My immediate thought is to determine if this introduces new functionality or just refactors existing code for better debugging.

First, I see a substantial number of changes across networking components, specifically involving the addition of several `SKB_DROP_REASON_*` enum values and their propagation through the code. The functions modified include `gre_parse_header`, `erspan_rcv`, and a whole slew of `*_xmit` functions related to GRE and IP tunnels, for both IPv4 and IPv6. Crucially, I notice that these changes involve replacing calls to `kfree_skb` with `kfree_skb_reason`, suggesting that the drop reasons are going to the `skb:kfree_skb` tracepoint, if that's enabled.

Now, before I get too deep, I should probably check the instructions and constraints. Right, it looks like I need to filter out certain changes: documentation, Kconfig changes, comments, purely decorative changes like logging or tracepoints and changes to numeric constants or macros that don't alter execution. I see `kfree_skb_reason` being used, so I'm not sure if that is considered a "decorative change" or if it alters execution flow, since the patch is providing more detailed debug information, so I need to investigate.

Let's dig a bit deeper. I see `include/net/dropreason-core.h` defining the new enum values, which is definitely a new feature. In `net/ipv4/gre_demux.c`, the signature of `gre_parse_header` changed to take an `enum skb_drop_reason *reason` argument. The code now uses `pskb_may_pull_reason` instead of the old `pskb_may_pull` calls. This seems to be the core change, propagating drop reasons upwards.

I should verify whether the execution logic changed, or just the error conditions. I can see that inside `gre_parse_header`, the code now sets the `reason` to `SKB_DROP_REASON_HDR_TRUNC` before returning an error in one of the code paths. In `net/ipv4/ip_tunnel.c`, the patch seems to have split up an `if` condition with separate `goto drop` paths, setting the `reason` to `SKB_DROP_REASON_IP_TUNNEL_CFG_OPTS_MISMATCH` or `SKB_DROP_REASON_IP_TUNNEL_OLD_SEQ` accordingly. Similar changes are in `ip6_tunnel.c`. Okay, so it looks like it did alter execution flow, which is exactly what I was looking for.

Now, I should determine if this change affects any more parts of the code. Let's use grepper to find any other callers of `gre_parse_header` or `ip6_tnl_xmit`.



4/2 2026/09/01 05:55 tool grepper
0m Args:
{
  "Expression": "gre_parse_header"
}

Results:
{
  "Output": "include/net/gre.h=33=int gre_del_protocol(const struct gre_protocol *proto, u8 version);\ninclude/net/gre.h-34-\ninclude/net/gre.h:35:int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\ninclude/net/gre.h-36-\t\t     enum skb_drop_reason *reason, __be16 proto, int nhs);\n--\nnet/ipv4/gre_demux.c=57=EXPORT_SYMBOL_GPL(gre_del_protocol);\n--\nnet/ipv4/gre_demux.c-69- */\nnet/ipv4/gre_demux.c:70:int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,\nnet/ipv4/gre_demux.c-71-\t\t     enum skb_drop_reason *reason, __be16 proto, int nhs)\n--\nnet/ipv4/gre_demux.c-166-}\nnet/ipv4/gre_demux.c:167:EXPORT_SYMBOL(gre_parse_header);\nnet/ipv4/gre_demux.c-168-\n--\nnet/ipv4/ip_gre.c=219=static void gre_err(struct sk_buff *skb, u32 info)\n--\nnet/ipv4/ip_gre.c-239-\nnet/ipv4/ip_gre.c:240:\tif (gre_parse_header(skb, \u0026tpi, NULL, htons(ETH_P_IP),\nnet/ipv4/ip_gre.c-241-\t\t\t     iph-\u003eihl * 4) \u003c 0)\n--\nnet/ipv4/ip_gre.c=451=static int gre_rcv(struct sk_buff *skb)\n--\nnet/ipv4/ip_gre.c-464-\nnet/ipv4/ip_gre.c:465:\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026reason, htons(ETH_P_IP), 0);\nnet/ipv4/ip_gre.c-466-\tif (hdr_len \u003c 0)\n--\nnet/ipv6/ip6_gre.c=387=static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,\n--\nnet/ipv6/ip6_gre.c-394-\nnet/ipv6/ip6_gre.c:395:\tif (gre_parse_header(skb, \u0026tpi, NULL, htons(ETH_P_IPV6),\nnet/ipv6/ip6_gre.c-396-\t\t\t     offset) \u003c 0)\n--\nnet/ipv6/ip6_gre.c=584=static int gre_rcv(struct sk_buff *skb)\n--\nnet/ipv6/ip6_gre.c-589-\nnet/ipv6/ip6_gre.c:590:\thdr_len = gre_parse_header(skb, \u0026tpi, \u0026reason, htons(ETH_P_IPV6), 0);\nnet/ipv6/ip6_gre.c-591-\tif (hdr_len \u003c 0)\n"
}

5/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 33200
							output: 22
							thoughts: 14
						

Thoughts:
Here's a summary of my thought process, as if I were analyzing `ip6_tnl_xmit`:

**Diving into `ip6_tnl_xmit`**

Okay, time to dissect `ip6_tnl_xmit`. First, I need to understand its role. It's clear from the name that this function handles the transmission of IPv6 packets encapsulated within a tunnel. That narrows the focus considerably. I need to figure out the specifics of this transmission process. What are the key steps involved? I'm thinking: header construction, address resolution (if applicable, depending on the tunnel type), fragmentation if the packet is too large, and then, crucially, the actual transmission over the underlying network interface.

I need to quickly grasp the data structures it uses, particularly any tunnel-specific contexts or control blocks. These structures will reveal how the encapsulation is managed—the IPv6 header insertion, potential GRE or other protocol headers, and any relevant options. I'll be looking for things like MTU handling within the tunnel and any error checking or rate limiting mechanisms.

I will also expect this to leverage existing networking infrastructure, so it is important to find the functions it calls to transmit the actual packet. What is it calling? What is the datapath for the transmission? Are there any potential inefficiencies or bottlenecks in this path?

Ultimately, I want to assess its efficiency, security considerations (especially related to header manipulation and potential for fragmentation attacks or DoS), and its interaction with other parts of the networking stack. Does it handle checksums properly? Does it correctly implement any required path MTU discovery or fragmentation handling? Does it have any known vulnerabilities? I want a robust understanding of the underlying logic and its implications for network performance and security. Let's dig in.



6/2 2026/09/01 05:55 tool grepper
0m Args:
{
  "Expression": "ip6_tnl_xmit"
}

Results:
{
  "Output": "drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c=521=mlxsw_sp_span_gretap6_route(const struct net_device *to_dev,\n--\ndrivers/net/ethernet/mellanox/mlxsw/spectrum_span.c-534-\tfl6.flowi6_mark = t-\u003eparms.fwmark;\ndrivers/net/ethernet/mellanox/mlxsw/spectrum_span.c:535:\tif (!ip6_tnl_xmit_ctl(t, \u0026fl6.saddr, \u0026fl6.daddr))\ndrivers/net/ethernet/mellanox/mlxsw/spectrum_span.c-536-\t\treturn NULL;\n--\ninclude/net/ip6_tunnel.h=140=int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,\n--\ninclude/net/ip6_tunnel.h-142-\t\tbool log_ecn_error);\ninclude/net/ip6_tunnel.h:143:int ip6_tnl_xmit_ctl(struct ip6_tnl *t, const struct in6_addr *laddr,\ninclude/net/ip6_tunnel.h-144-\t\t     const struct in6_addr *raddr);\ninclude/net/ip6_tunnel.h:145:int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\ninclude/net/ip6_tunnel.h-146-\t\t struct flowi6 *fl6, int encap_limit, __u32 *pmtu, __u8 proto,\n--\nnet/ipv6/ip6_gre.c=734=static netdev_tx_t __gre6_xmit(struct sk_buff *skb,\n--\nnet/ipv6/ip6_gre.c-810-\nnet/ipv6/ip6_gre.c:811:\treturn ip6_tnl_xmit(skb, dev, dsfield, fl6, encap_limit, pmtu,\nnet/ipv6/ip6_gre.c-812-\t\t\t    NEXTHDR_GRE, reason);\n--\nnet/ipv6/ip6_gre.c=918=static netdev_tx_t ip6gre_tunnel_xmit(struct sk_buff *skb,\n--\nnet/ipv6/ip6_gre.c-929-\nnet/ipv6/ip6_gre.c:930:\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr)) {\nnet/ipv6/ip6_gre.c-931-\t\treason = SKB_DROP_REASON_DEV_READY;\n--\nnet/ipv6/ip6_gre.c=961=static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,\n--\nnet/ipv6/ip6_gre.c-981-\nnet/ipv6/ip6_gre.c:982:\tif (!ip6_tnl_xmit_ctl(t, \u0026t-\u003eparms.laddr, \u0026t-\u003eparms.raddr)) {\nnet/ipv6/ip6_gre.c-983-\t\treason = SKB_DROP_REASON_DEV_READY;\n--\nnet/ipv6/ip6_gre.c-1129-\t}\nnet/ipv6/ip6_gre.c:1130:\terr = ip6_tnl_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\nnet/ipv6/ip6_gre.c-1131-\t\t\t   NEXTHDR_GRE, \u0026reason);\n--\nnet/ipv6/ip6_tunnel.c=1048=ip6_tnl_addr_conflict(const struct ip6_tnl *t, const struct ipv6hdr *hdr)\n--\nnet/ipv6/ip6_tunnel.c-1052-\nnet/ipv6/ip6_tunnel.c:1053:int ip6_tnl_xmit_ctl(struct ip6_tnl *t,\nnet/ipv6/ip6_tunnel.c-1054-\t\t     const struct in6_addr *laddr,\n--\nnet/ipv6/ip6_tunnel.c-1088-}\nnet/ipv6/ip6_tunnel.c:1089:EXPORT_SYMBOL_GPL(ip6_tnl_xmit_ctl);\nnet/ipv6/ip6_tunnel.c-1090-\nnet/ipv6/ip6_tunnel.c-1091-/**\nnet/ipv6/ip6_tunnel.c:1092: * ip6_tnl_xmit - encapsulate packet and send\nnet/ipv6/ip6_tunnel.c-1093- *   @skb: the outgoing socket buffer\n--\nnet/ipv6/ip6_tunnel.c-1110-\nnet/ipv6/ip6_tunnel.c:1111:int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,\nnet/ipv6/ip6_tunnel.c-1112-\t\t struct flowi6 *fl6, int encap_limit, __u32 *pmtu,\n--\nnet/ipv6/ip6_tunnel.c-1188-\nnet/ipv6/ip6_tunnel.c:1189:\tif (!ip6_tnl_xmit_ctl(t, \u0026fl6-\u003esaddr, \u0026fl6-\u003edaddr)) {\nnet/ipv6/ip6_tunnel.c-1190-\t\t*reason = SKB_DROP_REASON_DEV_READY;\n--\nnet/ipv6/ip6_tunnel.c-1325-}\nnet/ipv6/ip6_tunnel.c:1326:EXPORT_SYMBOL(ip6_tnl_xmit);\nnet/ipv6/ip6_tunnel.c-1327-\nnet/ipv6/ip6_tunnel.c=1328=static inline int\nnet/ipv6/ip6_tunnel.c:1329:ipxip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev,\nnet/ipv6/ip6_tunnel.c-1330-\t\tu8 protocol, enum skb_drop_reason *reason)\n--\nnet/ipv6/ip6_tunnel.c-1443-\nnet/ipv6/ip6_tunnel.c:1444:\terr = ip6_tnl_xmit(skb, dev, dsfield, \u0026fl6, encap_limit, \u0026mtu,\nnet/ipv6/ip6_tunnel.c-1445-\t\t\t   protocol, reason);\n--\nnet/ipv6/ip6_tunnel.c=1468=ip6_tnl_start_xmit(struct sk_buff *skb, struct net_device *dev)\n--\nnet/ipv6/ip6_tunnel.c-1497-\nnet/ipv6/ip6_tunnel.c:1498:\tret = ipxip6_tnl_xmit(skb, dev, ipproto, \u0026reason);\nnet/ipv6/ip6_tunnel.c-1499-\tif (ret \u003c 0)\n--\nnet/ipv6/ip6_vti.c=443=vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)\n--\nnet/ipv6/ip6_vti.c-497-\nnet/ipv6/ip6_vti.c:498:\tif (!ip6_tnl_xmit_ctl(t, (const struct in6_addr *)\u0026x-\u003eprops.saddr,\nnet/ipv6/ip6_vti.c-499-\t\t\t      (const struct in6_addr *)\u0026x-\u003eid.daddr))\n"
}

7/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 35617
							output: 22
							thoughts: 316
						

Thoughts:
**Analyzing the Patch's Suitability for Fuzzing**

Okay, let's break down these instructions. I need to figure out if this patch is worth fuzzing, and the guidelines are pretty clear. I should return `WorthFuzzing=false` if the changes fall into specific categories. Let's see: documentation, Kconfig, comments... those are obvious no-gos. Decorative changes, like logging – `pr_err`, `printk` – or tracepoints? Nope. Numeric changes that don't affect execution flow? Still no. Unreachable code paths in virtualized environments, like those that rely on specific emulated hardware not present in standard setups? That's a clear exclusion. And then there are those vendor-specific drivers that need actual PCIe hardware… definitely not fuzzable in a standard environment. Finally, the `.remove`, `.shutdown`, and `pci_unregister_driver` teardown callbacks that only trigger during PCI hot-unplug or driver unbinding? Those are also out.

So, this patch... it's all about adding drop reasons to `skb` drops and including a selftest. Hmm, that `kfree_skb_reason` stuff is a bit of a flag. I *think* that's related to tracepoints, but I need to be absolutely sure. My intuition is telling me this is purely related to tracing and the added selftest is likely testing these tracing mechanisms, but I need to confirm. I should definitely double-check the definition and how `kfree_skb_reason` is actually used. Need to see if it does *anything* beyond just being a tracepoint. Let's go look at its definition and usage.



8/2 2026/09/01 05:55 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "void kfree_skb_reason"
}

Results:
{
  "error": "no matches"
}

9/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 36326
							output: 31
							thoughts: 17
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Hunting Down `kfree_skb_reason`**

Alright, let's track down the `kfree_skb_reason` function within the codebase. It's time to dig in and understand precisely where and why it's being used. I need to figure out what's causing this memory management action. I'm expecting to see calls to this function sprinkled throughout the network stack, likely tied to error handling, resource exhaustion, or possibly even debugging assertions related to SKB lifecycle management. Depending on the kernel version and networking implementation, there may be some indirect calls via inline functions or macros that I'll need to account for. Let's see if grep can narrow down the candidates and help me understand the context of the memory deallocation. I'm also considering checking the documentation or any relevant kernel tracing options that can provide further insights.



10/2 2026/09/01 05:55 tool grepper
0m Args:
{
  "Expression": "kfree_skb_reason",
  "PathPrefix": "net/core/"
}

Results:
{
  "Output": "net/core/dev.c=3511=void dev_kfree_skb_any_reason(struct sk_buff *skb, enum skb_drop_reason reason)\n--\nnet/core/dev.c-3515-\telse\nnet/core/dev.c:3516:\t\tkfree_skb_reason(skb, reason);\nnet/core/dev.c-3517-}\n--\nnet/core/dev.c=4233=static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,\n--\nnet/core/dev.c-4286-\t\t\tif (unlikely(defer_count \u003e READ_ONCE(net_hotdata.qdisc_max_burst))) {\nnet/core/dev.c:4287:\t\t\t\tkfree_skb_reason(skb, SKB_DROP_REASON_QDISC_BURST_DROP);\nnet/core/dev.c-4288-\t\t\t\treturn NET_XMIT_DROP;\n--\nnet/core/dev.c=4513=sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,\n--\nnet/core/dev.c-4555-\tcase TC_ACT_SHOT:\nnet/core/dev.c:4556:\t\tkfree_skb_reason(skb, drop_reason);\nnet/core/dev.c-4557-\t\t*ret = NET_RX_DROP;\n--\nnet/core/dev.c=4577=sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)\n--\nnet/core/dev.c-4606-\tcase TC_ACT_SHOT:\nnet/core/dev.c:4607:\t\tkfree_skb_reason(skb, drop_reason);\nnet/core/dev.c-4608-\t\t*ret = NET_XMIT_DROP;\n--\nnet/core/dev.c=4819=int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)\n--\nnet/core/dev.c-4837-\t\tdev_core_stats_tx_dropped_inc(dev);\nnet/core/dev.c:4838:\t\tkfree_skb_reason(skb, reason);\nnet/core/dev.c-4839-\t\treturn -EINVAL;\n--\nnet/core/dev.c=5429=static int enqueue_to_backlog(struct sk_buff *skb, int cpu,\n--\nnet/core/dev.c-5478-\tdev_core_stats_rx_dropped_inc(skb-\u003edev);\nnet/core/dev.c:5479:\tkfree_skb_reason(skb, reason);\nnet/core/dev.c-5480-\treturn NET_RX_DROP;\n--\nnet/core/dev.c=5718=int do_xdp_generic(const struct bpf_prog *xdp_prog, struct sk_buff **pskb)\n--\nnet/core/dev.c-5748-\tbpf_net_ctx_clear(bpf_net_ctx);\nnet/core/dev.c:5749:\tkfree_skb_reason(*pskb, SKB_DROP_REASON_XDP);\nnet/core/dev.c-5750-\treturn XDP_DROP;\n--\nnet/core/dev.c=6034=static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,\n--\nnet/core/dev.c-6237-\nnet/core/dev.c:6238:\t\tkfree_skb_reason(skb, drop_reason);\nnet/core/dev.c-6239-\t\t/* Jamal, now you will not able to escape explaining\n--\nnet/core/neighbour.c=1202=int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb,\n--\nnet/core/neighbour.c-1239-\nnet/core/neighbour.c:1240:\t\t\tkfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_FAILED);\nnet/core/neighbour.c-1241-\t\t\treturn 1;\n--\nnet/core/neighbour.c-1261-\t\t\t\tneigh-\u003earp_queue_len_bytes -= buff-\u003etruesize;\nnet/core/neighbour.c:1262:\t\t\t\tkfree_skb_reason(buff, SKB_DROP_REASON_NEIGH_QUEUEFULL);\nnet/core/neighbour.c-1263-\t\t\t\tNEIGH_CACHE_STAT_INC(neigh-\u003etbl, unres_discards);\n--\nnet/core/neighbour.c-1283-\twrite_unlock_bh(\u0026neigh-\u003elock);\nnet/core/neighbour.c:1284:\tkfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_DEAD);\nnet/core/neighbour.c-1285-\ttrace_neigh_event_send_dead(neigh, 1);\n--\nnet/core/neighbour.c=1596=int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)\n--\nnet/core/neighbour.c-1623-\trc = -EINVAL;\nnet/core/neighbour.c:1624:\tkfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_HH_FILLFAIL);\nnet/core/neighbour.c-1625-\tgoto out;\n--\nnet/core/neighbour.c=1631=int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)\n--\nnet/core/neighbour.c-1647-\t\terr = -EINVAL;\nnet/core/neighbour.c:1648:\t\tkfree_skb_reason(skb, SKB_DROP_REASON_NEIGH_HH_FILLFAIL);\nnet/core/neighbour.c-1649-\t}\n"
}

11/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 38120
							output: 23
							thoughts: 16
						

Thoughts:
Okay, let's dive into this `kfree_skb_reason` function. I'm going to approach this with the assumption that I understand the basics of `skb`s (Socket Buffer) and kernel memory management. My goal is to quickly grasp the core purpose of this specific function, and how it differs from a simple `kfree`. I need to understand its nuances, and how its usage ties into more complex logic in the network stack.

**Diving into `kfree_skb_reason` Implementation**

Alright, I need to see how they've implemented the "reason" part here. Does it just add an argument to the normal `kfree`, or is there something more substantial going on? Is this some sort of debugging aid, perhaps tracing buffer deallocation in certain scenarios? Maybe it's about logging deallocation events to track down memory leaks or pinpoint where packets are being dropped unnecessarily. I'll need to figure out if the "reason" is just an enumerated type, a bitmask, or if it involves a more sophisticated mechanism for capturing context about why the `skb` is being freed. I'll be looking for any indications of extra overhead, like tracing calls, additional memory writes, or any interactions with debug or statistics facilities. I'm hoping to quickly understand whether this has significant performance implications, if it's meant for production use, or if it's primarily a development and debugging tool. I'm also curious about its integration with any existing memory management subsystems. Ultimately, I'll need to assess its usefulness in a real-world debugging context.



12/2 2026/09/01 05:55 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "void kfree_skb_reason\\("
}

Results:
{
  "error": "no matches"
}

13/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 38507
							output: 35
							thoughts: 24
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into SKB Deallocation**

Okay, so I need to understand something related to how SKBs are freed, likely to debug a memory issue or optimize performance. "kfree_skb_reason" feels like the right place to start – it suggests a function involved in deallocating SKBs (socket buffer) with some level of reason or context. Immediately, I'm thinking, "net/core/skbuff.c" is the most logical location for it. This is the heart of the SKB management in the kernel network stack, and it's where core deallocation functions reside. Time to get my hands dirty.



14/2 2026/09/01 05:55 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "kfree_skb_reason",
  "PathPrefix": "net/core/skbuff.c"
}

Results:
{
  "error": "no matches"
}

15/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 38733
							output: 29
							thoughts: 26
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:

**Locating `kfree_skb_reason`**

Okay, so I need to track down the definition of `kfree_skb_reason`. My gut feeling is that this is likely a macro or function related to debugging or tracing of memory management within the networking stack. Given its name, it's pretty clearly related to freeing `sk_buff` structures.

The most logical place to start looking is within the kernel's include files, specifically under `include/`. I'll first check there, as it could be a simple inline function or a macro defined for use across the kernel. Failing that, and considering its networking-specific nature, I'll then move my search to the `net/` directory. That's the obvious home for anything directly involved with networking code. I will use tools, `grep` or maybe `find` with `grep`, to efficiently search the files in those directories to locate the definition of this symbol. I will also be mindful of possible namespace issues, and check include paths in common networking source files, just in case. The objective is to identify how this thing works, its purpose and in which contexts it is being used.



16/2 2026/09/01 05:55 tool grepper
0m Args:
{
  "Expression": "kfree_skb_reason",
  "PathPrefix": "include/"
}

Results:
{
  "Output": "include/linux/netfilter.h=26=NF_DROP_REASON(struct sk_buff *skb, enum skb_drop_reason reason, u32 err)\n--\ninclude/linux/netfilter.h-29-\ninclude/linux/netfilter.h:30:\tkfree_skb_reason(skb, reason);\ninclude/linux/netfilter.h-31-\n--\ninclude/linux/skbuff.h=1320=static inline void\ninclude/linux/skbuff.h:1321:kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)\ninclude/linux/skbuff.h-1322-{\n--\ninclude/linux/skbuff.h=1330=static inline void kfree_skb(struct sk_buff *skb)\ninclude/linux/skbuff.h-1331-{\ninclude/linux/skbuff.h:1332:\tkfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);\ninclude/linux/skbuff.h-1333-}\n--\ninclude/linux/skbuff.h=3459=static inline void __skb_queue_purge_reason(struct sk_buff_head *list,\n--\ninclude/linux/skbuff.h-3464-\twhile ((skb = __skb_dequeue(list)) != NULL)\ninclude/linux/skbuff.h:3465:\t\tkfree_skb_reason(skb, reason);\ninclude/linux/skbuff.h-3466-}\n--\ninclude/net/dropreason-core.h-141- *\ninclude/net/dropreason-core.h:142: * The reason of skb drop, which is used in kfree_skb_reason().\ninclude/net/dropreason-core.h-143- */\n--\ninclude/net/ip6_tunnel.h=155=static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,\n--\ninclude/net/ip6_tunnel.h-165-\t\t}\ninclude/net/ip6_tunnel.h:166:\t\tkfree_skb_reason(skb, SKB_DROP_REASON_RECURSION_LIMIT);\ninclude/net/ip6_tunnel.h-167-\t\treturn;\n--\ninclude/net/ipv6_frag.h=65=ip6frag_expire_frag_queue(struct net *net, struct frag_queue *fq)\n--\ninclude/net/ipv6_frag.h-108-\ticmpv6_send(head, ICMPV6_TIME_EXCEED, ICMPV6_EXC_FRAGTIME, 0);\ninclude/net/ipv6_frag.h:109:\tkfree_skb_reason(head, SKB_DROP_REASON_FRAG_REASM_TIMEOUT);\ninclude/net/ipv6_frag.h-110-\tgoto out_rcu_unlock;\n--\ninclude/net/sch_generic.h=1227=static inline void qdisc_dequeue_drop(struct Qdisc *q, struct sk_buff *skb,\n--\ninclude/net/sch_generic.h-1242-\t} else {\ninclude/net/sch_generic.h:1243:\t\tkfree_skb_reason(skb, (enum skb_drop_reason)reason);\ninclude/net/sch_generic.h-1244-\t}\n"
}

17/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 39937
							output: 37
							thoughts: 31
						

Thoughts:
Here's my summary, as though I'm processing those lines from `include/linux/skbuff.h`:

**Analyzing skbuff.h: Deciphering the Network Buffer Structure**

Alright, let's dive into the guts of the `skbuff` structure – the core of network packet handling in the Linux kernel. I'm using `read-file` to get a good look at lines 1320-1335 in `include/linux/skbuff.h`. My immediate goal is to understand how the kernel organizes and manages these packets at a low level. I want to see what crucial data fields are defined or, at the least, what the comments say about what's going on. I'm hoping to understand some of the memory management tricks and critical locking mechanisms they are using around those bits of data. Specifically, I'm expecting to see things like the packet's length, pointers to the data itself (skb_shared_info, data, head), any metadata about the flow (source, destination, protocol), and likely some reference counting or locking mechanisms to ensure concurrency and prevent race conditions when multiple network threads touch the same data. It's time to find out what's in there.



18/2 2026/09/01 05:55 tool read-file
0m Args:
{
  "File": "include/linux/skbuff.h",
  "FirstLine": 1315,
  "LineCount": 25
}

Results:
{
  "Contents": "1315:\t\n1316:\tvoid __fix_address sk_skb_reason_drop(const struct sock *sk,\n1317:\t\t\t\t\t      struct sk_buff *skb,\n1318:\t\t\t\t\t      enum skb_drop_reason reason);\n1319:\t\n1320:\tstatic inline void\n1321:\tkfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)\n1322:\t{\n1323:\t\tsk_skb_reason_drop(NULL, skb, reason);\n1324:\t}\n1325:\t\n1326:\t/**\n1327:\t *\tkfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason\n1328:\t *\t@skb: buffer to free\n1329:\t */\n1330:\tstatic inline void kfree_skb(struct sk_buff *skb)\n1331:\t{\n1332:\t\tkfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);\n1333:\t}\n1334:\t\n1335:\tvoid skb_release_head_state(struct sk_buff *skb);\n1336:\tvoid kfree_skb_list_reason(struct sk_buff *segs,\n1337:\t\t\t\t   enum skb_drop_reason reason);\n1338:\tvoid skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt);\n1339:\tvoid skb_tx_error(struct sk_buff *skb);\n"
}

19/2 2026/09/01 05:55 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 40702
							output: 22
							thoughts: 102
						

Thoughts:
**Tracing the `kfree_skb` Path**

Okay, so I'm digging into how we're tracking skb drops. Let's start with `kfree_skb(skb)`. Aha, it just delegates to `kfree_skb_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED)`. That makes sense; gives us a central place to add the drop reason. Good. Now, that `sk_skb_reason_drop` function – that's the key. That function feeds the drop reason, which can be useful when you are investigating memory management, directly into `trace_kfree_skb(skb, __builtin_return_address(0), reason, ...)`!  So, the tracepoints must be what's feeding the tools I'm using. Now I should check the implementation of that `sk_skb_reason_drop` function to figure out where the information is being fed to those tracing tools.



20/2 2026/09/01 05:56 tool grepper
0m Args:
{
  "Expression": "sk_skb_reason_drop"
}

Results:
{
  "Output": "include/linux/skbuff.h=1298=static inline bool skb_data_unref(const struct sk_buff *skb,\n--\ninclude/linux/skbuff.h-1315-\ninclude/linux/skbuff.h:1316:void __fix_address sk_skb_reason_drop(const struct sock *sk,\ninclude/linux/skbuff.h-1317-\t\t\t\t      struct sk_buff *skb,\n--\ninclude/linux/skbuff.h=1321=kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)\ninclude/linux/skbuff.h-1322-{\ninclude/linux/skbuff.h:1323:\tsk_skb_reason_drop(NULL, skb, reason);\ninclude/linux/skbuff.h-1324-}\n--\nnet/can/bcm.c=399=static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,\n--\nnet/can/bcm.c-466-\nnet/can/bcm.c:467:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/can/bcm.c-468-\t\t/* don't care about overflows in this statistic */\n--\nnet/can/isotp.c=355=static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)\n--\nnet/can/isotp.c-367-\tif (reason)\nnet/can/isotp.c:368:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/can/isotp.c-369-}\n--\nnet/can/j1939/socket.c=311=static void j1939_sk_recv_one(struct j1939_sock *jsk, struct sk_buff *oskb)\n--\nnet/can/j1939/socket.c-337-\tif (reason)\nnet/can/j1939/socket.c:338:\t\tsk_skb_reason_drop(\u0026jsk-\u003esk, skb, reason);\nnet/can/j1939/socket.c-339-}\n--\nnet/can/raw.c=129=static void raw_rcv(struct sk_buff *oskb, void *data)\n--\nnet/can/raw.c-211-\tif (reason)\nnet/can/raw.c:212:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/can/raw.c-213-}\n--\nnet/core/skbuff.c=1216=static __always_inline\nnet/core/skbuff.c:1217:bool __sk_skb_reason_drop(const struct sock *sk, struct sk_buff *skb,\nnet/core/skbuff.c-1218-\t\t\t  enum skb_drop_reason reason)\n--\nnet/core/skbuff.c-1235-/**\nnet/core/skbuff.c:1236: *\tsk_skb_reason_drop - free an sk_buff with special reason\nnet/core/skbuff.c-1237- *\t@sk: the socket to receive @skb, or NULL if not applicable\n--\nnet/core/skbuff.c=1245=void __fix_address\nnet/core/skbuff.c:1246:sk_skb_reason_drop(const struct sock *sk, struct sk_buff *skb,\nnet/core/skbuff.c-1247-\t\t   enum skb_drop_reason reason)\nnet/core/skbuff.c-1248-{\nnet/core/skbuff.c:1249:\tif (__sk_skb_reason_drop(sk, skb, reason))\nnet/core/skbuff.c-1250-\t\t__kfree_skb(skb);\nnet/core/skbuff.c-1251-}\nnet/core/skbuff.c:1252:EXPORT_SYMBOL(sk_skb_reason_drop);\nnet/core/skbuff.c-1253-\n--\nnet/core/skbuff.c=1282=kfree_skb_list_reason(struct sk_buff *segs, enum skb_drop_reason reason)\n--\nnet/core/skbuff.c-1290-\nnet/core/skbuff.c:1291:\t\tif (__sk_skb_reason_drop(NULL, segs, reason)) {\nnet/core/skbuff.c-1292-\t\t\tskb_poison_list(segs);\n--\nnet/core/sock.c=544=int __sk_receive_skb(struct sock *sk, struct sk_buff *skb,\n--\nnet/core/sock.c-590-discard_and_relse:\nnet/core/sock.c:591:\tsk_skb_reason_drop(sk, skb, reason);\nnet/core/sock.c-592-\tgoto out;\n--\nnet/ipv4/ping.c=931=static enum skb_drop_reason __ping_queue_rcv_skb(struct sock *sk,\n--\nnet/ipv4/ping.c-939-\tif (reason) {\nnet/ipv4/ping.c:940:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv4/ping.c-941-\t\tpr_debug(\"ping_queue_rcv_skb -\u003e failed\\n\");\n--\nnet/ipv4/raw.c=302=static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/raw.c-310-\tif (reason) {\nnet/ipv4/raw.c:311:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv4/raw.c-312-\t\treturn NET_RX_DROP;\n--\nnet/ipv4/raw.c=318=int raw_rcv(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/raw.c-321-\t\tsk_drops_inc(sk);\nnet/ipv4/raw.c:322:\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_XFRM_POLICY);\nnet/ipv4/raw.c-323-\t\treturn NET_RX_DROP;\n--\nnet/ipv4/syncookies.c=405=struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/syncookies.c-509-out_drop:\nnet/ipv4/syncookies.c:510:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv4/syncookies.c-511-\treturn NULL;\n--\nnet/ipv4/tcp_input.c=5297=tcp_drop_reason(struct sock *sk, struct sk_buff *skb, enum skb_drop_reason reason)\n--\nnet/ipv4/tcp_input.c-5299-\tsk_drops_skbadd(sk, skb);\nnet/ipv4/tcp_input.c:5300:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv4/tcp_input.c-5301-}\n--\nnet/ipv4/tcp_ipv4.c=1830=int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/tcp_ipv4.c-1883-discard:\nnet/ipv4/tcp_ipv4.c:1884:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv4/tcp_ipv4.c-1885-\t/* Be careful here. If this function gets more complicated and\n--\nnet/ipv4/tcp_ipv4.c=2070=int tcp_v4_rcv(struct sk_buff *skb)\n--\nnet/ipv4/tcp_ipv4.c-2282-\t/* Discard frame. */\nnet/ipv4/tcp_ipv4.c:2283:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv4/tcp_ipv4.c-2284-\treturn 0;\n--\nnet/ipv4/udp.c=1657=int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/udp.c-1764-\t\t\tskb_mark_not_on_list(skb);\nnet/ipv4/udp.c:1765:\t\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PROTO_MEM);\nnet/ipv4/udp.c-1766-\t\t}\n--\nnet/ipv4/udp.c=2309=static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/udp.c-2335-\t\ttrace_udp_fail_queue_rcv_skb(rc, sk, skb);\nnet/ipv4/udp.c:2336:\t\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv4/udp.c-2337-\t\treturn -1;\n--\nnet/ipv4/udp.c=2351=static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv4/udp.c-2419-\tudp_drops_inc(sk);\nnet/ipv4/udp.c:2420:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv4/udp.c-2421-\treturn -1;\n--\nnet/ipv4/udp.c=2592=int udp_rcv(struct sk_buff *skb)\n--\nnet/ipv4/udp.c-2672-\t */\nnet/ipv4/udp.c:2673:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv4/udp.c-2674-\treturn 0;\n--\nnet/ipv4/udp.c-2695-\t__UDP_INC_STATS(net, UDP_MIB_INERRORS);\nnet/ipv4/udp.c:2696:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv4/udp.c-2697-\treturn 0;\n--\nnet/ipv6/inet6_connection_sock.c=97=int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused)\n--\nnet/ipv6/inet6_connection_sock.c-109-\t\t\tsk-\u003esk_route_caps = 0;\nnet/ipv6/inet6_connection_sock.c:110:\t\t\tsk_skb_reason_drop(sk, skb,\nnet/ipv6/inet6_connection_sock.c-111-\t\t\t\t\t   SKB_DROP_REASON_IP_OUTNOROUTES);\n--\nnet/ipv6/ip6mr.c=1089=static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,\n--\nnet/ipv6/ip6mr.c-1174-\tif (reason) {\nnet/ipv6/ip6mr.c:1175:\t\tsk_skb_reason_drop(mroute6_sk, skb, reason);\nnet/ipv6/ip6mr.c-1176-\t\treturn -ENOMEM;\n--\nnet/ipv6/raw.c=359=static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/raw.c-365-\t\tsk_drops_inc(sk);\nnet/ipv6/raw.c:366:\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_SKB_CSUM);\nnet/ipv6/raw.c-367-\t\treturn NET_RX_DROP;\n--\nnet/ipv6/raw.c-373-\tif (reason) {\nnet/ipv6/raw.c:374:\t\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv6/raw.c-375-\t\treturn NET_RX_DROP;\n--\nnet/ipv6/raw.c=388=int rawv6_rcv(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/raw.c-394-\t\tsk_drops_inc(sk);\nnet/ipv6/raw.c:395:\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_XFRM_POLICY);\nnet/ipv6/raw.c-396-\t\treturn NET_RX_DROP;\n--\nnet/ipv6/raw.c-419-\t\t\tsk_drops_inc(sk);\nnet/ipv6/raw.c:420:\t\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_SKB_CSUM);\nnet/ipv6/raw.c-421-\t\t\treturn NET_RX_DROP;\n--\nnet/ipv6/syncookies.c=174=struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/syncookies.c-286-out_drop:\nnet/ipv6/syncookies.c:287:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv6/syncookies.c-288-\treturn NULL;\n--\nnet/ipv6/tcp_ipv6.c=847=static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32 seq,\n--\nnet/ipv6/tcp_ipv6.c-1001-\nnet/ipv6/tcp_ipv6.c:1002:\tsk_skb_reason_drop(sk, buff, SKB_DROP_REASON_IP_OUTNOROUTES);\nnet/ipv6/tcp_ipv6.c-1003-}\n--\nnet/ipv6/tcp_ipv6.c=1567=int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/tcp_ipv6.c-1662-\t\t__kfree_skb(opt_skb);\nnet/ipv6/tcp_ipv6.c:1663:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv6/tcp_ipv6.c-1664-\treturn 0;\n--\nnet/ipv6/tcp_ipv6.c=1730=INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)\n--\nnet/ipv6/tcp_ipv6.c-1935-\tSKB_DR_OR(drop_reason, NOT_SPECIFIED);\nnet/ipv6/tcp_ipv6.c:1936:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv6/tcp_ipv6.c-1937-\treturn 0;\n--\nnet/ipv6/udp.c=772=static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/udp.c-798-\t\ttrace_udp_fail_queue_rcv_skb(rc, sk, skb);\nnet/ipv6/udp.c:799:\t\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv6/udp.c-800-\t\treturn -1;\n--\nnet/ipv6/udp.c=806=static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)\n--\nnet/ipv6/udp.c-872-\tudp_drops_inc(sk);\nnet/ipv6/udp.c:873:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/ipv6/udp.c-874-\treturn -1;\n--\nnet/ipv6/udp.c=1069=INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb)\n--\nnet/ipv6/udp.c-1162-\nnet/ipv6/udp.c:1163:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv6/udp.c-1164-\treturn 0;\n--\nnet/ipv6/udp.c-1182-\t__UDP6_INC_STATS(net, UDP_MIB_INERRORS);\nnet/ipv6/udp.c:1183:\tsk_skb_reason_drop(sk, skb, reason);\nnet/ipv6/udp.c-1184-\treturn 0;\n--\nnet/packet/af_packet.c=2136=static int packet_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2244-drop:\nnet/packet/af_packet.c:2245:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/packet/af_packet.c-2246-\treturn 0;\n--\nnet/packet/af_packet.c=2249=static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2517-drop:\nnet/packet/af_packet.c:2518:\tsk_skb_reason_drop(sk, skb, drop_reason);\nnet/packet/af_packet.c-2519-\treturn 0;\n--\nnet/packet/af_packet.c-2526-\tsk-\u003esk_data_ready(sk);\nnet/packet/af_packet.c:2527:\tsk_skb_reason_drop(sk, copy_skb, drop_reason);\nnet/packet/af_packet.c-2528-\tgoto drop_n_restore;\n--\nnet/psp/psp_sock.c=30=psp_validate_xmit(struct sock *sk, struct net_device *dev, struct sk_buff *skb)\n--\nnet/psp/psp_sock.c-39-\tif (!good) {\nnet/psp/psp_sock.c:40:\t\tsk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PSP_OUTPUT);\nnet/psp/psp_sock.c-41-\t\treturn NULL;\n"
}

21/2 2026/09/01 05:56 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 45935
							output: 99
							thoughts: 1534
						

Thoughts:
**Analysis of the Proposed Patch**

Okay, let's break this down. From what I can see, `kfree_skb_reason(skb, reason)` is the central function here. It's essentially a wrapper. It passes a specified "reason" to the `sk_skb_reason_drop` function, which then does two things: it uses this reason to invoke `trace_kfree_skb`, and then it frees the buffer using `__kfree_skb(skb)`. The core change is that instead of the previously generic `kfree_skb(skb)` calls which defaulted to a "not specified" reason, we're now getting more specific enum values for the `skb:kfree_skb` tracepoint, thanks to the introduction of `kfree_skb_reason(skb, reason)`.

Now, let's carefully consider the provided criteria for determining if this patch is suitable for fuzzing. The key question is whether the changes functionally alter the execution flow of the kernel. Looking at bullet point number 2 in the instructions, the question becomes: does this purely represent "decorative changes, such as logging (e.g., pr_err, printk) or tracepoints."

The patch involves a few key aspects:

1.  New drop reason enum values added in `include/net/dropreason-core.h`.
2.  The insertion of reason parameters to  `kfree_skb_reason` calls within IP tunnel and GRE code (`gre_demux.c`, `ip_gre.c`, `ip_tunnel.c`, `ip6_gre.c`, `ip6_tunnel.c`) so that the `skb:kfree_skb` tracepoint records specific drop reasons rather than a generic one.
3.  A self-test script (`tools/testing/selftests/net/tunnel_drop_reasons.sh`) to test the tracepoint and drop reasons.

Let's dissect each of the modified files, looking for functional changes:

*   `include/net/dropreason-core.h`: This simply defines the drop reasons for the tracepoint – adding new enum values.
*   `include/net/gre.h`, `include/net/ip6_tunnel.h`: These involve signature changes to pass the drop reason enum.
*   The actual implementation files like `net/ipv4/gre_demux.c`, `net/ipv4/ip_gre.c`, `net/ipv4/ip_tunnel.c`, `net/ipv6/ip6_gre.c`, and `net/ipv6/ip6_tunnel.c`: In all of these, the core function calls or existing error paths are kept with their control flow unaltered. The patch introduces `reason` and uses `kfree_skb_reason` instead of `kfree_skb`, but the execution flow in the event of an error remains the same as before. The new calls to `kfree_skb_reason()` are placed within existing error handling paths, but no new execution paths are created.
*   `tools/testing/selftests/net/Makefile`, `config`, `tunnel_drop_reasons.sh`: self-tests which exercise the new features.

There are no functional changes to packet forwarding, encapsulation, or parsing, or any other core aspects of the kernel. The sole change in kernel execution is the inclusion of specific drop reason codes to the `kfree_skb` tracepoint via `kfree_skb_reason()`. This is, in essence, a more detailed logging and observability enhancement. It doesn't alter how the kernel processes packets or makes any changes to the execution path in the event of any specific error or drop; it simply adds more detailed logging when these error paths are hit.

Therefore, this patch is purely decorative, enhancing a tracepoint and adding a selftest. It does not functionally modify kernel execution, therefore the "WorthFuzzing" parameter should be set to "false".

**Final Decision:** WorthFuzzing = false.



22/2 2026/09/01 05:56 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [],
  "Reasoning": "The patch purely introduces new SKB drop reasons and updates IPv4 and IPv6 GRE and tunnel routines to pass specific drop reasons to kfree_skb_reason() (skb:kfree_skb tracepoint), along with a corresponding net selftest. It makes purely decorative/tracepoint changes without functionally altering execution flow.",
  "WorthFuzzing": false
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [],
  "Reasoning": "The patch purely introduces new SKB drop reasons and updates IPv4 and IPv6 GRE and tunnel routines to pass specific drop reasons to kfree_skb_reason() (skb:kfree_skb tracepoint), along with a corresponding net selftest. It makes purely decorative/tracepoint changes without functionally altering execution flow.",
  "WorthFuzzing": false
}

23/1 2026/09/01 05:56 action If
0m Args:
{
  "WorthFuzzing": false
}

Results:
null

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)