From patchwork Thu May 12 12:33:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12847644 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 72403C433F5 for ; Thu, 12 May 2022 12:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353799AbiELMeB (ORCPT ); Thu, 12 May 2022 08:34:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353797AbiELMd7 (ORCPT ); Thu, 12 May 2022 08:33:59 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C48D5A0B9; Thu, 12 May 2022 05:33:57 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id q4so4710336plr.11; Thu, 12 May 2022 05:33:57 -0700 (PDT) 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=lu6LLmf+mIxeAaUg73+GivA9lAoPCMxzQrmOZW/LzWA=; b=mw95GprIIc/lu6UHRgabNxbg/fwSnS6eFbpNvmjm3oQBhPPGC/PJsjUzzXDki9gJIt T9ShGoQYViA7HRexkaKEVv6HmJ2/SQ9n0cByrCBHMBw4NGFaHrLd9Vaz/dfgHLLXREQm OEgGQqlgnSgTc4VvJyHV+LKMfgaBOFR0lcVCo2pIdcHBmYEB/R5er+u+gjDiGE1BHzFf uhasXmC13rmr8HsSvgOddv6Qo7GpWzgB97OgYXfEZMhlrYYbRX6aD1ur88tEVsDOKIn0 ige3I+lyYgOhD7CiQAxkFJLD/XG1d0SH/ABQJkMh1Z0UlgUDjvtuPp56oSYuKM7qsfz4 I0Dw== 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=lu6LLmf+mIxeAaUg73+GivA9lAoPCMxzQrmOZW/LzWA=; b=G8A6PV32HzqVWircY9ROlnzRmT1wH/TtMbpycTU08zak1GErh3JoqZ+qgooOOXZpYc adLZ6l9vKMr2kDrmq/IgmFbyUiQjCymL0b8Ar2GA6+KuA+4K7PHEJM5B7TZJ9jx1yWCk +ueWOZI16Q6okxFhnXf0/VE9T4oAPPy1KmZmARbyZ3KHUqMVzlE9c5xw4hDFBXLWJYqq ZQa5S5Rnz76RwM+lTrEqhyEMvXrcPaFIC+7wAlTnQ1NhmeQOcvDNUtb7fE2u8GMmov6H Qfih/b71PWrsiHgrqSgYM4cGp269+Toii4BlgmzEyF8xeqiyruGtvY34pVf4egvVYpT0 HxMQ== X-Gm-Message-State: AOAM531Z/52ShLMnbSzCUc7N+iTitkJvJyUE0IyjiyH27lTjE3G0NyFz LUhz7nh5uWLCYzPGldFkM0U= X-Google-Smtp-Source: ABdhPJx20iJA02L5mSNF6Fhswk+orQRSVthqsiRRtSCPTOA97nBgU5+TrxbnUnyg0qK+Wmqg/uST8g== X-Received: by 2002:a17:903:20f:b0:158:d86a:f473 with SMTP id r15-20020a170903020f00b00158d86af473mr30294897plh.92.1652358836786; Thu, 12 May 2022 05:33:56 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.112]) by smtp.gmail.com with ESMTPSA id y24-20020a63de58000000b003c14af50643sm1738130pgi.91.2022.05.12.05.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:33:56 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: nhorman@tuxdriver.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, asml.silence@gmail.com, willemb@google.com, vasily.averin@linux.dev, ilias.apalodimas@linaro.org, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 1/4] net: dm: check the boundary of skb drop reasons Date: Thu, 12 May 2022 20:33:10 +0800 Message-Id: <20220512123313.218063-2-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220512123313.218063-1-imagedong@tencent.com> References: <20220512123313.218063-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 The 'reason' will be set to 'SKB_DROP_REASON_NOT_SPECIFIED' if it not small that SKB_DROP_REASON_MAX in net_dm_packet_trace_kfree_skb_hit(), but it can't avoid it to be 0, which is invalid and can cause NULL pointer in drop_reasons. Therefore, reset it to SKB_DROP_REASON_NOT_SPECIFIED when 'reason <= 0'. Signed-off-by: Menglong Dong --- net/core/drop_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index b89e3e95bffc..41cac0e4834e 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -517,7 +517,7 @@ static void net_dm_packet_trace_kfree_skb_hit(void *ignore, if (!nskb) return; - if ((unsigned int)reason >= SKB_DROP_REASON_MAX) + if (unlikely(reason >= SKB_DROP_REASON_MAX || reason <= 0)) reason = SKB_DROP_REASON_NOT_SPECIFIED; cb = NET_DM_SKB_CB(nskb); cb->reason = reason; From patchwork Thu May 12 12:33:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12847645 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 B3F54C433F5 for ; Thu, 12 May 2022 12:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353814AbiELMeD (ORCPT ); Thu, 12 May 2022 08:34:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353812AbiELMeC (ORCPT ); Thu, 12 May 2022 08:34:02 -0400 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 85C856472D; Thu, 12 May 2022 05:34:01 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id iq10so5068605pjb.0; Thu, 12 May 2022 05:34:01 -0700 (PDT) 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=0V/g4vf7d52LTUG/UsmwgEG5VgHlj0HZXVekJyZLmLw=; b=G/JVuwSEPN76TvxMfqy//u63ILusYW4sCTGj5y3HNBk98lCEIJqMpXEOmk6rQJ30nj YfElfvpOg/oJXQb6Fd8PqMKj9iJ5o+kXrk/NgCi1ZFybwDX37pJMyXV5MiT7bHxnlT25 IJmgExMmwGxkEnetQCrSuuQVCLGtJIhNQHKxTSIrUr3C68BjSneW5MI+xmddALoBocqL tIEeg7BrUGPxr4J3Q9TuPGO1l6t5zjg/l5XF89L6kf8/497QHu2PbVk6YftG7hBjgpp6 /LcDgWuukBWtHf6lB1JWmX1hhPEr4hMF3PeNjuGBASicbojf2GJ6j3ukd8cUQ1nLMu5m A4IA== 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=0V/g4vf7d52LTUG/UsmwgEG5VgHlj0HZXVekJyZLmLw=; b=cXYJZK7jDEXmKDIKsAEYoUWg7XOTUSo6IOGGvcYiDXtXcKBiJ+8T8ZZmwbAX4T3HcA 0tOD27o0fv6f9rYp+2bXTc2x6P+NaRLA1gnXg/hGxWgJi07pxvtcQtUo32SPwrM6YTN/ gG4XLzBIUvK6WIy6u/fWz92WKE7OK0ZF3uTt7mLXXo7Gtkna3WjGUtLGwyHU5Ooay+yB KnTqEX9bUyceqdxHX9jN7yHcQ41z0j5Yj8+B9cup77fY1yVvwXjs7K/J2btxG/8uSEBM SdINJBYwMu6kj8/FoSANpc3wRmI40UydrvIlzE5+uHySYWLfEnpyswB7zEI6SUOScORa 31Pg== X-Gm-Message-State: AOAM530kEP4VUhiTTQkKVGNOq68OLzFUJcBhKfXuzyZLnz7d0RzOX5ez GW5H+np4HclIgxOXO2GF9VQ= X-Google-Smtp-Source: ABdhPJwKDLSY6KwMpO0cPuAPisRwuDA6Z/r2td7rBvg2PXRrUAZP6WQ2SwOzd9BWZu2NhCBfVvERwQ== X-Received: by 2002:a17:90b:1c04:b0:1dc:4dfd:5a43 with SMTP id oc4-20020a17090b1c0400b001dc4dfd5a43mr10899801pjb.160.1652358841119; Thu, 12 May 2022 05:34:01 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.112]) by smtp.gmail.com with ESMTPSA id y24-20020a63de58000000b003c14af50643sm1738130pgi.91.2022.05.12.05.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:34:00 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: nhorman@tuxdriver.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, asml.silence@gmail.com, willemb@google.com, vasily.averin@linux.dev, ilias.apalodimas@linaro.org, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason() Date: Thu, 12 May 2022 20:33:11 +0800 Message-Id: <20220512123313.218063-3-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220512123313.218063-1-imagedong@tencent.com> References: <20220512123313.218063-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 Sometimes, we may forget to reset skb drop reason to NOT_SPECIFIED after we make it the return value of the functions with return type of enum skb_drop_reason, such as tcp_inbound_md5_hash. Therefore, its value can be SKB_NOT_DROPPED_YET(0), which is invalid for kfree_skb_reason(). So we check the range of drop reason in kfree_skb_reason() and reset it to NOT_SPECIFIED and print a warning with DEBUG_NET_WARN_ON_ONCE() if it is invalid. Signed-off-by: Menglong Dong --- net/core/skbuff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 15f7b6f99a8f..e49e43d4c34d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -771,6 +771,11 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) if (!skb_unref(skb)) return; + if (unlikely(reason <= 0 || reason >= SKB_DROP_REASON_MAX)) { + DEBUG_NET_WARN_ON_ONCE(1); + reason = SKB_DROP_REASON_NOT_SPECIFIED; + } + trace_kfree_skb(skb, __builtin_return_address(0), reason); __kfree_skb(skb); } From patchwork Thu May 12 12:33:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12847646 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 008C5C433F5 for ; Thu, 12 May 2022 12:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353835AbiELMeU (ORCPT ); Thu, 12 May 2022 08:34:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353828AbiELMeS (ORCPT ); Thu, 12 May 2022 08:34:18 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EBE365419; Thu, 12 May 2022 05:34:05 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso4744753pjb.5; Thu, 12 May 2022 05:34:05 -0700 (PDT) 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=Y5dFPjnyVYyt7e0oJj6359izJi2BOR8deoMws+Pet9s=; b=NIh3uopiwf4V3MI0QnLFTh9xT0Nf7QLGBqNCxLhJiR0AfeSywsGdaEPBdxK8pXwEyl gc4ZS/T4DFa2NDU+H+Y5Ze/QeTbMV/vRS9AQrP7llYXbN8XPFkD8XaiRAxt8t1Q6Ak0n LDM61V07i+ZAblvWZNKiG40xwOn69PnoT0HaFr56R5FCAyOvZ4iHuu9C19oe2IDS+gGL V3Ffxg8Vv2QE4n4FGO6/tsIjkE1bXK5difTRdNaPSOauhvCF4NikOvOgzo1NfcYhHq2S W53ZduDvMpl4/gBAMzpl7+Kvag89GRQFjtwnAsf12Tu3FDVvHp202hPT5g1BPND4XkHx 1log== 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=Y5dFPjnyVYyt7e0oJj6359izJi2BOR8deoMws+Pet9s=; b=KVV0JcuBfacV3oTWcSo8tEWw0Fq1auy/t5LGCOEO5T36GAsGSh0y0psoSPvkQB6k0H 3p/XAoOU656U3O7ljb4G1eebPX1UdQRE91AYbVFrBP07lE4yqp6guB7qg3nFphMtgAz0 TlVjn7+00DiJYI5OhYnfLI2JkPP17wRQQh7Dgruy+iAOpn7DeoUYZ+z4W0jtehxoKaV0 i7YS8aRI7xvmggS/VQVelQOnOTUVsFPb6KwOk/kmvIOprlnG6NW/WZ2FDQ2RqVaEeD+M mdiDejbBaAkRQgEglAxZfknN5+XQcM61KlZkOl7QwiWCsZLQF5sdjiQe0JCzhSpu1YfI QtWw== X-Gm-Message-State: AOAM533b6Pv74th393h+DOFdHTJvYGNzba898NTX0KwsHczMfDtYSMTr uhXh80KHFmsSqv4WbHrBF4I= X-Google-Smtp-Source: ABdhPJxO/W8GjBTSNxjCKoe0QKYbDlQw1BDaSodAE0by9rDf7QDxDsZU39X2GOS9GPUhC3/75KrKHw== X-Received: by 2002:a17:902:e883:b0:15e:bfbc:1a53 with SMTP id w3-20020a170902e88300b0015ebfbc1a53mr30412111plg.62.1652358845456; Thu, 12 May 2022 05:34:05 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.112]) by smtp.gmail.com with ESMTPSA id y24-20020a63de58000000b003c14af50643sm1738130pgi.91.2022.05.12.05.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:34:04 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: nhorman@tuxdriver.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, asml.silence@gmail.com, willemb@google.com, vasily.averin@linux.dev, ilias.apalodimas@linaro.org, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 3/4] net: skb: change the definition SKB_DR_SET() Date: Thu, 12 May 2022 20:33:12 +0800 Message-Id: <20220512123313.218063-4-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220512123313.218063-1-imagedong@tencent.com> References: <20220512123313.218063-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 The SKB_DR_OR() is used to set the drop reason to a value when it is not set or specified yet. SKB_NOT_DROPPED_YET should also be considered as not set. Signed-off-by: Menglong Dong --- include/linux/skbuff.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index b91d225fdc13..4db3f4a33580 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -510,7 +510,8 @@ enum skb_drop_reason { (name = SKB_DROP_REASON_##reason) #define SKB_DR_OR(name, reason) \ do { \ - if (name == SKB_DROP_REASON_NOT_SPECIFIED) \ + if (name == SKB_DROP_REASON_NOT_SPECIFIED || \ + name == SKB_NOT_DROPPED_YET) \ SKB_DR_SET(name, reason); \ } while (0) From patchwork Thu May 12 12:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12847647 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 A8346C433EF for ; Thu, 12 May 2022 12:34:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353848AbiELMe3 (ORCPT ); Thu, 12 May 2022 08:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353844AbiELMeT (ORCPT ); Thu, 12 May 2022 08:34:19 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E5C765D3B; Thu, 12 May 2022 05:34:10 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d22so4715541plr.9; Thu, 12 May 2022 05:34:10 -0700 (PDT) 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=4qRhse/EElRlNlt5CjLk1lxqck1AwLgnmQmAk8U8knE=; b=C+xI6Uel5XoPC9VAdCee+cw2YQDuNTCtXZ9d5B2ntwHiDYMeajxivbXN5ptDz6lBML hqjXHE+42UHaiNVz8CmKXL8sp//jlMPI1mtY1e8aTtMq9FXU0c70+3xMxpEwrQYeU2yZ 2w1pXUdnVUuu2HStV3QjU0QIMaCTX92Hs87KPCP0NWhYcZLpMOptflV1AUNEN7KkDmLc aMYe4fDQpj/dLuB7SHr4oxXKKntQUgiRydr4qe9Gk1KWLZOnwIL1A5yIGdTLjNO8djfN 0hAaJtXfdcKkn8UfOfOQkEdqW2SPA9TOiLD6Fg8CnQi3WKNhXN2oUyjeywjECwOtsUXl uBTg== 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=4qRhse/EElRlNlt5CjLk1lxqck1AwLgnmQmAk8U8knE=; b=NeoSguKwc7tAFX/zrsjsnONre3Zjtg1DM1RX2bNyyikmRnpusytZaH6buxdfU/9kBN 1lY9NzUjxAP2OhUzh1rnhR1Rxkk2Wbyu3hxwAfGoc5UjQIDy9sjrb+41qsi8GP4+1aJl iGoFGegSoDFGU+U6qQAmw0373CFCW7gNO7dwBsjLSCBjmjkjqzuOmiQSF5jqsppNNIOO RZnNKNpoxdQbrIsS3fvLqVR9BpHcU9vRsyqjF1KZGqkjOrCgLnPeAqnoFwZU93jjdb44 3g6UHFMYc6qlXYT+IAR/ALb+GYZz1s4iZc6KQzFN53HSYgiSUfw/jM1zqZHutW217lgu hy9g== X-Gm-Message-State: AOAM532u5qZtutZgZ0k5mm5qtGsVTmDz8nojbv0z0SrewOhWv5ImH1x1 Qja1d0UcyonQo1hJBQ7xgqE= X-Google-Smtp-Source: ABdhPJy+qLF/vwUaeC0vpFzsUXpOlPWIH1u4fK9KybQ0x/Y/yyc1GHdj/+XljeZC7HGYV/vePxcfSg== X-Received: by 2002:a17:902:b18e:b0:15f:b2c:6ca with SMTP id s14-20020a170902b18e00b0015f0b2c06camr20550250plr.84.1652358849787; Thu, 12 May 2022 05:34:09 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.112]) by smtp.gmail.com with ESMTPSA id y24-20020a63de58000000b003c14af50643sm1738130pgi.91.2022.05.12.05.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:34:09 -0700 (PDT) From: menglong8.dong@gmail.com X-Google-Original-From: imagedong@tencent.com To: kuba@kernel.org Cc: nhorman@tuxdriver.com, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org, imagedong@tencent.com, kafai@fb.com, talalahmad@google.com, keescook@chromium.org, asml.silence@gmail.com, willemb@google.com, vasily.averin@linux.dev, ilias.apalodimas@linaro.org, luiz.von.dentz@intel.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 4/4] net: tcp: reset 'drop_reason' to NOT_SPCIFIED in tcp_v{4,6}_rcv() Date: Thu, 12 May 2022 20:33:13 +0800 Message-Id: <20220512123313.218063-5-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220512123313.218063-1-imagedong@tencent.com> References: <20220512123313.218063-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 The 'drop_reason' that passed to kfree_skb_reason() in tcp_v4_rcv() and tcp_v6_rcv() can be SKB_NOT_DROPPED_YET(0), as it is used as the return value of tcp_inbound_md5_hash(). And it can panic the kernel with NULL pointer in net_dm_packet_report_size() if the reason is 0, as drop_reasons[0] is NULL. Fixes: 1330b6ef3313 ("skb: make drop reason booleanable") Signed-off-by: Menglong Dong --- v2: - consider tcp_v6_rcv() --- net/ipv4/tcp_ipv4.c | 1 + net/ipv6/tcp_ipv6.c | 1 + 2 files changed, 2 insertions(+) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 918816ec5dd4..24eb42497a71 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2101,6 +2101,7 @@ int tcp_v4_rcv(struct sk_buff *skb) } discard_it: + SKB_DR_OR(drop_reason, NOT_SPECIFIED); /* Discard frame. */ kfree_skb_reason(skb, drop_reason); return 0; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 60bdec257ba7..636ed23d9af0 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1509,6 +1509,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) discard: if (opt_skb) __kfree_skb(opt_skb); + SKB_DR_OR(reason, NOT_SPECIFIED); kfree_skb_reason(skb, reason); return 0; csum_err: