From: Eric Dumazet <edumazet@gmail.com>
To: menglong8.dong@gmail.com, dsahern@kernel.org
Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net,
yoshfuji@linux-ipv6.org, kuba@kernel.org, pabeni@redhat.com,
benbjiang@tencent.com, flyingpeng@tencent.com,
imagedong@tencent.com, edumazet@google.com, kafai@fb.com,
talalahmad@google.com, keescook@chromium.org,
mengensun@tencent.com, dongli.zhang@oracle.com,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 8/9] net: ipv6: add skb drop reasons to ip6_rcv_core()
Date: Wed, 13 Apr 2022 13:40:59 -0700 [thread overview]
Message-ID: <62903323-d1c0-79cd-7cf8-d6c4b89ff848@gmail.com> (raw)
In-Reply-To: <20220413081600.187339-9-imagedong@tencent.com>
On 4/13/22 01:15, menglong8.dong@gmail.com wrote:
> From: Menglong Dong <imagedong@tencent.com>
>
> Replace kfree_skb() used in ip6_rcv_core() with kfree_skb_reason().
> No new drop reasons are added.
>
> Seems now we use 'SKB_DROP_REASON_IP_INHDR' for too many case during
> ipv6 header parse or check, just like what 'IPSTATS_MIB_INHDRERRORS'
> do. Will it be too general and hard to know what happened?
>
> Signed-off-by: Menglong Dong <imagedong@tencent.com>
> Reviewed-by: Jiang Biao <benbjiang@tencent.com>
> Reviewed-by: Hao Peng <flyingpeng@tencent.com>
> ---
> net/ipv6/ip6_input.c | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
> index b4880c7c84eb..1b925ecb26e9 100644
> --- a/net/ipv6/ip6_input.c
> +++ b/net/ipv6/ip6_input.c
> @@ -145,13 +145,14 @@ static void ip6_list_rcv_finish(struct net *net, struct sock *sk,
> static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
> struct net *net)
> {
> + enum skb_drop_reason reason;
> const struct ipv6hdr *hdr;
> u32 pkt_len;
> struct inet6_dev *idev;
>
> if (skb->pkt_type == PACKET_OTHERHOST) {
> dev_core_stats_rx_otherhost_dropped_inc(skb->dev);
> - kfree_skb(skb);
> + kfree_skb_reason(skb, SKB_DROP_REASON_OTHERHOST);
> return NULL;
> }
>
> @@ -161,9 +162,12 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
>
> __IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_IN, skb->len);
>
> + SKB_DR_SET(reason, NOT_SPECIFIED);
> if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL ||
> !idev || unlikely(idev->cnf.disable_ipv6)) {
> __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
> + if (unlikely(idev->cnf.disable_ipv6))
idev can be NULL here (according to surrounding code), and we crash :/
> + SKB_DR_SET(reason, IPV6DISABLED);
> goto drop;
> }
>
> @@ -187,8 +191,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
>
> hdr = ipv6_hdr(skb);
>
> - if (hdr->version != 6)
> + if (hdr->version != 6) {
> + SKB_DR_SET(reason, UNHANDLED_PROTO);
> goto err;
> + }
>
> __IP6_ADD_STATS(net, idev,
> IPSTATS_MIB_NOECTPKTS +
> @@ -226,8 +232,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
> if (!ipv6_addr_is_multicast(&hdr->daddr) &&
> (skb->pkt_type == PACKET_BROADCAST ||
> skb->pkt_type == PACKET_MULTICAST) &&
> - idev->cnf.drop_unicast_in_l2_multicast)
> + idev->cnf.drop_unicast_in_l2_multicast) {
> + SKB_DR_SET(reason, UNICAST_IN_L2_MULTICAST);
> goto err;
> + }
>
> /* RFC4291 2.7
> * Nodes must not originate a packet to a multicast address whose scope
> @@ -256,12 +264,11 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
> if (pkt_len + sizeof(struct ipv6hdr) > skb->len) {
> __IP6_INC_STATS(net,
> idev, IPSTATS_MIB_INTRUNCATEDPKTS);
> + SKB_DR_SET(reason, PKT_TOO_SMALL);
> goto drop;
> }
> - if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr))) {
> - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
> - goto drop;
> - }
> + if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
> + goto err;
> hdr = ipv6_hdr(skb);
> }
>
> @@ -282,9 +289,10 @@ static struct sk_buff *ip6_rcv_core(struct sk_buff *skb, struct net_device *dev,
> return skb;
> err:
> __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
> + SKB_DR_OR(reason, IP_INHDR);
> drop:
> rcu_read_unlock();
> - kfree_skb(skb);
> + kfree_skb_reason(skb, reason);
> return NULL;
> }
>
next prev parent reply other threads:[~2022-04-13 20:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 8:15 [PATCH net-next 0/9] net: ip: add skb drop reasons to ip ingress menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 1/9] skb: add some helpers for skb drop reasons menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 2/9] net: ipv4: add skb drop reasons to ip_error() menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 3/9] net: ipv6: add skb drop reasons to ip6_pkt_drop() menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 4/9] net: ip: add skb drop reasons to ip forwarding menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 5/9] net: icmp: introduce function icmpv6_param_prob_reason() menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 6/9] net: ipv6: remove redundant statistics in ipv6_hop_jumbo() menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 7/9] net: ipv6: add skb drop reasons to TLV parse menglong8.dong
2022-04-13 8:15 ` [PATCH net-next 8/9] net: ipv6: add skb drop reasons to ip6_rcv_core() menglong8.dong
2022-04-13 20:40 ` Eric Dumazet [this message]
2022-04-14 1:20 ` Menglong Dong
2022-04-13 8:16 ` [PATCH net-next 9/9] net: ipv6: add skb drop reasons to ip6_protocol_deliver_rcu() menglong8.dong
2022-04-13 13:30 ` [PATCH net-next 0/9] net: ip: add skb drop reasons to ip ingress patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=62903323-d1c0-79cd-7cf8-d6c4b89ff848@gmail.com \
--to=edumazet@gmail.com \
--cc=benbjiang@tencent.com \
--cc=davem@davemloft.net \
--cc=dongli.zhang@oracle.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=flyingpeng@tencent.com \
--cc=imagedong@tencent.com \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mengensun@tencent.com \
--cc=menglong8.dong@gmail.com \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
--cc=talalahmad@google.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).