From patchwork Fri May 13 03:03: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: 12848310 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 0F65EC433F5 for ; Fri, 13 May 2022 03:04:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376630AbiEMDE5 (ORCPT ); Thu, 12 May 2022 23:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358809AbiEMDEy (ORCPT ); Thu, 12 May 2022 23:04:54 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9569028ED19; Thu, 12 May 2022 20:04:52 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id c1-20020a17090a558100b001dca2694f23so6576006pji.3; Thu, 12 May 2022 20:04:52 -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=7iuYS+DTP82eQ8OK6un+T5VxnMX84G3Tig9oHmRFRKk=; b=evv1ZaG5LMKZCMQIuFTvXErFTbSpJxWI53hwRnIMD3Ry7NzuDyhr2UdnEOA2ARD58M bJ/1z6Ua5ytyY7htORu08sxLulzGCICuDFY2YhCIFgZqL/rlYWWfQJ47rt0/MDivAynw yeNZQRVHwWjibOFb+oRs4lm/xZJmGIF69rbpY97De8uDheskdLplJV5xeMgJGXx+uGVe 0iajjUlp6quZvj/1Gc6cTDS+D/iIOBUPKDCrMu8m84CA+joWr6T6u7r7eQ3ZFzLifVXF 37QNzysw6i9IchOzVbHFhWkJC+OM7YSqs3SenfP8xAckmCw5kXfNjEIInttyIoKLCvx5 Lz5A== 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=7iuYS+DTP82eQ8OK6un+T5VxnMX84G3Tig9oHmRFRKk=; b=uGp06GkhvHdHSAYDjP8P8O/TsKfr+JlSY5hGzYmtnHtiqbeXjHtSthlmU4Ugh2ewts z45y2+g4C1EPsJP4GJn1fMQLk20FfXkOSyS4mWY0VT2m7HKFJYEcobpwuKVnC5CsVk4l eoJHDSV1mYwAvzsWzNAW7jGccuf4udwdVIWF02UYfRCT+cJQZXAhE6CbgWIqjy290af4 01n+1J7AoK4ZdehWm4FsJG6reGe2TDrA1DmyJIjxin50G23J4GuV055Z5s4diHmN6bCA Yg0XuLuBn22pSudDxx2Wh01EcaTO5olVZdDG1E6jDE0hFzkLGMC9C/+l1uLf2LFMWM7P EjKQ== X-Gm-Message-State: AOAM530/Z/iD/3OKk+MnP0aRVLGJnzvUyOYkGdBm0IPY26GEM0RAOh0L Kaw3KgcknbR+48yHvP0Pq9o= X-Google-Smtp-Source: ABdhPJxRklea0fuQGLM4tboxMaCGdVeTGON3stKpT58ilxbUrHt17Ui+9ICoqRBsjze4p+BrlUkszQ== X-Received: by 2002:a17:902:e543:b0:15e:fbaf:ba8c with SMTP id n3-20020a170902e54300b0015efbafba8cmr2700972plf.78.1652411091944; Thu, 12 May 2022 20:04:51 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.26]) by smtp.gmail.com with ESMTPSA id b7-20020a170903228700b0015e8d4eb1f8sm638693plh.66.2022.05.12.20.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 20:04:51 -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, Jiang Biao , Hao Peng Subject: [PATCH net-next v3 1/4] net: dm: check the boundary of skb drop reasons Date: Fri, 13 May 2022 11:03:36 +0800 Message-Id: <20220513030339.336580-2-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513030339.336580-1-imagedong@tencent.com> References: <20220513030339.336580-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'. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng 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 Fri May 13 03:03: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: 12848311 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 D7D4EC433F5 for ; Fri, 13 May 2022 03:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376647AbiEMDFF (ORCPT ); Thu, 12 May 2022 23:05:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358809AbiEMDFE (ORCPT ); Thu, 12 May 2022 23:05:04 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A351228ED02; Thu, 12 May 2022 20:04:59 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id v11so6524248pff.6; Thu, 12 May 2022 20:04:59 -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=i20mAFU7NrHSI3GzXENtfgmQUTPKqxrlvWBJ4mCwr9c=; b=joiLveGVf3AJvcPBN/LqMUAK0HIU3rBu0aMekWowF8XK+DwlD4XjYdYc7vGUYAB+ba GvU/tgViuBZYutmEgCuF2fN6UbDtPHcGXYEHTZJdA2nccLQDTbnvSOcG7Vs6x20xa37d OVtL0csbLTpmzXQfiLTW1ya/Nl4jA+1dpRu73J9zYN+8FB7++Pz7L09fdXQQtFrKppo8 oLTZops//4KpZMuyaAg7T31FxYVQ6pvtM37pHZ868ibKlT1tpA/Be1kDMFxQmT8FLYKg yBfC4EE4Uy4f6vduQdvlFL0F0L1cCQWpFp1es8z9bHwmGtoY22gFQWdTHNdLgKax3W1h wd9A== 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=i20mAFU7NrHSI3GzXENtfgmQUTPKqxrlvWBJ4mCwr9c=; b=jBYEYSa9ZObT1OjaSc8q3RYtJ+lL2wp93eW2gaO0NA3pmnJrpnjpCrPOflsxrI3O4g edzZsYDYatGVuQYKlwNfKotPa8RQkVhIXiv/7lVexq3U0plVoPqHBYTwY008D1zWwa64 3DRMw4Cuidpz2oKW1Wwp2ff/vdJNig2w4rLJk/jCL0RJ6+8z7YBw1WrAstMBYlvXjbXq u5mFdo0J4xXJJKQrPyl18I1B8gO2WKCU16EY9DRf+BFwUlm4i4KSLER1WGYErNHUjwKZ 7nAA4ffUS7hFdN/CC6nojPguLC9tpMPWR75ewtPzMcfpJ8sgL//I+6e2eai26t9GK9Oh AV1g== X-Gm-Message-State: AOAM532bNAnJpu24aSGFff1kpic7r5ZPeQ42QWGC+/Fv2kE/47PjHOtR C3s3zxs/XB24GF8EAcK/RIE= X-Google-Smtp-Source: ABdhPJyJnmaidAHX0E8/Nd4wSwXKJOzOqNRl2z0ABpT0KruYsD2fC7cnf8jrVtFiwuezqjXXxF41zA== X-Received: by 2002:a63:c112:0:b0:3c6:b835:2043 with SMTP id w18-20020a63c112000000b003c6b8352043mr2209742pgf.528.1652411099200; Thu, 12 May 2022 20:04:59 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.26]) by smtp.gmail.com with ESMTPSA id b7-20020a170903228700b0015e8d4eb1f8sm638693plh.66.2022.05.12.20.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 20:04:58 -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, Jiang Biao , Hao Peng Subject: [PATCH net-next v3 2/4] net: skb: check the boundrary of drop reason in kfree_skb_reason() Date: Fri, 13 May 2022 11:03:37 +0800 Message-Id: <20220513030339.336580-3-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513030339.336580-1-imagedong@tencent.com> References: <20220513030339.336580-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() with DEBUG_NET_WARN_ON_ONCE(). Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- v3: - don't reset the reason and print the debug warning only (Jakub Kicinski) --- net/core/skbuff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 15f7b6f99a8f..fab791b0c59e 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -771,6 +771,8 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) if (!skb_unref(skb)) return; + DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX); + trace_kfree_skb(skb, __builtin_return_address(0), reason); __kfree_skb(skb); } From patchwork Fri May 13 03:03: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: 12848312 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 598D6C433F5 for ; Fri, 13 May 2022 03:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376654AbiEMDFR (ORCPT ); Thu, 12 May 2022 23:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376661AbiEMDFN (ORCPT ); Thu, 12 May 2022 23:05:13 -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 161AC28ED02; Thu, 12 May 2022 20:05:06 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id m12so6722741plb.4; Thu, 12 May 2022 20:05:06 -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=HDu0z3UNTUmPRRo575SlQWaiiOZEc5TgsbPLrsF6F5E=; b=XM05gpTuaLNiPbmcDzOGEpLg3H7KYY/vEcUvDQu5ZtfbQucAiN14eegoAUY7qAUDoj hgJ4/mX2nm6czn81tJ6Wa6qjGZJDXUBdvknkqaF/sxhMMXtefI7jNLT7MfEcVxoDVG7I XcDMgjjbQkBCEY1pzYzdOHHmCFIF/GJxlS5GxHzIM4eS4jYL8sr2KkQ5Jb55XPu4Xkid PnOodOG3iDzvS2F5WORd8Px8ne5YDsCJCCzKOiFldIDODIKrl90iYp5CXQibIpnNRFqV bmE7MUxp9gXvER2qnAgdMzNyzeoXVI8QxsFikYKbcf4JRwxperZxj2e499hoeyZYuxTI WkJg== 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=HDu0z3UNTUmPRRo575SlQWaiiOZEc5TgsbPLrsF6F5E=; b=g2BzpE8CmAvpPMFkefHw5bsAIHyRapZtR0lwk/CuzKmC9/wUEBpm+QX0SOnQ9mPujV DqQkQl4LB9BRSs7xoExa3R8zG+Yz+OMK6U5ktiF/+UxYmxmvmxIWUcuDJwlUHu4d0A5+ vV3ZiytB3usnyQUD1dzlMxAw56yniM9ITACJuNWgtDipgwtWnBeX+ABU0hKbIxrgh0rI st2ZmCXKhkpDA29mCpkWCCJL3nAy8gDuilcYbtVnaqNB3yyhp85EFHZFIdIrhITdnQok sPkJJtnd0L4jPVb+laxBcWSyoHdhA+sgHAIpNDwJicMBQJNn4JapmfaTrq5A4R7LNjmA k0kQ== X-Gm-Message-State: AOAM531mi33Rc79js6pSVkFJegxFbBOwxBtJz8Sey765QhXrV9cTdC7i tiojbKS1fZtP5DOtBxGAJRU= X-Google-Smtp-Source: ABdhPJxvEagH5pqXuRunEPMlbOlkdX8lEFUheBpWfF12/LSGhjF739dwmFECeFlNij2SlrVWPs96wA== X-Received: by 2002:a17:90b:1e53:b0:1dc:5cdf:565e with SMTP id pi19-20020a17090b1e5300b001dc5cdf565emr2692081pjb.78.1652411105651; Thu, 12 May 2022 20:05:05 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.26]) by smtp.gmail.com with ESMTPSA id b7-20020a170903228700b0015e8d4eb1f8sm638693plh.66.2022.05.12.20.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 20:05:05 -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, Jiang Biao , Hao Peng Subject: [PATCH net-next v3 3/4] net: skb: change the definition SKB_DR_SET() Date: Fri, 13 May 2022 11:03:38 +0800 Message-Id: <20220513030339.336580-4-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513030339.336580-1-imagedong@tencent.com> References: <20220513030339.336580-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. Reviewed-by: Jiang Biao Reviewed-by: Hao Peng 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 Fri May 13 03:03:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Menglong Dong X-Patchwork-Id: 12848313 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 B2DEDC433F5 for ; Fri, 13 May 2022 03:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376662AbiEMDF0 (ORCPT ); Thu, 12 May 2022 23:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376659AbiEMDFW (ORCPT ); Thu, 12 May 2022 23:05:22 -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 BBDC8296BCD; Thu, 12 May 2022 20:05:10 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so6587414pjm.1; Thu, 12 May 2022 20:05: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=BHwxj5/3zfJqT2Wrvjpo8DsHfoccm9nsiUOrbL558ys=; b=c0U/VBDd0f57x+RlO6UJhtq14moDx1LVcq/Xt9i5HyZxtKjX3JjQZYEmbFdwKUSo9q hhbGiXUAY7gzbWnOHD17WM0vDC3Bplaq4xwTLO4rwcy3E60mweRlYpjuBfKb91k5EivS guAG697EhWtP5JlRekHvAbQk8D7cDtzmYVh1EAi0HrSZe6LakOwvpqjO6rFU/KRhOC37 CouYvy+lJ28/OjpEzED4httUbrb2q7ZbCBbAutdnkER4Ny6B45AkFmPBCYf1BJtuYZoU ry0LMWmon8dtrWgd4zKoAztMHTaneMEDSkGadn+/WgtHirYiB9I84Swa4a89Bwe1ZVe4 p7FQ== 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=BHwxj5/3zfJqT2Wrvjpo8DsHfoccm9nsiUOrbL558ys=; b=InMgo1xddcAwtIemPbuzkPsO+LM0mMwoGlrGICuOVWM3xSRqKiMkQvWZBLLC6YJRKw 4V21BWR5vhZcSHerDg4Jm03OPvYl5AFZhagNBoKYw0PuQtvA1n6/0pxrItJ4gI97ByYq UKUA5LXKySHs5gAi4RAEd91kXz6C2Eq16owvAv6ps1zUthMwzs78D9/vO462OmrbRYTE RtGNsICwgznEzNkzQHQkEzUtJH04Szmap4XK8ixMi10RYL4sZ63HfayCpiXkulerMATz uvLdFfaIoYMHEIqdYHWv5274uh1cxb163meU7+B4L58hUXobTinuzuuovqMzomyQzrB0 bEBQ== X-Gm-Message-State: AOAM5335VOhVVU+OIf06XX6mEWJOQPWKX9wRzjWujMinQ5SJQJ0T2u1f k5D8mX3FYVRytpZZt2o/oso= X-Google-Smtp-Source: ABdhPJwYAcMlmA0kpYY5SJtvzHRDsIyHJ7UtTXrxKOAqW1Cy9GoJNNiOfM8KsEypDaHq1ZKvCCdX2g== X-Received: by 2002:a17:902:f652:b0:156:701b:9a2a with SMTP id m18-20020a170902f65200b00156701b9a2amr2497221plg.14.1652411110315; Thu, 12 May 2022 20:05:10 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.26]) by smtp.gmail.com with ESMTPSA id b7-20020a170903228700b0015e8d4eb1f8sm638693plh.66.2022.05.12.20.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 20:05: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, Jiang Biao , Hao Peng Subject: [PATCH net-next v3 4/4] net: tcp: reset 'drop_reason' to NOT_SPCIFIED in tcp_v{4,6}_rcv() Date: Fri, 13 May 2022 11:03:39 +0800 Message-Id: <20220513030339.336580-5-imagedong@tencent.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513030339.336580-1-imagedong@tencent.com> References: <20220513030339.336580-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") Reviewed-by: Jiang Biao Reviewed-by: Hao Peng Signed-off-by: Menglong Dong --- v3: - remove new lines between tags 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: