From patchwork Mon Jan 24 13:15:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722132 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6C14C433FE for ; Mon, 24 Jan 2022 13:15:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243032AbiAXNP4 (ORCPT ); Mon, 24 Jan 2022 08:15:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243041AbiAXNPy (ORCPT ); Mon, 24 Jan 2022 08:15:54 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78168C06173D; Mon, 24 Jan 2022 05:15:54 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id z131so4335025pgz.12; Mon, 24 Jan 2022 05:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sBcUzmR8HipAMmfGTXgE1nbM6mUi+zj9tY3YPqei71A=; b=VfujqfnNX0UUJbMS5C3SxFb/ynubohdqoD8vcFVVfMHKgzxhwGiyqmX8YOVXyuwMa9 gg00dtfqAiGjAHEL23X1ZX3AmyJnPqYlABkdcXRN+PcAt+a+wjdjS2lY1atSopw+4NEF U+zDmcsoHIwGcCoyuLAH2Cg0ZaDeEhI+1gkcQ7URBWviL6CZvzIlEQp8q0iP/2jBpyFb 8PbCctrJ7fqy9xukJ4yoVWMxz+eC+AYW+XbaLVJWPj3Yv6e8q1B3gidhtpvfKkVyQjre 9+u2f+7rWlvNAZRggAkmjerBHHXiGsVJr5UqG/DjFBpyW5LKWfqRbWn3bVHeZ/jBEuQi EBCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sBcUzmR8HipAMmfGTXgE1nbM6mUi+zj9tY3YPqei71A=; b=0cSMVsJ7EDgI25IN5qjhTq5144LETYoRN+YjiA1Z2RG7170/nrTOWtCtXUrk+h37ac DjN7qS59JYdxzPEPAM9vyXA/MswBiTP1MYGUSoKgFZwnHxsgE27infE8gu1qgzI/+P8g bOI4DP+qGjXwv4b7gFsMGzD3GZMw6L9YQtlop+A4Oa06Vz87EsXOtdTWJq98qCIYcQFK s++rbo8eAiU2Px5PaZg1PwQUlFkc1Etsl/ezHEx853Mxhk/3x6j3qT2EYwLMIi6PYgGx gXVkco2T/MkDBImxU66w/JdIonXMfpQMxSLSKOtIpDzbVU1yD6iluaLuoRrU6GHZCyyM kfrg== X-Gm-Message-State: AOAM532rM3LSYAou9Z2hSOl7wUe4e46kAeTb9iRXwKNJdKTj81n12rhE aptX0B1VKICudkNQtT4NwVE= X-Google-Smtp-Source: ABdhPJwefWMxahNevYpy0VOjiBJ6H0TV8n629KxQMGKFMJdluAO99q9/dJo/wYc9ytZwHtzC8tn1dg== X-Received: by 2002:a05:6a00:18a6:b0:4ca:38e0:400d with SMTP id x38-20020a056a0018a600b004ca38e0400dmr1147619pfh.22.1643030154055; Mon, 24 Jan 2022 05:15:54 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:15:53 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 1/6] net: netfilter: use kfree_drop_reason() for NF_DROP Date: Mon, 24 Jan 2022 21:15:33 +0800 Message-Id: <20220124131538.1453657-2-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in nf_hook_slow() when skb is dropped by reason of NF_DROP. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/netfilter/core.c | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index bf11e1fbd69b..1bcd690b8ae1 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -320,6 +320,7 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_CSUM, SKB_DROP_REASON_TCP_FILTER, SKB_DROP_REASON_UDP_CSUM, + SKB_DROP_REASON_NETFILTER_DROP, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 3e042ca2cedb..beed7bb2bc0e 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -16,6 +16,7 @@ EM(SKB_DROP_REASON_TCP_CSUM, TCP_CSUM) \ EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ + EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/netfilter/core.c b/net/netfilter/core.c index 354cb472f386..d1c9dfbb11fa 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -621,7 +621,8 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, case NF_ACCEPT: break; case NF_DROP: - kfree_skb(skb); + kfree_skb_reason(skb, + SKB_DROP_REASON_NETFILTER_DROP); ret = NF_DROP_GETERR(verdict); if (ret == 0) ret = -EPERM; From patchwork Mon Jan 24 13:15:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722133 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76DE3C433FE for ; Mon, 24 Jan 2022 13:16:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243049AbiAXNQC (ORCPT ); Mon, 24 Jan 2022 08:16:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243069AbiAXNQA (ORCPT ); Mon, 24 Jan 2022 08:16:00 -0500 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6719DC061748; Mon, 24 Jan 2022 05:16:00 -0800 (PST) Received: by mail-pl1-x644.google.com with SMTP id y17so5061049plg.7; Mon, 24 Jan 2022 05:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O88eKXAZyfDbUImGdIOspl+p31sKA6IRKKmfTf5yIqs=; b=E8W5K8vRb2LRLnX2+E+Ey1GWeDfcRPgBRijAMK7lGIH8dVCG/exxweu6oRR4+YFZIV haLSlmPafJFAw2h6C57D62+k7hmXE3VSSfjkIuqz8QIOqB4nn8YAO8j+Xmykcmcgmf/N rDpsaEHpwSnLDiAzRaFb9aRt8YHodLT02g1G0BkdNJjLEd6YBEbf31CqWQ5QMQIWRQ1T SPtBLfXgwfWvRK1Lb9feotDT3z+pUQ8RwKzOtgvpQ2AwsQHWx/czvIWIg7eJkySpXKnZ HFODSbaYvC0oxmunYN2rNIi1pReWeHepWZ2bGGqBIBJjsuPMWoH9FlbtQaRNpD+8QM1b NzbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O88eKXAZyfDbUImGdIOspl+p31sKA6IRKKmfTf5yIqs=; b=F8v3/BV57UzYb+ferEKEzcFl62/5TrKYznojHQRuSisH2Ez/FlHPRYCHFdkZHti2ij DZKAvBrueps/jactx4rhI7t84/ua56TQPP+nfGSQw6y8c3f169tEDnZSGXEFyrtL4Adl 7mzgXlLqGA6rr11+n7L9lvlzgvQRILGItUQfbzGZFmbWsESa9qr/Q5C+lKvzBAUMw91x 7SEXQOUdvex/8RLtfqJNsz6/kZUW9wkZ9ApneYqno/yxJW0QHdxrFPtkNVvIdyNS7vw+ 7PQLOl6JoTgb/VRkE0wCHGuzYckZ+qn5SZEJQddogffnEqBqyjRnRVu9Xy2Z2fXsUIlg NblA== X-Gm-Message-State: AOAM531pYJj3S26ykMhcT1CrBVog7fqiomDJOeeNTV9SgEuVsIS6Am6U k3+VXidloqFuqgs0ZdM3rGPxrg38Wm4= X-Google-Smtp-Source: ABdhPJyiiBSyVCynkgf6WjIlGDCIr1R5ShoYM9FU/heOFrIbh6hpwRJKPCslWeqbawLDdjWcTeWERA== X-Received: by 2002:a17:90b:1801:: with SMTP id lw1mr1811740pjb.215.1643030160025; Mon, 24 Jan 2022 05:16:00 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:15:59 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 2/6] net: ipv4: use kfree_skb_reason() in ip_rcv_core() Date: Mon, 24 Jan 2022 21:15:34 +0800 Message-Id: <20220124131538.1453657-3-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in ip_rcv_core(). Three new drop reasons are introduced: SKB_DROP_REASON_OTHERHOST SKB_DROP_REASON_IP_CSUM SKB_DROP_REASON_IP_INHDR Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 3 +++ include/trace/events/skb.h | 3 +++ net/ipv4/ip_input.c | 15 +++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1bcd690b8ae1..f3028028b83e 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -321,6 +321,9 @@ enum skb_drop_reason { SKB_DROP_REASON_TCP_FILTER, SKB_DROP_REASON_UDP_CSUM, SKB_DROP_REASON_NETFILTER_DROP, + SKB_DROP_REASON_OTHERHOST, + SKB_DROP_REASON_IP_CSUM, + SKB_DROP_REASON_IP_INHDR, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index beed7bb2bc0e..d1b0d9690e62 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -17,6 +17,9 @@ EM(SKB_DROP_REASON_TCP_FILTER, TCP_FILTER) \ EM(SKB_DROP_REASON_UDP_CSUM, UDP_CSUM) \ EM(SKB_DROP_REASON_NETFILTER_DROP, NETFILTER_DROP) \ + EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ + EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ + EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index 3a025c011971..ab9bee4bbf0a 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -436,13 +436,18 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb) static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) { const struct iphdr *iph; + int drop_reason; u32 len; + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; + /* When the interface is in promisc. mode, drop all the crap * that it receives, do not try to analyse it. */ - if (skb->pkt_type == PACKET_OTHERHOST) + if (skb->pkt_type == PACKET_OTHERHOST) { + drop_reason = SKB_DROP_REASON_OTHERHOST; goto drop; + } __IP_UPD_PO_STATS(net, IPSTATS_MIB_IN, skb->len); @@ -478,7 +483,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) IPSTATS_MIB_NOECTPKTS + (iph->tos & INET_ECN_MASK), max_t(unsigned short, 1, skb_shinfo(skb)->gso_segs)); - if (!pskb_may_pull(skb, iph->ihl*4)) + if (!pskb_may_pull(skb, iph->ihl * 4)) goto inhdr_error; iph = ip_hdr(skb); @@ -490,7 +495,7 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) if (skb->len < len) { __IP_INC_STATS(net, IPSTATS_MIB_INTRUNCATEDPKTS); goto drop; - } else if (len < (iph->ihl*4)) + } else if (len < (iph->ihl * 4)) goto inhdr_error; /* Our transport medium may have padded the buffer out. Now we know it @@ -516,11 +521,13 @@ static struct sk_buff *ip_rcv_core(struct sk_buff *skb, struct net *net) return skb; csum_error: + drop_reason = SKB_DROP_REASON_IP_CSUM; __IP_INC_STATS(net, IPSTATS_MIB_CSUMERRORS); inhdr_error: + drop_reason = drop_reason ?: SKB_DROP_REASON_IP_INHDR; __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); out: return NULL; } From patchwork Mon Jan 24 13:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722134 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C65DC433EF for ; Mon, 24 Jan 2022 13:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243071AbiAXNQK (ORCPT ); Mon, 24 Jan 2022 08:16:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243077AbiAXNQF (ORCPT ); Mon, 24 Jan 2022 08:16:05 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B87CFC061744; Mon, 24 Jan 2022 05:16:05 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id e28so11494990pfj.5; Mon, 24 Jan 2022 05:16:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I7Kfl0iYEEcM6De3k82IV85ORzkWhJdyfX79ePAXbNo=; b=kGDtXpI8RbYEDb+NHf6rtqjvtmFsukYaLBorp7pjuiAXcSmEHKmrw/KgIEjLKTqP2u qT7ObAsmIcoXOyRDR+rjc7vt31IJjAzkLJ1Awc8n/exe5AKxBYeHTQo/gcHrOBuYVIpM EOmGslV84c53mxEk01PMVModJD7hyl9AMiEBLTcbVf5HxutvQxal+/CEjcRNcVs+Ujp5 yIAfw/yzd39FpS0mhelve7f45MIu+ZzEM63eoExYd1hxbuyjusDCFX61khl/1SnTSQ3P PTOyTxHthq/zfyXNhfGxXARqRCz7wegYxGxqBixvaz+zrr5IVveNpfFy7G79pH9cehWA xBVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I7Kfl0iYEEcM6De3k82IV85ORzkWhJdyfX79ePAXbNo=; b=uvp67VFAAzdmeCgmAaAU6YZs5EEA84RdQUry+Rrm8qcxLxsoUF5Y4OmTeQvTSrsaUi RSQnd68uYphEXtoZR4BiLZfeAKITtqWGG96TPZP+09Ph1bxETaE6lDtMjdMv1eVt3jHN /GKfKvtomOxggv1GmOEg9vz/4xbpRAgHgDRfk6/eY+tflwMS175xvoAwrYzR1ignlWgd 0NmIGa9qWHby1EUf94uV7PPrN+yIWsDH4FPP7z//xOuSmppZEmU5oWzX8j4TFmZIGazD SVylqPJyyQoReSf2jfnJqcfFRxBnjE+SLUNAstN5NksfSjLQCns47/Zm12YeMFv7YLL1 7+2w== X-Gm-Message-State: AOAM532fIkZSspr+MWD6h2EpaioBIDGYcHQxqoIWA/XvksEGhmxjjoJl FNgpg+Zuo/E8S09XLaB4BJo= X-Google-Smtp-Source: ABdhPJz9l+WWbd/wMeFWF+h29wP+FL0PAU6CxZG08MSVJK+QSdJjw1dUg3JFNIYSDYXv3mek2jAEsg== X-Received: by 2002:a63:d312:: with SMTP id b18mr11952028pgg.198.1643030165340; Mon, 24 Jan 2022 05:16:05 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:16:04 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 3/6] net: ipv4: use kfree_skb_reason() in ip_rcv_finish_core() Date: Mon, 24 Jan 2022 21:15:35 +0800 Message-Id: <20220124131538.1453657-4-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in ip_rcv_finish_core(), following drop reasons are introduced: SKB_DROP_REASON_IP_ROUTE_INPUT SKB_DROP_REASON_IP_RPFILTER SKB_DROP_REASON_EARLY_DEMUX SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 4 ++++ include/trace/events/skb.h | 5 +++++ net/ipv4/ip_input.c | 22 ++++++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index f3028028b83e..8942d32c0657 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -324,6 +324,10 @@ enum skb_drop_reason { SKB_DROP_REASON_OTHERHOST, SKB_DROP_REASON_IP_CSUM, SKB_DROP_REASON_IP_INHDR, + SKB_DROP_REASON_IP_ROUTE_INPUT, + SKB_DROP_REASON_IP_RPFILTER, + SKB_DROP_REASON_EARLY_DEMUX, + SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index d1b0d9690e62..1dcdcc92cf08 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -20,6 +20,11 @@ EM(SKB_DROP_REASON_OTHERHOST, OTHERHOST) \ EM(SKB_DROP_REASON_IP_CSUM, IP_CSUM) \ EM(SKB_DROP_REASON_IP_INHDR, IP_INHDR) \ + EM(SKB_DROP_REASON_IP_ROUTE_INPUT, IP_ROUTE_INPUT) \ + EM(SKB_DROP_REASON_IP_RPFILTER, IP_RPFILTER) \ + EM(SKB_DROP_REASON_EARLY_DEMUX, EARLY_DEMUX) \ + EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ + UNICAST_IN_L2_MULTICAST) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index ab9bee4bbf0a..77bb9ddc441b 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -318,8 +318,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, { const struct iphdr *iph = ip_hdr(skb); int (*edemux)(struct sk_buff *skb); + int err, drop_reason; struct rtable *rt; - int err; + + drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; if (ip_can_use_hint(skb, iph, hint)) { err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos, @@ -339,8 +341,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, if (ipprot && (edemux = READ_ONCE(ipprot->early_demux))) { err = INDIRECT_CALL_2(edemux, tcp_v4_early_demux, udp_v4_early_demux, skb); - if (unlikely(err)) + if (unlikely(err)) { + drop_reason = SKB_DROP_REASON_EARLY_DEMUX; goto drop_error; + } /* must reload iph, skb->head might have changed */ iph = ip_hdr(skb); } @@ -353,8 +357,10 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, if (!skb_valid_dst(skb)) { err = ip_route_input_noref(skb, iph->daddr, iph->saddr, iph->tos, dev); - if (unlikely(err)) + if (unlikely(err)) { + drop_reason = SKB_DROP_REASON_IP_ROUTE_INPUT; goto drop_error; + } } #ifdef CONFIG_IP_ROUTE_CLASSID @@ -396,19 +402,23 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, * so-called "hole-196" attack) so do it for both. */ if (in_dev && - IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) + IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) { + drop_reason = SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST; goto drop; + } } return NET_RX_SUCCESS; drop: - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return NET_RX_DROP; drop_error: - if (err == -EXDEV) + if (err == -EXDEV) { + drop_reason = SKB_DROP_REASON_IP_RPFILTER; __NET_INC_STATS(net, LINUX_MIB_IPRPFILTER); + } goto drop; } From patchwork Mon Jan 24 13:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722135 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE496C433FE for ; Mon, 24 Jan 2022 13:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243087AbiAXNQM (ORCPT ); Mon, 24 Jan 2022 08:16:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243076AbiAXNQK (ORCPT ); Mon, 24 Jan 2022 08:16:10 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5B4CC06173B; Mon, 24 Jan 2022 05:16:10 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id i8so15311473pgt.13; Mon, 24 Jan 2022 05:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bbIwpa2HKtPGNZ5ti6tjdrZrFRI38QINO2+UYVbJdYQ=; b=gpbMAew2b+vep0adLFGdhSjoUwwNOu28ixF3C0IeCEeM5JPO6jrF2HDDOvEPFG7ZQf R+pU1pDKEiz5etn0ehviAZAOtOWOHQoA9XyxU3ifCHvhYpLJ6emkYe1NdgsVUcZxVRNn 08hGdgYxJU7/5Sdz8U2XJWTE7QTDuGvaJ4zBT/rIUvtktNKGeX5HK4d/JzIr0YT9KZeA Lgj0APiQTTqjvTPXjya2RPtZh9dSP4GRiWAYYWhRlAR6BwUz83fiaeJr9aF56HnXorb3 Nvb0tOiMJiLNcl+/igxrqHbj3wY1bRXl5x1hOxwSgbmLqo8G4P/T4XzC6euLzWDA0kUG Sl7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bbIwpa2HKtPGNZ5ti6tjdrZrFRI38QINO2+UYVbJdYQ=; b=o1yCYmjzPpWVJQX9+SJEkHvG4DWEbQzPZ87zDiEci7ch/jXsc2KvUSk7H/pRLwxdLe Zl547OpSIaUILF+pA8ozis00s3D4TXnfYz10sjOxPM1dvNBqAwBzowbuj5IFMz63HJUC ihpcKvExFZ/rpnbZZPG2LkSTi0AZJUzUTkxwumvA1EgfpLC639UYY4t58F8i4jgI7iBZ Mu22Hs1+V1YsaebQqxDBGiio/B9FfeZIYnu0L87tXuit9Vpq2PU2aY+r7FhsrBLL31cd 5xFoY1e6pByFSBirvBTxmwhOLYGLOdimSe7qcbzt5mzRRs/hApNEP+xf3qNjYk3KxM/j EGjg== X-Gm-Message-State: AOAM533IhHSPNnWloYUgxetzN5He5nxki9s60WnCbOfDVSEBYeyPEK6M s12DDD1ZMdrCjby2E8iVbC8= X-Google-Smtp-Source: ABdhPJxwYGoYD4VqxA5ZquAvqI/k2yGTOIJwjnY+ZIkUmRPmEvxaSIGD1AV/cPHB1XHb4sTDP9ZRYQ== X-Received: by 2002:a65:63c2:: with SMTP id n2mr11567070pgv.609.1643030170430; Mon, 24 Jan 2022 05:16:10 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:16:09 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 4/6] net: ipv4: use kfree_skb_reason() in ip_protocol_deliver_rcu() Date: Mon, 24 Jan 2022 21:15:36 +0800 Message-Id: <20220124131538.1453657-5-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in ip_protocol_deliver_rcu(). Following new drop reasons are introduced: SKB_DROP_REASON_XFRM_POLICY SKB_DROP_REASON_IP_NOPROTO Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 2 ++ include/trace/events/skb.h | 2 ++ net/ipv4/ip_input.c | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 8942d32c0657..603f77ef2170 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -328,6 +328,8 @@ enum skb_drop_reason { SKB_DROP_REASON_IP_RPFILTER, SKB_DROP_REASON_EARLY_DEMUX, SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, + SKB_DROP_REASON_XFRM_POLICY, + SKB_DROP_REASON_IP_NOPROTO, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 1dcdcc92cf08..e8369b8e8430 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -25,6 +25,8 @@ EM(SKB_DROP_REASON_EARLY_DEMUX, EARLY_DEMUX) \ EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, \ UNICAST_IN_L2_MULTICAST) \ + EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ + EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index a4afb367cf02..376c96cfd5d1 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -196,7 +196,8 @@ void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) if (ipprot) { if (!ipprot->no_policy) { if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) { - kfree_skb(skb); + kfree_skb_reason(skb, + SKB_DROP_REASON_XFRM_POLICY); return; } nf_reset_ct(skb); @@ -215,7 +216,7 @@ void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol) icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0); } - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_IP_NOPROTO); } else { __IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS); consume_skb(skb); From patchwork Mon Jan 24 13:15:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722136 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4F78C433FE for ; Mon, 24 Jan 2022 13:16:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243103AbiAXNQU (ORCPT ); Mon, 24 Jan 2022 08:16:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243095AbiAXNQQ (ORCPT ); Mon, 24 Jan 2022 08:16:16 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CC98C06173D; Mon, 24 Jan 2022 05:16:16 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id j10so3215190pgc.6; Mon, 24 Jan 2022 05:16:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y79107MnbAk14rpj6xPrfrI/dwJH+6GIzGrPuGsa7dI=; b=aGLivlnEmsp5izTPw1TRX8a+9zEI51Gnea5ofIDL3nLHrZIj4s6aHunamdc/KC8gQL uup6S4n8sZsOuT0O/UknErGAeMbUgrbHWHzBkh/d/zI32ppqsgKzrZ6R6C+dtug/75gC RWw1dUwL72WcwZHoIj/aBCOSZKTTLv3/2jgSHuw6uN0ktHvkO/+8nB56R045uSdPdCT9 YqIwyrbEK37ehh2tOPhgsT2fsrZMsz8YvFH0aylf8U8Qqt0zOLb6I8Lh58pvU91m7eWK 158hjQwv5ymojVsRnFHgolKIXyCvPS068C3ZwXe3pn8yxPDo4r3JxcaLiRaEMdONZUQJ 9W1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y79107MnbAk14rpj6xPrfrI/dwJH+6GIzGrPuGsa7dI=; b=EoPxPw/l5K+NfAjb02ZZeuoXhr9RQmptcFzgWaBkOSJCWCWya4vSRkw0B3hYXobN4V CpMYoDcxKID4GFHoFdJXuVGZ+KUjYtnwdpQlk1yPpKi3CVObOW6J2fSJn80kzMoS2tOZ b3sSKxyY2mG16j79J9DrSO9klmS9rDlZX6Fb2jHYtswD65ScLLlWOa39KtDlFg6JxeIp 6c9GC/678bSs46i3kc/z0y6sMpTaGA2Lfo77MMIyMDGeFX+fRfbqazJZu1bHmnXQeToE syWbrqP+43vJH7Rus4gqmk++0XU3JkIBjYEdt3NZcDhPA4moNp6Ag8YI/UIKWRVZ4s8u DyHQ== X-Gm-Message-State: AOAM531G5R/LFtZwE19kOFu43X44FXpwof9XrrShc6awbLkAA5zFO+PI WoiFn/u1BQsFUBk476zzCRapa+zmHXk= X-Google-Smtp-Source: ABdhPJz0D3XJ5hP55ygW2RYxhk22jhdlt2cnuwbzC3FiUStqBv0CvvZz2KuVdT2zx+dM7ldZRQeo1A== X-Received: by 2002:a63:f201:: with SMTP id v1mr3295910pgh.250.1643030175589; Mon, 24 Jan 2022 05:16:15 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:16:15 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 5/6] net: udp: use kfree_skb_reason() in udp_queue_rcv_one_skb() Date: Mon, 24 Jan 2022 21:15:37 +0800 Message-Id: <20220124131538.1453657-6-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in udp_queue_rcv_one_skb(). Following new drop reasons are introduced: SKB_DROP_REASON_UDP_FILTER Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 1 + include/trace/events/skb.h | 1 + net/ipv4/udp.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 603f77ef2170..dd64a4f2ff1d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -330,6 +330,7 @@ enum skb_drop_reason { SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST, SKB_DROP_REASON_XFRM_POLICY, SKB_DROP_REASON_IP_NOPROTO, + SKB_DROP_REASON_UDP_FILTER, SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index e8369b8e8430..6db61ce4d6f5 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -27,6 +27,7 @@ UNICAST_IN_L2_MULTICAST) \ EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ + EM(SKB_DROP_REASON_UDP_FILTER, UDP_FILTER) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 464590ea922e..57681e98e6bf 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2120,14 +2120,17 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) */ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) { + int drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; struct udp_sock *up = udp_sk(sk); int is_udplite = IS_UDPLITE(sk); /* * Charge it to the socket, dropping if the queue is full. */ - if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) + if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) { + drop_reason = SKB_DROP_REASON_XFRM_POLICY; goto drop; + } nf_reset_ct(skb); if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) { @@ -2204,8 +2207,10 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) udp_lib_checksum_complete(skb)) goto csum_error; - if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr))) + if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr))) { + drop_reason = SKB_DROP_REASON_UDP_FILTER; goto drop; + } udp_csum_pull_header(skb); @@ -2213,11 +2218,12 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) return __udp_queue_rcv_skb(sk, skb); csum_error: + drop_reason = SKB_DROP_REASON_UDP_CSUM; __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); drop: __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); atomic_inc(&sk->sk_drops); - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); return -1; } From patchwork Mon Jan 24 13:15:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12722137 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39A19C433FE for ; Mon, 24 Jan 2022 13:16:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243132AbiAXNQX (ORCPT ); Mon, 24 Jan 2022 08:16:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243051AbiAXNQW (ORCPT ); Mon, 24 Jan 2022 08:16:22 -0500 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C4AEC06173B; Mon, 24 Jan 2022 05:16:21 -0800 (PST) Received: by mail-pj1-x1042.google.com with SMTP id nn16-20020a17090b38d000b001b56b2bce31so5921760pjb.3; Mon, 24 Jan 2022 05:16:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ppg6e0FUc7/+T7KoOP2mY3oDf3knGfZ3sgY11AP0m8c=; b=N5OpEeEZ2HG1lv9lhr/M0WNCOXjyW8crtPrGnqtEsi58aHeDVaonh/NC4L+/NAr7jA 1Au/zsIikA/hhJtAOy/Si8ivuFNx1hnQKBRgA2qw0GqeQY2IKv3k52SkBbLBaAKDznR9 jrEOQKcvWyqCAP7BoXZ2bih7m40BjApEvhdrNyV4yiBb++3LyIbtBXM4vXFHpn3nQilf YF4/RSVA+GM3cDZ7i/WEFCWJEiEw2me/ekjvL3M4jRmrlQ4/mcLp649Mjz+cGpMZQyLb yzeCQVHYhdT/wPs0FwtuZww57l9VZfgooDbnpp59W5lzDMtNjxNpmIEyF/GT3pCNk/X+ jLoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ppg6e0FUc7/+T7KoOP2mY3oDf3knGfZ3sgY11AP0m8c=; b=QqsVU4C75YS+WaVCAnSJVq2TodjjoNMl1PpfJqmpUJIlgpMQ07yVTDTG19IPRvRSQl 8sWP7mR+Fr41fWjwC82u0kWU9sm1gFCGzgXvQaypTT48j39tg8Idy5vTlC0zjih1BA3X KYWY9eI3qelOIkXiMLkUmm/P85q5IU7WzgtXqYD267rEASnCEOay0Z0TT0Yi2+V8N/8I 8Jgim2VZjeiHcaR/bfyvMrR4oCttFizds+k1Vgns2Al3qRUbGTD8N988BxtxCMIBKCpO nS5CwPnfQ1xHYqD1rJ12D1FJKEPbTo+7w+NXnyu+KWoHn0kh59FmNWnn7N4rYPteGhNk J8ew== X-Gm-Message-State: AOAM532GuMfNFN1+2hzm2+Ch4M985avV+KJJg0/Spn1+Ba5RYMTgKGR/ k60NXsW4m/C/cV6X8KGzkig= X-Google-Smtp-Source: ABdhPJxQNeH7Fa20w+9Hv2sUuwO57UWFPyWYTuKKQZ9D1pnJMIjizaXst04CmDMwtEPTRWhI7VmoYA== X-Received: by 2002:a17:903:32c1:b0:14b:3c0c:9118 with SMTP id i1-20020a17090332c100b0014b3c0c9118mr7867771plr.58.1643030181201; Mon, 24 Jan 2022 05:16:21 -0800 (PST) Received: from localhost.localdomain ([43.132.141.9]) by smtp.gmail.com with ESMTPSA id j11sm16508806pfu.55.2022.01.24.05.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jan 2022 05:16:20 -0800 (PST) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, imagedong@tencent.com, edumazet@google.com, alobakin@pm.me, paulb@nvidia.com, pabeni@redhat.com, talalahmad@google.com, haokexin@gmail.com, keescook@chromium.org, memxor@gmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, cong.wang@bytedance.com Subject: [PATCH net-next 6/6] net: udp: use kfree_skb_reason() in __udp_queue_rcv_skb() Date: Mon, 24 Jan 2022 21:15:38 +0800 Message-Id: <20220124131538.1453657-7-imagedong@tencent.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220124131538.1453657-1-imagedong@tencent.com> References: <20220124131538.1453657-1-imagedong@tencent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Menglong Dong Replace kfree_skb() with kfree_skb_reason() in __udp_queue_rcv_skb(). Following new drop reasons are introduced: SKB_DROP_REASON_SOCKET_RCVBUFF SKB_DROP_REASON_PROTO_MEM For example, following log will be printed by ftrace when udp socket receive buff overflow: > 3345.537796: kfree_skb: skbaddr=00000000f013dfb6 protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3345.638805: kfree_skb: skbaddr=00000000cbc73bc7 protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3345.739975: kfree_skb: skbaddr=00000000717f24bb protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3345.841172: kfree_skb: skbaddr=00000000c62d20e9 protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3345.941353: kfree_skb: skbaddr=000000007eea9d4d protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3346.042610: kfree_skb: skbaddr=00000000c62d20e9 protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3346.142723: kfree_skb: skbaddr=00000000717f24bb protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF > 3346.242785: kfree_skb: skbaddr=00000000cbc73bc7 protocol=2048 location=00000000c74d2ddd reason: SOCKET_RCVBUFF Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 5 +++++ include/trace/events/skb.h | 2 ++ net/ipv4/udp.c | 10 +++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index dd64a4f2ff1d..723fc1cbbe3c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -331,6 +331,11 @@ enum skb_drop_reason { SKB_DROP_REASON_XFRM_POLICY, SKB_DROP_REASON_IP_NOPROTO, SKB_DROP_REASON_UDP_FILTER, + SKB_DROP_REASON_SOCKET_RCVBUFF, /* socket receive buff is full */ + SKB_DROP_REASON_PROTO_MEM, /* proto memory limition, such as + * udp packet drop out of + * udp_memory_allocated. + */ SKB_DROP_REASON_MAX, }; diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h index 6db61ce4d6f5..0496bbb0fe08 100644 --- a/include/trace/events/skb.h +++ b/include/trace/events/skb.h @@ -28,6 +28,8 @@ EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY) \ EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO) \ EM(SKB_DROP_REASON_UDP_FILTER, UDP_FILTER) \ + EM(SKB_DROP_REASON_SOCKET_RCVBUFF, SOCKET_RCVBUFF) \ + EM(SKB_DROP_REASON_PROTO_MEM, PROTO_MEM) \ EMe(SKB_DROP_REASON_MAX, MAX) #undef EM diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 57681e98e6bf..ca9ed24704ec 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2093,16 +2093,20 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) rc = __udp_enqueue_schedule_skb(sk, skb); if (rc < 0) { int is_udplite = IS_UDPLITE(sk); + int drop_reason; /* Note that an ENOMEM error is charged twice */ - if (rc == -ENOMEM) + if (rc == -ENOMEM) { UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS, is_udplite); - else + drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF; + } else { UDP_INC_STATS(sock_net(sk), UDP_MIB_MEMERRORS, is_udplite); + drop_reason = SKB_DROP_REASON_PROTO_MEM; + } UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); - kfree_skb(skb); + kfree_skb_reason(skb, drop_reason); trace_udp_fail_queue_rcv_skb(rc, sk); return -1; }