From patchwork Thu Jul 13 18:05:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13312563 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 001B41F92B for ; Thu, 13 Jul 2023 18:05:30 +0000 (UTC) Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96300271F for ; Thu, 13 Jul 2023 11:05:29 -0700 (PDT) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1b3f281c4e1so843755fac.3 for ; Thu, 13 Jul 2023 11:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1689271529; x=1691863529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lq7JLWSnO4kLsX66Bz5Lma1zemUZ3rsSNZ/srgBkgmo=; b=eP43kPRLRepvAZpcqoPrfIqUTZPZ/uSRp9gXi/Eu9I/owN6iS8AwVMslZ/sA8J7dvz KOOHsamX5w6cefZW0WIyRQqTlAcWBBAqvqGLW06TYJnnJMSbwBGA71ACZ4oZCoO2dINP Cv51168XhccDOHZ1p519MBD0EmTSiWgOBhMrRIA+LBbI9Pl01Iqh+sckRnM8mBMtHvcD znHVfZLxZTNNflUWoQMAiKV3EsYzi/QEfZQdgcRY8FkI5fxzc9QnpJ8dLHNxGRzwlolt s4csTUmcmD9RHbQqi2fXbpPT7ZBWuftfUsALMy7AC4RNGVIWuf+3eP2/sMWC2+0gxXgd 5eLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689271529; x=1691863529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lq7JLWSnO4kLsX66Bz5Lma1zemUZ3rsSNZ/srgBkgmo=; b=Z4Fk+Z1PbN9Eiee8WnguQM/h9dEyTVp1K30A2YyEfczjkZuf4g0l+0JM1Hyd/WfKBE VtbI6r9LwnUiNb9CWsEglarxXsS2Ixb5gtvebANWW19j/as6IHtcY4c6LyhebQo0pFXy rHyDKggfrmrZ5QVWtZcw3mHZoT2EkvXXMMestvZtAYOrfKIvj/DCZGxUjXFVcN4wF5VP UJQ5uzWu0I1Y6ByKCESvh6CMF8IaurBvNCVFs8kWwVQnQWmxmApVM7zEjQsU+qyeftS9 nKiqoc6B56vkAAAIerg1XZ8aGeaxbLaZn/G6ZjgY778gZKR9sTcB5DIqQTlBRETuh2hW sdHA== X-Gm-Message-State: ABy/qLZn12UKHwJ/dlX2mWiupOpAEXiV80kb65v0ExqT1NVoc4bXfqaz Fe9Y6W+UCdtOYunTXC58VgcMHkISGEXdKbkBN8E= X-Google-Smtp-Source: APBJJlHqPYmQT0owseusIcsbSt2onEJjvTiOujWi/StbjLxQMUC8//o0xBUMCQiMDeafM1IbYDMDDQ== X-Received: by 2002:a05:6871:20f:b0:1b0:5fc0:e2b5 with SMTP id t15-20020a056871020f00b001b05fc0e2b5mr3013677oad.53.1689271528800; Thu, 13 Jul 2023 11:05:28 -0700 (PDT) Received: from localhost.localdomain ([2804:7f1:e2c1:1622:34af:d3bb:8e9a:95c5]) by smtp.gmail.com with ESMTPSA id t65-20020a4a5444000000b005660b585a00sm3175299ooa.22.2023.07.13.11.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:05:28 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v5 1/5] net: sched: cls_matchall: Undo tcf_bind_filter in case of failure after mall_set_parms Date: Thu, 13 Jul 2023 15:05:10 -0300 Message-Id: <20230713180514.592812-2-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713180514.592812-1-victor@mojatatu.com> References: <20230713180514.592812-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In case an error occurred after mall_set_parms executed successfully, we must undo the tcf_bind_filter call it issues. Fix that by calling tcf_unbind_filter in err_replace_hw_filter label. Fixes: ec2507d2a306 ("net/sched: cls_matchall: Fix error path") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_matchall.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c index fa3bbd187eb9..c4ed11df6254 100644 --- a/net/sched/cls_matchall.c +++ b/net/sched/cls_matchall.c @@ -159,26 +159,6 @@ static const struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = { [TCA_MATCHALL_FLAGS] = { .type = NLA_U32 }, }; -static int mall_set_parms(struct net *net, struct tcf_proto *tp, - struct cls_mall_head *head, - unsigned long base, struct nlattr **tb, - struct nlattr *est, u32 flags, u32 fl_flags, - struct netlink_ext_ack *extack) -{ - int err; - - err = tcf_exts_validate_ex(net, tp, tb, est, &head->exts, flags, - fl_flags, extack); - if (err < 0) - return err; - - if (tb[TCA_MATCHALL_CLASSID]) { - head->res.classid = nla_get_u32(tb[TCA_MATCHALL_CLASSID]); - tcf_bind_filter(tp, &head->res, base); - } - return 0; -} - static int mall_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, @@ -187,6 +167,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, { struct cls_mall_head *head = rtnl_dereference(tp->root); struct nlattr *tb[TCA_MATCHALL_MAX + 1]; + bool bound_to_filter = false; struct cls_mall_head *new; u32 userflags = 0; int err; @@ -226,11 +207,17 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, goto err_alloc_percpu; } - err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], - flags, new->flags, extack); - if (err) + err = tcf_exts_validate_ex(net, tp, tb, tca[TCA_RATE], + &new->exts, flags, new->flags, extack); + if (err < 0) goto err_set_parms; + if (tb[TCA_MATCHALL_CLASSID]) { + new->res.classid = nla_get_u32(tb[TCA_MATCHALL_CLASSID]); + tcf_bind_filter(tp, &new->res, base); + bound_to_filter = true; + } + if (!tc_skip_hw(new->flags)) { err = mall_replace_hw_filter(tp, new, (unsigned long)new, extack); @@ -246,6 +233,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, return 0; err_replace_hw_filter: + if (bound_to_filter) + tcf_unbind_filter(tp, &new->res); err_set_parms: free_percpu(new->pf); err_alloc_percpu: From patchwork Thu Jul 13 18:05:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13312564 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3468E1F922 for ; Thu, 13 Jul 2023 18:05:34 +0000 (UTC) Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F2C3271F for ; Thu, 13 Jul 2023 11:05:33 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-560b56b638eso618331eaf.0 for ; Thu, 13 Jul 2023 11:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1689271532; x=1691863532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nWAL230OToaDGGCE5V6CVwFPYGqlRrkHrId/ceZWwhk=; b=Iyhh74xlMR9YjZRx/eOZ9ruTbzRet0Z5nT4dsn0xlLx+IJnTA5vVbEbOJEN8Suxbtk vsD/hW8XtGPyJh3jwlHD7anxSjfTI6rnwEfVhZFGzOkAieaf2y6bEQmGx0U/4W/dJmdH tEAMl8Fz1H1oZmD8U7lOM46BtiStXtSQ11+VW0KmgxUcysmWeLwVuqtI0ysfkHrO1TTp w6KypLwHaaSqumSUeYvs4h+STSJEWMiPh3tXBZno6l59CFKvif1J0xh98U7ZpFukqxQx bjz/1+U23jOgW4RCqZQ7S2J9QvITO0qjXgflS+7pQ6BbfFFzbk7DapEewoZuhAkEnxPg rHYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689271532; x=1691863532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nWAL230OToaDGGCE5V6CVwFPYGqlRrkHrId/ceZWwhk=; b=kFGCrv/VpChbxg63N4wnVHSdPxeKyWQ3CQnnXRIhAjYa0yednMvlc1Pf1Wux9I4Xhx f4eAyzFPIld7VgqnfeLnkBlosFdFUfg7VjVjGJXWlPtoaiFmsnMbFLF12w3s8xATT//l jn0kt4llWOdnyMTV7Oze/h/x1zib+AqS1sxSQpWWHwrgYDWHRVF2PpNAvlerGVDCjhvO 7ZubaApW61eajFLrwViPQ8VtT8DMcPv2DDvggm8buYhgPvAISd1Oy62BeDva3k9UZICI zbiU1DL4+Bd9hFzGTu9nhy04nY+ibwwOZNaPs7/QhSoGAk4/JvsCCWVOouBXG31d5uBI AnXg== X-Gm-Message-State: ABy/qLbkOHwzg8KcLf5CkTECi48LT5Z6oNsDnvP6XH4S4sHwWY2Lsv8u kY2ervEN/UvBzc1XvAvgT3zEDJSBEiw3qJnhQiA= X-Google-Smtp-Source: APBJJlGLcNHUF3BJgfBVPA4H8IhpAfWtcl3sxyd/TnSr/rQ4LmoWR7rNmNTEwQNlgHmQ1Z0yY/eAaQ== X-Received: by 2002:a4a:e2ce:0:b0:560:bc01:24e2 with SMTP id l14-20020a4ae2ce000000b00560bc0124e2mr338195oot.4.1689271532245; Thu, 13 Jul 2023 11:05:32 -0700 (PDT) Received: from localhost.localdomain ([2804:7f1:e2c1:1622:34af:d3bb:8e9a:95c5]) by smtp.gmail.com with ESMTPSA id t65-20020a4a5444000000b005660b585a00sm3175299ooa.22.2023.07.13.11.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:05:31 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v5 2/5] net: sched: cls_u32: Undo tcf_bind_filter if u32_replace_hw_knode Date: Thu, 13 Jul 2023 15:05:11 -0300 Message-Id: <20230713180514.592812-3-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713180514.592812-1-victor@mojatatu.com> References: <20230713180514.592812-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org When u32_replace_hw_knode fails, we need to undo the tcf_bind_filter operation done at u32_set_parms. Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_u32.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index d15d50de7980..ed358466d042 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -712,8 +712,23 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { [TCA_U32_FLAGS] = { .type = NLA_U32 }, }; +static void u32_unbind_filter(struct tcf_proto *tp, struct tc_u_knode *n, + struct nlattr **tb) +{ + if (tb[TCA_U32_CLASSID]) + tcf_unbind_filter(tp, &n->res); +} + +static void u32_bind_filter(struct tcf_proto *tp, struct tc_u_knode *n, + unsigned long base, struct nlattr **tb) +{ + if (tb[TCA_U32_CLASSID]) { + n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); + tcf_bind_filter(tp, &n->res, base); + } +} + static int u32_set_parms(struct net *net, struct tcf_proto *tp, - unsigned long base, struct tc_u_knode *n, struct nlattr **tb, struct nlattr *est, u32 flags, u32 fl_flags, struct netlink_ext_ack *extack) @@ -760,10 +775,6 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, if (ht_old) ht_old->refcnt--; } - if (tb[TCA_U32_CLASSID]) { - n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); - tcf_bind_filter(tp, &n->res, base); - } if (ifindex >= 0) n->ifindex = ifindex; @@ -903,17 +914,20 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (!new) return -ENOMEM; - err = u32_set_parms(net, tp, base, new, tb, - tca[TCA_RATE], flags, new->flags, - extack); + err = u32_set_parms(net, tp, new, tb, tca[TCA_RATE], + flags, new->flags, extack); if (err) { __u32_destroy_key(new); return err; } + u32_bind_filter(tp, new, base, tb); + err = u32_replace_hw_knode(tp, new, flags, extack); if (err) { + u32_unbind_filter(tp, new, tb); + __u32_destroy_key(new); return err; } @@ -1074,15 +1088,18 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, } #endif - err = u32_set_parms(net, tp, base, n, tb, tca[TCA_RATE], + err = u32_set_parms(net, tp, n, tb, tca[TCA_RATE], flags, n->flags, extack); + + u32_bind_filter(tp, n, base, tb); + if (err == 0) { struct tc_u_knode __rcu **ins; struct tc_u_knode *pins; err = u32_replace_hw_knode(tp, n, flags, extack); if (err) - goto errhw; + goto errunbind; if (!tc_in_hw(n->flags)) n->flags |= TCA_CLS_FLAGS_NOT_IN_HW; @@ -1100,7 +1117,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, return 0; } -errhw: +errunbind: + u32_unbind_filter(tp, n, tb); + #ifdef CONFIG_CLS_U32_MARK free_percpu(n->pcpu_success); #endif From patchwork Thu Jul 13 18:05:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13312565 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC09F200B3 for ; Thu, 13 Jul 2023 18:05:37 +0000 (UTC) Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 676C0271F for ; Thu, 13 Jul 2023 11:05:36 -0700 (PDT) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-55e1ae72dceso736011eaf.3 for ; Thu, 13 Jul 2023 11:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1689271535; x=1691863535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OfaOeLsHcWm3y96PN9hXO8vYNt4DMjxwC7HGrF/Wk1k=; b=EWRp2gMhxH/PWxdwVAdB/hKa2K54IaT1apyX3lekEmTxlZgK0CeI4Da4vu/+KxJsx7 YrruB238xt0/F5KZCYmzquszy4fW6/xTK72EGv/o0qAWlRi7I6RAsCK91xnhLolIsmCf jeFQTu/8ZXK1475ICectKjJ0RFxNI4VJJqtsGK7ZtoYOe309eGd43hJSZ8RTZml2jIAJ Hv3I30mAAyrGV+8B/972AH/v8y6O6nIGehlVGtXvGbX5AMHbDH9RcRX7R2LXtKH3/p+/ VMART1msJKQzDvWp4ubUIaSgdZKly9lix4dlvlJmA47G+va+iB82ZDhyb65cijpYbsG1 T0Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689271535; x=1691863535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OfaOeLsHcWm3y96PN9hXO8vYNt4DMjxwC7HGrF/Wk1k=; b=SoIAXm6IJ8duoQqO9qEeKUW5ts8SyQ/g77a5Qxj9jecjIqZgekkB1xZf0VGq+oUiHO A388AOo+t4Sh9Bd9rKSDjOTQH1WeQBSvC+04TGWU5puXElMon3gS1hU4U7dbN61L2faI D4pEG0o7NO4VulheZ6fEqhB7i+EEur2WfhYYMdhxDcxCGVcsCa2E42XWL+kyNuCmIBYM zKxcYM/qHqVlnEibjPQDQWYlJOcisGWHanAzRNK0yq/+QF8yhQW6iV/xpbZfEHKANm0r RWgiJcFu6ZgpHF30xU4o7pk3LD2htaReySBFWnNM94mnx13kL3aMgtdPJ5mW/vuGaow6 Jmgg== X-Gm-Message-State: ABy/qLZa/dc7dCmofnZz1PUGtnKiu0QIwDasAaCSB4zT/p4i2FETZ7Zu mQT+kY6UAV3/Cr2N5VxtR7Z6eGy4ssq8u5iUojw= X-Google-Smtp-Source: APBJJlGPoWiuO3hRHsG9TCxkDD/IPFvC0+EHJ9dcpVOznssv59V4HfAyT/aA5hGGTdYCb440u3OoOA== X-Received: by 2002:a4a:840c:0:b0:566:fafc:ce47 with SMTP id l12-20020a4a840c000000b00566fafcce47mr1967106oog.8.1689271535556; Thu, 13 Jul 2023 11:05:35 -0700 (PDT) Received: from localhost.localdomain ([2804:7f1:e2c1:1622:34af:d3bb:8e9a:95c5]) by smtp.gmail.com with ESMTPSA id t65-20020a4a5444000000b005660b585a00sm3175299ooa.22.2023.07.13.11.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:05:35 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v5 3/5] net: sched: cls_u32: Undo refcount decrement in case update failed Date: Thu, 13 Jul 2023 15:05:12 -0300 Message-Id: <20230713180514.592812-4-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713180514.592812-1-victor@mojatatu.com> References: <20230713180514.592812-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In the case of an update, when TCA_U32_LINK is set, u32_set_parms will decrement the refcount of the ht_down (struct tc_u_hnode) pointer present in the older u32 filter which we are replacing. However, if u32_replace_hw_knode errors out, the update command fails and that ht_down pointer continues decremented. To fix that, when u32_replace_hw_knode fails, check if ht_down's refcount was decremented and undo the decrement. Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_u32.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index ed358466d042..5abf31e432ca 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -928,6 +928,13 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (err) { u32_unbind_filter(tp, new, tb); + if (tb[TCA_U32_LINK]) { + struct tc_u_hnode *ht_old; + + ht_old = rtnl_dereference(n->ht_down); + if (ht_old) + ht_old->refcnt++; + } __u32_destroy_key(new); return err; } From patchwork Thu Jul 13 18:05:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13312566 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83483200B3 for ; Thu, 13 Jul 2023 18:05:41 +0000 (UTC) Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD3F02728 for ; Thu, 13 Jul 2023 11:05:39 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-565f8e359b8so731110eaf.2 for ; Thu, 13 Jul 2023 11:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1689271539; x=1691863539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RlIZocve4fJZ8/+M2tU4BiuJM8y43OIzDZI1VHdaM28=; b=Kv816XtlYe+q+gKcX+1svviN42DSmR+VZPadnxkzYUhjHcw5JAGEojL/zd+e4y4qS5 Zv26ztXDuiwt/pEC5NY8+ZzXrN3dEtGt2+Sj6H46PJEKEySPjhaeKJ5JtoyB+k5CHq8p vAtqpBQzaaT1QB5KeuhGPBlBej6EHe9bWXD6kyJUz65s08FCCwgy2tXBb9d1acF6IdjI d2Azz48X8C/RQSVG98di5e3h0FcF1hG33Ox5kRkLqCihJ32ZmCgOXFicI3+C3rEIdAYD kr+K++Tax930Xsp5saYzSCe9pEZ+vwUeurlAF2vOvBZ0R2nrTvKRr3NYQNU93C24AaE3 lA+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689271539; x=1691863539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RlIZocve4fJZ8/+M2tU4BiuJM8y43OIzDZI1VHdaM28=; b=FrfZS82E3zR/oJQ3+O8/wgHtcjhQgo5l61Io//UiD3sl/euslpqWsrIFS70yYZ6vuW onrQdcJf2v/rcP1JycbH8DoQy92S83cojFUtfEe+B+0cDOPzkdWhivgoRRwC40CTAr2P mdMDTAFvoB6mTj5g1whsRLDNSeQGyYXQ36A6IXflKsArXAYDjHH+8U8PYfYtv3MJNryt ortKcOVg9NVHjtFvwLh865SYoUs/bszJTGmNQwZSHxvOOv22PoQ+uzgjE4djqfhkDzhh 8+VuaY80KZhP1JHm7YbrSfD6SATw813H+/qCrCYgjHsoOubhKU6N7r3gPX1YET94xv0h 2X+w== X-Gm-Message-State: ABy/qLZVA50nSrOHk7Aqx5h9NAcf4/4jNriReqaDGHlRuFJgvuY9t9sH 42aJccxog2OIGz7xKuK4qmYo5+/U65ShY7A29oE= X-Google-Smtp-Source: APBJJlFnnxS4cAfRPkQgiRmJbUX29jt7mrI9P4gEpQdjj0EQvhcwl7A+16wS5N6HozJBIbE5VgyVbA== X-Received: by 2002:a4a:2517:0:b0:566:fd47:eb5 with SMTP id g23-20020a4a2517000000b00566fd470eb5mr1992784ooa.0.1689271538869; Thu, 13 Jul 2023 11:05:38 -0700 (PDT) Received: from localhost.localdomain ([2804:7f1:e2c1:1622:34af:d3bb:8e9a:95c5]) by smtp.gmail.com with ESMTPSA id t65-20020a4a5444000000b005660b585a00sm3175299ooa.22.2023.07.13.11.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:05:38 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v5 4/5] net: sched: cls_bpf: Undo tcf_bind_filter in case of an error Date: Thu, 13 Jul 2023 15:05:13 -0300 Message-Id: <20230713180514.592812-5-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713180514.592812-1-victor@mojatatu.com> References: <20230713180514.592812-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org If cls_bpf_offload errors out, we must also undo tcf_bind_filter that was done before the error. Fix that by calling tcf_unbind_filter in errout_parms. Fixes: eadb41489fd2 ("net: cls_bpf: add support for marking filters as hardware-only") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_bpf.c | 99 +++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 466c26df853a..382c7a71f81f 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -406,56 +406,6 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, return 0; } -static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, - struct cls_bpf_prog *prog, unsigned long base, - struct nlattr **tb, struct nlattr *est, u32 flags, - struct netlink_ext_ack *extack) -{ - bool is_bpf, is_ebpf, have_exts = false; - u32 gen_flags = 0; - int ret; - - is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS]; - is_ebpf = tb[TCA_BPF_FD]; - if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf)) - return -EINVAL; - - ret = tcf_exts_validate(net, tp, tb, est, &prog->exts, flags, - extack); - if (ret < 0) - return ret; - - if (tb[TCA_BPF_FLAGS]) { - u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]); - - if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT) - return -EINVAL; - - have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT; - } - if (tb[TCA_BPF_FLAGS_GEN]) { - gen_flags = nla_get_u32(tb[TCA_BPF_FLAGS_GEN]); - if (gen_flags & ~CLS_BPF_SUPPORTED_GEN_FLAGS || - !tc_flags_valid(gen_flags)) - return -EINVAL; - } - - prog->exts_integrated = have_exts; - prog->gen_flags = gen_flags; - - ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) : - cls_bpf_prog_from_efd(tb, prog, gen_flags, tp); - if (ret < 0) - return ret; - - if (tb[TCA_BPF_CLASSID]) { - prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]); - tcf_bind_filter(tp, &prog->res, base); - } - - return 0; -} - static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, struct tcf_proto *tp, unsigned long base, u32 handle, struct nlattr **tca, @@ -463,9 +413,12 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, struct netlink_ext_ack *extack) { struct cls_bpf_head *head = rtnl_dereference(tp->root); + bool is_bpf, is_ebpf, have_exts = false; struct cls_bpf_prog *oldprog = *arg; struct nlattr *tb[TCA_BPF_MAX + 1]; + bool bound_to_filter = false; struct cls_bpf_prog *prog; + u32 gen_flags = 0; int ret; if (tca[TCA_OPTIONS] == NULL) @@ -504,11 +457,51 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, goto errout; prog->handle = handle; - ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], flags, - extack); + is_bpf = tb[TCA_BPF_OPS_LEN] && tb[TCA_BPF_OPS]; + is_ebpf = tb[TCA_BPF_FD]; + if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf)) { + ret = -EINVAL; + goto errout_idr; + } + + ret = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &prog->exts, + flags, extack); + if (ret < 0) + goto errout_idr; + + if (tb[TCA_BPF_FLAGS]) { + u32 bpf_flags = nla_get_u32(tb[TCA_BPF_FLAGS]); + + if (bpf_flags & ~TCA_BPF_FLAG_ACT_DIRECT) { + ret = -EINVAL; + goto errout_idr; + } + + have_exts = bpf_flags & TCA_BPF_FLAG_ACT_DIRECT; + } + if (tb[TCA_BPF_FLAGS_GEN]) { + gen_flags = nla_get_u32(tb[TCA_BPF_FLAGS_GEN]); + if (gen_flags & ~CLS_BPF_SUPPORTED_GEN_FLAGS || + !tc_flags_valid(gen_flags)) { + ret = -EINVAL; + goto errout_idr; + } + } + + prog->exts_integrated = have_exts; + prog->gen_flags = gen_flags; + + ret = is_bpf ? cls_bpf_prog_from_ops(tb, prog) : + cls_bpf_prog_from_efd(tb, prog, gen_flags, tp); if (ret < 0) goto errout_idr; + if (tb[TCA_BPF_CLASSID]) { + prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]); + tcf_bind_filter(tp, &prog->res, base); + bound_to_filter = true; + } + ret = cls_bpf_offload(tp, prog, oldprog, extack); if (ret) goto errout_parms; @@ -530,6 +523,8 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, return 0; errout_parms: + if (bound_to_filter) + tcf_unbind_filter(tp, &prog->res); cls_bpf_free_parms(prog); errout_idr: if (!oldprog) From patchwork Thu Jul 13 18:05:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13312567 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2A981F927 for ; Thu, 13 Jul 2023 18:05:45 +0000 (UTC) Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 476772738 for ; Thu, 13 Jul 2023 11:05:43 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1b3c503af99so830888fac.0 for ; Thu, 13 Jul 2023 11:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1689271542; x=1691863542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oI/H8ZTBT7Wxmh0S82hyx/kEJhcXfFsXkwohK51Y7pI=; b=V/Vv5WwH/jcWnr0jEAWDbK2P41Ki7yJbKFsQzFKhdqtjqYGpLOYDxO8lSP6/1XtE7B qxUhLwKAj8S03ArG9QodqAf25BJDOB/WSTdHWRkVM70SM0a0a4lPEcyT+4oKIxJ+80zP EWJJxCbbbRSjEpJvLb121sclvUvkptk+Jjqa+xJuJYWMkWV2HH/W3Ot6wPwJ3r73QFbl UmwUfvhjbetZA9Zf/d2tZBlxCn5IBQPoSvhPyFiV9EZbdHKz1ckgFzIn77vy9Z+Nrp3Y ky8lrh5Zw+HW2Mf2jARQXkCoEeS0CN7y21MZpbEav3iPFRgzTl402bvfw3VBIfUoKaP3 GcgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689271542; x=1691863542; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oI/H8ZTBT7Wxmh0S82hyx/kEJhcXfFsXkwohK51Y7pI=; b=F/IzAHOdLVX3U07zh3t6eqZ+UhD9mZJVdwCSW54UzxKYgWA3SryQwVozFRYZ+I/IUn 7yKHIXGS5M2gruSdPz7EihwsZUaIeDU636gpg8ZcjnWJSPs07YZ6wYw1WmyYDy6lDtoY AAV8R+qjz6sE2745G3V+GvGxWa4nzY9Q3Dipq3Ls0Oqz7kZVGAR/wE/7/KIi0GsQGpvL hV0uOuJXr77nWy2iGKq0W1nEFFK4SA9gpibaU1pKEg+21ARyv9KB/HkkitWingiqx0j7 tiQpoCzrrBy8fzILSK7FE5Zvpnc8wqZZNdt9txSO1svetMPB5wenAGBeZait3TPTprn/ rl8Q== X-Gm-Message-State: ABy/qLbiS/oaMPE8pfLRKEAfIj57nfgoCeAUPWAUePr3s1DslqXiSSC9 Q4UOw+xblLjF+b37KTFtCUieUVs48QeJH3mvWco= X-Google-Smtp-Source: APBJJlFKPiENOUHEnrOs+fiaIL5JvGkgE4jtncN89IaqPLKbsI7FJpn1jjyROp+qTdX6pwz+6hqyGQ== X-Received: by 2002:a05:6870:d62a:b0:1a6:b183:b0ab with SMTP id a42-20020a056870d62a00b001a6b183b0abmr3003036oaq.40.1689271542348; Thu, 13 Jul 2023 11:05:42 -0700 (PDT) Received: from localhost.localdomain ([2804:7f1:e2c1:1622:34af:d3bb:8e9a:95c5]) by smtp.gmail.com with ESMTPSA id t65-20020a4a5444000000b005660b585a00sm3175299ooa.22.2023.07.13.11.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:05:41 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v5 5/5] net: sched: cls_flower: Undo tcf_bind_filter in case of an error Date: Thu, 13 Jul 2023 15:05:14 -0300 Message-Id: <20230713180514.592812-6-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713180514.592812-1-victor@mojatatu.com> References: <20230713180514.592812-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org If TCA_FLOWER_CLASSID is specified in the netlink message, the code will call tcf_bind_filter. However, if any error occurs after that, the code should undo this by calling tcf_unbind_filter. Fixes: 77b9900ef53a ("tc: introduce Flower classifier") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/cls_flower.c | 99 ++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 52 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index f2b0bc4142fe..8da9d039d964 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -2173,53 +2173,6 @@ static bool fl_needs_tc_skb_ext(const struct fl_flow_key *mask) return mask->meta.l2_miss; } -static int fl_set_parms(struct net *net, struct tcf_proto *tp, - struct cls_fl_filter *f, struct fl_flow_mask *mask, - unsigned long base, struct nlattr **tb, - struct nlattr *est, - struct fl_flow_tmplt *tmplt, - u32 flags, u32 fl_flags, - struct netlink_ext_ack *extack) -{ - int err; - - err = tcf_exts_validate_ex(net, tp, tb, est, &f->exts, flags, - fl_flags, extack); - if (err < 0) - return err; - - if (tb[TCA_FLOWER_CLASSID]) { - f->res.classid = nla_get_u32(tb[TCA_FLOWER_CLASSID]); - if (flags & TCA_ACT_FLAGS_NO_RTNL) - rtnl_lock(); - tcf_bind_filter(tp, &f->res, base); - if (flags & TCA_ACT_FLAGS_NO_RTNL) - rtnl_unlock(); - } - - err = fl_set_key(net, tb, &f->key, &mask->key, extack); - if (err) - return err; - - fl_mask_update_range(mask); - fl_set_masked_key(&f->mkey, &f->key, mask); - - if (!fl_mask_fits_tmplt(tmplt, mask)) { - NL_SET_ERR_MSG_MOD(extack, "Mask does not fit the template"); - return -EINVAL; - } - - /* Enable tc skb extension if filter matches on data extracted from - * this extension. - */ - if (fl_needs_tc_skb_ext(&mask->key)) { - f->needs_tc_skb_ext = 1; - tc_skb_ext_tc_enable(); - } - - return 0; -} - static int fl_ht_insert_unique(struct cls_fl_filter *fnew, struct cls_fl_filter *fold, bool *in_ht) @@ -2251,6 +2204,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, struct cls_fl_head *head = fl_head_dereference(tp); bool rtnl_held = !(flags & TCA_ACT_FLAGS_NO_RTNL); struct cls_fl_filter *fold = *arg; + bool bound_to_filter = false; struct cls_fl_filter *fnew; struct fl_flow_mask *mask; struct nlattr **tb; @@ -2335,15 +2289,46 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, if (err < 0) goto errout_idr; - err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], - tp->chain->tmplt_priv, flags, fnew->flags, - extack); - if (err) + err = tcf_exts_validate_ex(net, tp, tb, tca[TCA_RATE], + &fnew->exts, flags, fnew->flags, + extack); + if (err < 0) goto errout_idr; + if (tb[TCA_FLOWER_CLASSID]) { + fnew->res.classid = nla_get_u32(tb[TCA_FLOWER_CLASSID]); + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_lock(); + tcf_bind_filter(tp, &fnew->res, base); + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_unlock(); + bound_to_filter = true; + } + + err = fl_set_key(net, tb, &fnew->key, &mask->key, extack); + if (err) + goto unbind_filter; + + fl_mask_update_range(mask); + fl_set_masked_key(&fnew->mkey, &fnew->key, mask); + + if (!fl_mask_fits_tmplt(tp->chain->tmplt_priv, mask)) { + NL_SET_ERR_MSG_MOD(extack, "Mask does not fit the template"); + err = -EINVAL; + goto unbind_filter; + } + + /* Enable tc skb extension if filter matches on data extracted from + * this extension. + */ + if (fl_needs_tc_skb_ext(&mask->key)) { + fnew->needs_tc_skb_ext = 1; + tc_skb_ext_tc_enable(); + } + err = fl_check_assign_mask(head, fnew, fold, mask); if (err) - goto errout_idr; + goto unbind_filter; err = fl_ht_insert_unique(fnew, fold, &in_ht); if (err) @@ -2434,6 +2419,16 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, fnew->mask->filter_ht_params); errout_mask: fl_mask_put(head, fnew->mask); + +unbind_filter: + if (bound_to_filter) { + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_lock(); + tcf_unbind_filter(tp, &fnew->res); + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_unlock(); + } + errout_idr: if (!fold) idr_remove(&head->handle_idr, fnew->handle);