From patchwork Fri Mar 17 19:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13179405 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 75EE3C76195 for ; Fri, 17 Mar 2023 20:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbjCQUGJ (ORCPT ); Fri, 17 Mar 2023 16:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229985AbjCQUGG (ORCPT ); Fri, 17 Mar 2023 16:06:06 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44664391F for ; Fri, 17 Mar 2023 13:06:03 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id f17-20020a9d7b51000000b00697349ab7e7so3486431oto.9 for ; Fri, 17 Mar 2023 13:06:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1679083562; 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=g/bAeGvHYteqcW3oSY0dYVvGX85jsfFt01QzXBIzUag=; b=S+ylxZskVJXI5ljAwy9tfrqJU+wh9jBkuQ2HsoA51rpK2M7NQsy5Mu3EEWVdn4OsH1 7gjskw2GAlv0TZyURYxrMfMIzv9RMVcM9YEwlDMebNB1ZNsFAZJtgjrj86A/ZkcszYdB H3NxJXkbYxcv29Bs/2TeapWZk3Tlrshzb8/1IhJwqVb+d19/norIoEqD8E7wfGQf826S 1QWmRPSXlxiBGtaDePrOHO+N+7QGs5DZGAtlj6g3O7dj1CQD4afQp1BDzddmF9YiEM2t 5YBCovZ1UJm8BLx1YfdL86zJMmioekliIN/ZegpHQ9LCjowhaXWf7eeK/szAug/mCW+Q EmJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679083562; 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=g/bAeGvHYteqcW3oSY0dYVvGX85jsfFt01QzXBIzUag=; b=mW3KuunmpOPDXfyruCqqxUU2Xo2SeHtRXcN+0WLzczmHiXZjz5GloX9z1f34GeXwr2 IMEq+JUKROdPVM+wqioBiJ/7e3tad1qQJC6Iyo6bCUxNmaFWH5Aq/kgUv6LhTN1R77vX s0EqgAkkWzKMdDqhehjaM9AfTbGC3JY3Obi4AitOdGYEgI1jXlZ5yT/GHRemTbAvgX8/ M+UN8R2W4sU1ZpWRkVyn/987cRHfvNiV5TUxMR+VkJKGZ4UNsaaCP6TQ9PIQXyzlWfs2 FCVkCIQy7HrK8B+GshSocquI72VjoV1GwJ/ebAeVsAcZb6eeYhw/UO4D7Qxn8E4sBT3s Z8YA== X-Gm-Message-State: AO0yUKXcPsaLrjaw+KzqqOSUhhfZw5TpfkX9CQpnN8gxth9gRXywaeI1 Nnzc/Nz8nOxWFU7aCSPsaD1StKPs/MCwTIje4Tc= X-Google-Smtp-Source: AK7set9UwrRn7Z9gADtr0MzQer92+WiegOquKjuiWBnc8dz/ylK6RL5M9NoVB5TyXN+6c+32GyH6gg== X-Received: by 2002:a05:6830:99:b0:699:7244:a372 with SMTP id a25-20020a056830009900b006997244a372mr378012oto.28.1679083562671; Fri, 17 Mar 2023 13:06:02 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:10c1:4b9b:b369:bda2]) by smtp.gmail.com with ESMTPSA id z8-20020a056830128800b00698a88cfad1sm1304209otp.68.2023.03.17.13.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 13:06:02 -0700 (PDT) From: Pedro Tammela 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, simon.horman@corigine.com, Pedro Tammela Subject: [PATCH net-next v3 1/4] net/sched: act_pedit: use extack in 'ex' parsing errors Date: Fri, 17 Mar 2023 16:51:32 -0300 Message-Id: <20230317195135.1142050-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317195135.1142050-1-pctammela@mojatatu.com> References: <20230317195135.1142050-1-pctammela@mojatatu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We have extack available when parsing 'ex' keys, so pass it to tcf_pedit_keys_ex_parse and add more detailed error messages. While at it, remove redundant code from the 'err_out' label code path. Reviewed-by: Jamal Hadi Salim Signed-off-by: Pedro Tammela --- net/sched/act_pedit.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 4559a1507ea5..cd3cbe397e87 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -35,7 +35,7 @@ static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = { }; static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, - u8 n) + u8 n, struct netlink_ext_ack *extack) { struct tcf_pedit_key_ex *keys_ex; struct tcf_pedit_key_ex *k; @@ -56,25 +56,25 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1]; if (!n) { - err = -EINVAL; + NL_SET_ERR_MSG_MOD(extack, "Can't parse more extended keys than requested"); goto err_out; } + n--; if (nla_type(ka) != TCA_PEDIT_KEY_EX) { - err = -EINVAL; + NL_SET_ERR_MSG_MOD(extack, "Unknown attribute, expected extended key"); goto err_out; } - err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, - ka, pedit_key_ex_policy, - NULL); + err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, ka, + pedit_key_ex_policy, extack); if (err) goto err_out; if (!tb[TCA_PEDIT_KEY_EX_HTYPE] || !tb[TCA_PEDIT_KEY_EX_CMD]) { - err = -EINVAL; + NL_SET_ERR_MSG_MOD(extack, "Extended Pedit missing required attributes"); goto err_out; } @@ -83,7 +83,7 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, if (k->htype > TCA_PEDIT_HDR_TYPE_MAX || k->cmd > TCA_PEDIT_CMD_MAX) { - err = -EINVAL; + NL_SET_ERR_MSG_MOD(extack, "Extended Pedit key is malformed"); goto err_out; } @@ -91,7 +91,7 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, } if (n) { - err = -EINVAL; + NL_SET_ERR_MSG_MOD(extack, "Not enough extended keys to parse"); goto err_out; } @@ -222,7 +222,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, } nparms->tcfp_keys_ex = - tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys); + tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys, extack); if (IS_ERR(nparms->tcfp_keys_ex)) { ret = PTR_ERR(nparms->tcfp_keys_ex); goto out_free; From patchwork Fri Mar 17 19:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13179406 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 81113C6FD1D for ; Fri, 17 Mar 2023 20:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjCQUGL (ORCPT ); Fri, 17 Mar 2023 16:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjCQUGJ (ORCPT ); Fri, 17 Mar 2023 16:06:09 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EE044200 for ; Fri, 17 Mar 2023 13:06:06 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id v2-20020a056830090200b0069c6952f4d3so3484072ott.7 for ; Fri, 17 Mar 2023 13:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1679083565; 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=mEbNWEQ2Tzjo+v75NSlVPWQEh095dnAAZdqY3OtxuKI=; b=HfkclB5RVvS174IfroSPMpH4SAObSGDdNjQrTrAiHbLhcTPxKdZGzNHnDmIoo7vpAe UyuRwbRMLdQIw202Q4uwVDewY7iAkCrlHAzBsqwmaNh58oQ7LuStoqdjnM5lsOvVZtbk wA6mcx6EgVBsZO1hXxahPmRJXF27lj+9SciY7/3mZ2YAvPKW6236DV8GCn+Ugk7cohWb 2iC9Z4aZfQGjNYgWa8Nr1xUTNfJSz94OgH4D/94Er1CXxzwPiNAx0L04tuzBfCLvS+zF +TqOFNYaPMd2TIF3rYClZnN01GUvf+DQOX/EDtQxgQqUCo4ZpcKrsMZ1AvWa+3JUJuTS 00mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679083565; 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=mEbNWEQ2Tzjo+v75NSlVPWQEh095dnAAZdqY3OtxuKI=; b=0L8rVpqUT7Rp0qnSCPK2GdQt+d7yyWxdbsHEhj8ivXhfDxk9ntzILdNhkmlyokFevw omiN/9uK0gcOFBH8FGN11QFGCWLLT0ZDqXQs9IzP8jof8NKc6lAP/w2hP9kpKqW7nOaE SP0rlR9QbhQL35BL7xua8P2DdpN0BLmrhAaSvY3F6CirQLlvXS+hN95cP5ZKk7/EaGLV mk9U2fm65KGFNKqHkXvpL4uXtt3uCOlt1bPdd6df9JWyfw55k5z0xUx1yIM65SJJhtD4 OPdE4bxkwujco88hHv5ynXyPMyLKE8lBMbKrkMbaBFDLfJuoK9ZC6Zteq7TULl3XESlR I9qg== X-Gm-Message-State: AO0yUKWLd+mrsaWEwuD2FS9kubMvxzB/DY9kKMLJUWHdHbbigWEMCwrc yfUpqKPAbenHJgwSCbut6pAIcF9EhgeTwzonvYE= X-Google-Smtp-Source: AK7set/iynELw4sRhOrI/YpXzihg2YXYszD0KaEY5GfNNd5uM51tReFuUItjHzhoroZw7XfLTFyb/Q== X-Received: by 2002:a05:6830:104e:b0:694:7da5:d04e with SMTP id b14-20020a056830104e00b006947da5d04emr403876otp.19.1679083565598; Fri, 17 Mar 2023 13:06:05 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:10c1:4b9b:b369:bda2]) by smtp.gmail.com with ESMTPSA id z8-20020a056830128800b00698a88cfad1sm1304209otp.68.2023.03.17.13.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 13:06:05 -0700 (PDT) From: Pedro Tammela 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, simon.horman@corigine.com, Pedro Tammela Subject: [PATCH net-next v3 2/4] net/sched: act_pedit: check static offsets a priori Date: Fri, 17 Mar 2023 16:51:33 -0300 Message-Id: <20230317195135.1142050-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317195135.1142050-1-pctammela@mojatatu.com> References: <20230317195135.1142050-1-pctammela@mojatatu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Static key offsets should always be on 32 bit boundaries. Validate them on create/update time for static offsets and move the datapath validation for runtime offsets only. iproute2 already errors out if a given offset and data size cannot be packed to a 32 bit boundary. This change will make sure users which create/update pedit instances directly via netlink also error out, instead of finding out when packets are traversing. Reviewed-by: Jamal Hadi Salim Reviewed-by: Simon Horman Signed-off-by: Pedro Tammela --- net/sched/act_pedit.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index cd3cbe397e87..d780acb44d06 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -249,6 +249,12 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, for (i = 0; i < nparms->tcfp_nkeys; ++i) { u32 cur = nparms->tcfp_keys[i].off; + if (cur % 4) { + NL_SET_ERR_MSG_MOD(extack, "Pedit offsets must be on 32bit boundaries"); + ret = -EINVAL; + goto put_chain; + } + /* sanitize the shift value for any later use */ nparms->tcfp_keys[i].shift = min_t(size_t, BITS_PER_TYPE(int) - 1, @@ -407,12 +413,12 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, sizeof(_d), &_d); if (!d) goto bad; - offset += (*d & tkey->offmask) >> tkey->shift; - } - if (offset % 4) { - pr_info("tc action pedit offset must be on 32 bit boundaries\n"); - goto bad; + offset += (*d & tkey->offmask) >> tkey->shift; + if (offset % 4) { + pr_info("tc action pedit offset must be on 32 bit boundaries\n"); + goto bad; + } } if (!offset_valid(skb, hoffset + offset)) { From patchwork Fri Mar 17 19:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13179407 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 227D6C74A5B for ; Fri, 17 Mar 2023 20:06:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbjCQUGX (ORCPT ); Fri, 17 Mar 2023 16:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbjCQUGW (ORCPT ); Fri, 17 Mar 2023 16:06:22 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB847CA780 for ; Fri, 17 Mar 2023 13:06:09 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-177ca271cb8so6929755fac.2 for ; Fri, 17 Mar 2023 13:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1679083569; 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=U3ulD6Qys0ZfunJDBappONbiScJ689GXwqPtC7oOTRc=; b=0gkwx4GvavO5rEpq9NsZkGwn6MxFHEjvwLdfdZFIrnUyb9hPdazXHHDM1bU2mPg61z upYYxmseot5gA3jFWpyAI97qvwsQiHxJIup5C3iYUVuHBLw+yss4wNUwCc5zFGbS0wbY I+NcugXpWsqvewz8J7UxJW0VKrjpPz0XKerUav2gk0EaxtY7uR3gbr4GsI1mnPu3K0Wm ZxoGn3OuoFkhZemOf2+f20TwXEeXW9pTBxQqfD8t8bg2SOCRaoSCuAogg/EtzI5tqod4 tPiN/qU8qDmT7KPvCWYKRV/9qMZ0CMT9b11bCrHcmhkeH4bjuJgTjli/ZeJbT1VsB86j G4yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679083569; 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=U3ulD6Qys0ZfunJDBappONbiScJ689GXwqPtC7oOTRc=; b=X5Z2B52vKB7bopl7Q86Ra5qtZGV/07EgsZtfQRG5DJPj01tmTsTM4Vbz85QVkmcsWY lqcVhaGgjYbPgQHzPZSoExrhgas8P/dOHABM6uFgxO5Rwh7euQX7kLkJxcrnOqmugtB/ omY0Im/1uYeRV6NNFnbZ890aflRG3Y5HSPshPVjilKYEyvFprJ4vx56KQtfZv4LTySPN FbquA5E/6sG9bftaKu6iAH//wcZqa2q/Q1gQnvYqMCSJH1ZG67oJA/xh9jxbLRCT0Ei6 pNrBFSUr/lDCU2BYNoCMJTl08YoRdjs1kktKLnr6qQRz3HRaGXzo1a7rhHt2gQMMtv2e f6FA== X-Gm-Message-State: AO0yUKVERmLVx6CpAStEBJZKh6X8LPrk10JBX58Sg0mvcxlDCop5Vgbu f6FwQtYLEF68Wdw5w5DrvyK6xEH84wiMS0Raxmg= X-Google-Smtp-Source: AK7set+VsEF/qBn3vtipfPT3YILbISeYqX4+d1wmK3s8bkv4/gb1z2dOddHQPT6IUpnJpp5CRvBJug== X-Received: by 2002:a05:6871:92:b0:177:9753:f823 with SMTP id u18-20020a056871009200b001779753f823mr463731oaa.20.1679083568827; Fri, 17 Mar 2023 13:06:08 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:10c1:4b9b:b369:bda2]) by smtp.gmail.com with ESMTPSA id z8-20020a056830128800b00698a88cfad1sm1304209otp.68.2023.03.17.13.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 13:06:08 -0700 (PDT) From: Pedro Tammela 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, simon.horman@corigine.com, Pedro Tammela Subject: [PATCH net-next v3 3/4] net/sched: act_pedit: remove extra check for key type Date: Fri, 17 Mar 2023 16:51:34 -0300 Message-Id: <20230317195135.1142050-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317195135.1142050-1-pctammela@mojatatu.com> References: <20230317195135.1142050-1-pctammela@mojatatu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The netlink parsing already validates the key 'htype'. Remove the datapath check as it's redundant. Reviewed-by: Jamal Hadi Salim Reviewed-by: Simon Horman Signed-off-by: Pedro Tammela --- net/sched/act_pedit.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index d780acb44d06..73414cbb6215 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -319,37 +319,28 @@ static bool offset_valid(struct sk_buff *skb, int offset) return true; } -static int pedit_skb_hdr_offset(struct sk_buff *skb, - enum pedit_header_type htype, int *hoffset) +static void pedit_skb_hdr_offset(struct sk_buff *skb, + enum pedit_header_type htype, int *hoffset) { - int ret = -EINVAL; - + /* 'htype' is validated in the netlink parsing */ switch (htype) { case TCA_PEDIT_KEY_EX_HDR_TYPE_ETH: - if (skb_mac_header_was_set(skb)) { + if (skb_mac_header_was_set(skb)) *hoffset = skb_mac_offset(skb); - ret = 0; - } break; case TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK: case TCA_PEDIT_KEY_EX_HDR_TYPE_IP4: case TCA_PEDIT_KEY_EX_HDR_TYPE_IP6: *hoffset = skb_network_offset(skb); - ret = 0; break; case TCA_PEDIT_KEY_EX_HDR_TYPE_TCP: case TCA_PEDIT_KEY_EX_HDR_TYPE_UDP: - if (skb_transport_header_was_set(skb)) { + if (skb_transport_header_was_set(skb)) *hoffset = skb_transport_offset(skb); - ret = 0; - } break; default: - ret = -EINVAL; break; } - - return ret; } TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, @@ -382,10 +373,9 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, for (i = parms->tcfp_nkeys; i > 0; i--, tkey++) { int offset = tkey->off; + int hoffset = 0; u32 *ptr, hdata; - int hoffset; u32 val; - int rc; if (tkey_ex) { htype = tkey_ex->htype; @@ -394,12 +384,7 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, tkey_ex++; } - rc = pedit_skb_hdr_offset(skb, htype, &hoffset); - if (rc) { - pr_info("tc action pedit bad header type specified (0x%x)\n", - htype); - goto bad; - } + pedit_skb_hdr_offset(skb, htype, &hoffset); if (tkey->offmask) { u8 *d, _d; From patchwork Fri Mar 17 19:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13179408 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 7F3EEC74A5B for ; Fri, 17 Mar 2023 20:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbjCQUGd (ORCPT ); Fri, 17 Mar 2023 16:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbjCQUGc (ORCPT ); Fri, 17 Mar 2023 16:06:32 -0400 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 0E501DCA4F for ; Fri, 17 Mar 2023 13:06:12 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id a23-20020a4ad5d7000000b005250867d3d9so945612oot.10 for ; Fri, 17 Mar 2023 13:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1679083572; 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=kNIltoAtE8byOMyYGGGlKSXDXoyOLtzko+GuK2RWSh4=; b=S3Awux1L6NphsvbEUtuyHKL/zfxX+JiyEAeC3DJupcqN0sf6rg3C/fy9nP9bKiGHb1 ivjz5tkELvyVRn9N6UngECSDWOFTDVHkLXBnkbfwXwOHTz89p6kJcZY53hQW1XTxikEF 8iLwPwmBqVgaTGvMIoetvMtV1YH4HcPBmR4rJ+GOHawFzHxEwAm7TnVQMlvlPBv6Gnb+ KZ/Prrpd/BCwmhP4dO9QM1i0ZeEIBLe4aCMnvVCqs2GjPkPsuN5NdA0pnI+GclhHQSzD fUSTsUzf5tox2Bagk6rt4/yfh5r/KSmCQP0IqJduGUrUFJGhGzDU8r2omg9p++jYGx5g AwLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679083572; 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=kNIltoAtE8byOMyYGGGlKSXDXoyOLtzko+GuK2RWSh4=; b=BgT0KW+c+9gsyhp7sLkZKmsKMx7DDh00NRWde7o6nqmfNfXlHJqfIfrJbQLlOJHnTH B+AEEZtiE/9u+L9iAYZL2WLmS1EuWGBCb74S5XkUgzvZS6KS8qIYsW67CaCyOmwLH8+T isMRTkJ0Ir8dIjT/YysXU4B45EhiH/7uKWEQZnQEhmTE03njAAMHV1KfOmlUNOqikZHy CsYrv8PRxyXVXSbFFEbf+Vav0O+/mjZWaizWGfW42FkD5dWdmkWEo3WyNp6soFLf/Aqk Pe/NTwb3ev8zXSMKU2cwlzcUeUA3uGzpahZT8xQqFeAi8Ost7K83pw0aDJGkgxaxRQPa kkHg== X-Gm-Message-State: AO0yUKXqsr0E6Fth7wjdWAqtDQz11h2re/pT6Em59Fv+GtutIRYCZS8J LMkAjnhbeexNoztwvmhBdhu+icRw/r8v0kvh+eI= X-Google-Smtp-Source: AK7set9xphw25U5a4vI3nhu55ehWbc20Wv6hRO1kawSXQtI5YG0/RABnuJ0L4F8XfTekwb0cW86xmw== X-Received: by 2002:a4a:49cb:0:b0:538:242e:803a with SMTP id z194-20020a4a49cb000000b00538242e803amr571316ooa.0.1679083572169; Fri, 17 Mar 2023 13:06:12 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:10c1:4b9b:b369:bda2]) by smtp.gmail.com with ESMTPSA id z8-20020a056830128800b00698a88cfad1sm1304209otp.68.2023.03.17.13.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 13:06:11 -0700 (PDT) From: Pedro Tammela 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, simon.horman@corigine.com, Pedro Tammela Subject: [PATCH net-next v3 4/4] net/sched: act_pedit: rate limit datapath messages Date: Fri, 17 Mar 2023 16:51:35 -0300 Message-Id: <20230317195135.1142050-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317195135.1142050-1-pctammela@mojatatu.com> References: <20230317195135.1142050-1-pctammela@mojatatu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Unbounded info messages in the pedit datapath can flood the printk ring buffer quite easily depending on the action created. As these messages are informational, usually printing some, not all, is enough to bring attention to the real issue. Reviewed-by: Jamal Hadi Salim Reviewed-by: Simon Horman Signed-off-by: Pedro Tammela --- net/sched/act_pedit.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 73414cbb6215..197ddc22d3e5 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -390,8 +390,8 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, u8 *d, _d; if (!offset_valid(skb, hoffset + tkey->at)) { - pr_info("tc action pedit 'at' offset %d out of bounds\n", - hoffset + tkey->at); + pr_info_ratelimited("tc action pedit 'at' offset %d out of bounds\n", + hoffset + tkey->at); goto bad; } d = skb_header_pointer(skb, hoffset + tkey->at, @@ -401,14 +401,13 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, offset += (*d & tkey->offmask) >> tkey->shift; if (offset % 4) { - pr_info("tc action pedit offset must be on 32 bit boundaries\n"); + pr_info_ratelimited("tc action pedit offset must be on 32 bit boundaries\n"); goto bad; } } if (!offset_valid(skb, hoffset + offset)) { - pr_info("tc action pedit offset %d out of bounds\n", - hoffset + offset); + pr_info_ratelimited("tc action pedit offset %d out of bounds\n", hoffset + offset); goto bad; } @@ -425,8 +424,7 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, val = (*ptr + tkey->val) & ~tkey->mask; break; default: - pr_info("tc action pedit bad command (%d)\n", - cmd); + pr_info_ratelimited("tc action pedit bad command (%d)\n", cmd); goto bad; }