From patchwork Tue Mar 14 20:24:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13174984 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 E1646C74A44 for ; Tue, 14 Mar 2023 20:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231224AbjCNUZG (ORCPT ); Tue, 14 Mar 2023 16:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbjCNUZE (ORCPT ); Tue, 14 Mar 2023 16:25:04 -0400 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A30412CC6B for ; Tue, 14 Mar 2023 13:25:00 -0700 (PDT) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-17683b570b8so18645769fac.13 for ; Tue, 14 Mar 2023 13:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1678825500; 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=1YVnzgg+Ck3vhoAoX3omT52Cmi1qLSD9CMfKQsgHwFE=; b=zLHlo4ExPsQsq7+3aUtR1Q66/zf1an4cUglvxIuvBcdjEcWTYJP+RDqKJhr/Ah3iep XRdBBkXfFtLitPU91YCqjWr3uaNzBbEJuEstlt+eT8U4dU5fHdZuT47M1BiVo7b8lsUP mxiPNRTrBWCkZmm2V4XRhCaghEfqqYzo1RAdJmT6sEQjRjclssDigR09gLKMPhko8xr7 2btfPpwKxPW+s7CuStgVwPx+sxM3EieW9loMRSdKUp0AHwwCjyavWYAEpiEdguJvyKZo VVGZ2FYsmtKpZM+WVbqiV6KfuRzW/Go6Zxh/lOn/YY2fQd58myntqHMcESeS6MRH9H+D Ncsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678825500; 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=1YVnzgg+Ck3vhoAoX3omT52Cmi1qLSD9CMfKQsgHwFE=; b=bPurD3KB5+qEKHaI7S7TFS18JCAPBQT0kaqr7dPg/uIvHhE18ZK49ejjj0j3ATpnDh A3acTGjqyhTHmO22dtAQ1UEPrcl1XAdW53uER9Wxo3mGXIkSb32vyX4X0UaoCziYwEvJ Lqsqe6pLtniwnZQBxAEfWRGfZQKEfgsElJFXRPRHLNgtukF2rrMiohlDXTX2JWxrs8Xi rFBs8K4tBAIDa/UiJaKgc5K1vblEPXbmlACyZpHKunIKIf97TV2Gd+5lCo68reW1HgQd gXPUoFrhizA1cl8BQdwdLaJCjuUy0h2YVDCRA6qUnULoi+zawSwuFXHWdjqGN1MJVklb 1r/Q== X-Gm-Message-State: AO0yUKUwEEmXhcvvkKPMVYQYVlqWj7TjJf+vq/5PO1n90Ksb5G/HXcql TzLKmerOOjpaO/aJBaZqrwHHH5ax2TmKHAF+N6g= X-Google-Smtp-Source: AK7set9ewwjv6nDcCRxvwnD6lt7A1Vax1+2WS9seyXdHj78lss1QsTm/C6SGRD8s9zxaphKmVlWACQ== X-Received: by 2002:a05:6870:9107:b0:176:3f58:4a06 with SMTP id o7-20020a056870910700b001763f584a06mr25558828oae.40.1678825499904; Tue, 14 Mar 2023 13:24:59 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:95f9:b8d9:4b9:5297]) by smtp.gmail.com with ESMTPSA id 103-20020a9d0870000000b00690e783b729sm1509278oty.52.2023.03.14.13.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:24:59 -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, Pedro Tammela Subject: [PATCH net-next v2 1/4] net/sched: act_pedit: use extack in 'ex' parsing errors Date: Tue, 14 Mar 2023 17:24:45 -0300 Message-Id: <20230314202448.603841-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230314202448.603841-1-pctammela@mojatatu.com> References: <20230314202448.603841-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 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 4559a1507ea5..be9e7e565551 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; } @@ -99,7 +99,7 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, err_out: kfree(keys_ex); - return ERR_PTR(err); + return ERR_PTR(-EINVAL); } static int tcf_pedit_key_ex_dump(struct sk_buff *skb, @@ -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 Tue Mar 14 20:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13174985 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 2D0FEC05027 for ; Tue, 14 Mar 2023 20:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229687AbjCNUZH (ORCPT ); Tue, 14 Mar 2023 16:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjCNUZF (ORCPT ); Tue, 14 Mar 2023 16:25:05 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA3E2A6F8 for ; Tue, 14 Mar 2023 13:25:03 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id o4-20020a9d6d04000000b00694127788f4so9094004otp.6 for ; Tue, 14 Mar 2023 13:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1678825502; 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=9/4Vb9Ag+cfw7q3a8zKAHcNDFnmlytJGB3KfyaKeoPQ=; b=dBqi/7KNlObmSN9IUyXSUOSp9cggZRN2OZZSd7lnjK9UIJe2Xn2qvRVFte6HHTAkSh tnwfGBA8z66KzdHJ/FO3FX0CmbwEeZwGyh1D7fIebmSYAkrHARn94X2cWm7wKZOi9GWW CziLGFB8AbJ+PPJCmamjh+RBVe0euv39zUn3PVm7TxC5zCfA/HKG7DrAswpffslQLLIz C7lXTqnHTXZbJWXlxCaEqV8Vm0Z3aAlcOMuHmyQjxhmRs4BjiI7TR7UD8CBokqYIFblq BKG15/T2bzPofzTBG7g59msji8lAI+Y1ZviP7SVXdDye7FxQHVM6tkFAOiPKgfTMvfFO ZVjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678825502; 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=9/4Vb9Ag+cfw7q3a8zKAHcNDFnmlytJGB3KfyaKeoPQ=; b=Oz/I1i8Ao5ZR6ZYUYz0FxkuDinAd3Sc19EHf3fmHQWTz3McNAjq6l4pTO0AxrLJ+An PCugEqzc8VxcmxnBqr7nVaw07Sr8Q5EARnUhv+81AVcun23NqZSQzelT9tlWFYHk5lF3 prxHrkktWr6yP6Lu4sqCjg6XYR9XqUrVIs/daCsFgHD0Y7DbbXXwolRybH3F81QPhLu4 MurP1UC98cvCRWSNFMbMMXsh5ump7cinzk3kRRBkTo0oJehkdlq+SO17D8KUC6zT4sCF mwG3DVxM3n12jBRF2cElxrIF4ZWRJQkBwMG7Efotsxmb83gvpaY/gaLoBKt0mW7u/i47 9cAQ== X-Gm-Message-State: AO0yUKUFzDuXnE7eRByHhMjw6T96MdyXFyQE2oAHg/mMi6QaF4TaOO3p LHr4YA/d73py9eci0e+1ON4HxjuuStEe6in+qQM= X-Google-Smtp-Source: AK7set+zU4BV6VUQEFo6cPIa/SPwMkr1L85E1458ROPVs7u9uvsZ8OIz18eKDMfW4EUVnGspHdcuvA== X-Received: by 2002:a05:6830:1614:b0:68d:50ac:b261 with SMTP id g20-20020a056830161400b0068d50acb261mr17597420otr.1.1678825502588; Tue, 14 Mar 2023 13:25:02 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:95f9:b8d9:4b9:5297]) by smtp.gmail.com with ESMTPSA id 103-20020a9d0870000000b00690e783b729sm1509278oty.52.2023.03.14.13.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:25: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, Pedro Tammela Subject: [PATCH net-next v2 2/4] net/sched: act_pedit: check static offsets a priori Date: Tue, 14 Mar 2023 17:24:46 -0300 Message-Id: <20230314202448.603841-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230314202448.603841-1-pctammela@mojatatu.com> References: <20230314202448.603841-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 Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- 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 be9e7e565551..e6725e329ec1 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 Tue Mar 14 20:24:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13174986 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 21DECC6FD1F for ; Tue, 14 Mar 2023 20:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbjCNUZO (ORCPT ); Tue, 14 Mar 2023 16:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjCNUZH (ORCPT ); Tue, 14 Mar 2023 16:25:07 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0765924BE3 for ; Tue, 14 Mar 2023 13:25:05 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id e26-20020a9d6e1a000000b00694274b5d3aso9103797otr.5 for ; Tue, 14 Mar 2023 13:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1678825505; 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=H2PkFhtB5ZubtyL+ATwbxbh9RB/tWz0cSQR+9+zw2VU=; b=xcbTz6jjxfOcAncDE0rafYDVRZ1/HYoR1MtoPz5F6Yugj6b9RUz4qiNWItUS2ESiiX S02O0dJ4kFrPOi7Hb+u+DQy8Tz9PFGb/Cq9i/uwqLBQxM8PyRfjjUmhjEq7H3bwzSofw v/H8YmU0idM+72BWz4zQMlXLINx3pJZIz6A65+2AlscF98VPK9OMMNUaeKQTU6WtWSXd c1f/ACqol8YIw22+2NX4G8BV8gOE81FjNxGPlD78ghMCb4dQ7xYWiAtCSu9U5gE97w3Z qDz+3vkaVxIm/WE7C2nWco11AX8tkfMqrTTQP0zFWWIEJ7N/f0criF5tUIkBWX2pGu23 W3Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678825505; 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=H2PkFhtB5ZubtyL+ATwbxbh9RB/tWz0cSQR+9+zw2VU=; b=DSxO5Vxaf8TK7Ao/t2UTbOg+UY5RhkbCekQPbFNe9LJ0+K1UuIn4vW56/oc0i1C/Gj xMjB7wfE8Sj5P8GNUB0r/wvnR8IQbp5jeaJViH6Rvthj5IcGOpILNNSpcisqPpw56ioQ Z7B33G8WA2ajQi6qdrLcKRNX9RdYEAMHlwujS0G7sHaNNWOtGeQ33M4zcZawsRmn8Tmq 6i9TqqgPmhy4D9y7bZ0r5yhWHo6fhRNC/AIzir6Lac/IO1O3CB5o9yOGI63td1JuP1YX VtKQXh/8H8wTMvWBqby7F+Ft76SPzK5NKBEn3yYx2HZAsRI0g8a0s4KDqbUR5GTTDrOq x/ZA== X-Gm-Message-State: AO0yUKU9qUtS8sBjXqUPmqg6btVvVoul+O5ESYj09FpBKK8T/rIEcq2x A0fJeRqOWrDcJr2IzGxJaDFV2MpPi6jOeUjiPwI= X-Google-Smtp-Source: AK7set9lbMPO4HZJ1+BDSrilU1huRoPthJ5WMnah1jiiAmBfBOY8Vfzj++gfcHvd8rorjRhIZ8jppw== X-Received: by 2002:a9d:487:0:b0:696:13be:c37a with SMTP id 7-20020a9d0487000000b0069613bec37amr2012721otm.22.1678825505234; Tue, 14 Mar 2023 13:25:05 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:95f9:b8d9:4b9:5297]) by smtp.gmail.com with ESMTPSA id 103-20020a9d0870000000b00690e783b729sm1509278oty.52.2023.03.14.13.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:25: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, Pedro Tammela Subject: [PATCH net-next v2 3/4] net/sched: act_pedit: remove extra check for key type Date: Tue, 14 Mar 2023 17:24:47 -0300 Message-Id: <20230314202448.603841-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230314202448.603841-1-pctammela@mojatatu.com> References: <20230314202448.603841-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 Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- 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 e6725e329ec1..b09e931f23d5 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 Tue Mar 14 20:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13174987 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 683E9C74A44 for ; Tue, 14 Mar 2023 20:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbjCNUZR (ORCPT ); Tue, 14 Mar 2023 16:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbjCNUZO (ORCPT ); Tue, 14 Mar 2023 16:25:14 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3DED4FF35 for ; Tue, 14 Mar 2023 13:25:08 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id f17-20020a9d7b51000000b00697349ab7e7so1652815oto.9 for ; Tue, 14 Mar 2023 13:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1678825508; 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=SzQcWiPyd6cW0XzNnHNmInOQT29eG1He3iX5OPy5vIU=; b=AXq+C9C06n+rCYBhAwiB8LF35e4exwyk9D6L5SBRM2CkSFJgcP2GFmXLDPUlQJZft6 MyDaPmU2qH//RyTMMPV8f5FqvCzV8NdhogW5PunMxw3QEF7pn4xqTgDF7kUc520T0Cqc hM/+XGG+dCyZHH1SQb7dEbcAVe49HIsBACjlI792squeIy5lqRgxQpr8JCvGrTDEpNcM il0Pl8k7+107A8KYPHvjNsjiZ4KGhSnU/EwEz3uA+KgYKaaOeD/HgXPBd2DdrZl0fgdo MWwxCfkXaGz3onZULFfiTuyCul7IJJEel83b9CZT/G3U1Gujv7rcpWQG2Qwrik58LgNv Qslw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678825508; 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=SzQcWiPyd6cW0XzNnHNmInOQT29eG1He3iX5OPy5vIU=; b=jbrgUUCWmRBgqSGp/Or/eZXuqz9vJX1mUpmtqXKEycP4JAwdTa2tH/h5K2Q0HWZm9t bVkzp9glrMhmq02mkGOD4x3nlhMuVrK33U9vFCeFskR2dQdzT2INr/5ZbjaCZS7Hu7qY czmP6Of8mBqB1j9C+kiTOdv74fZ/275nT30Nvd46uKSWH5mIF7KsRhGF3B/wdcqNbFPM fdV+NqAlYjqUbCBv1NMwUJM76sKF3pVQkuUNEA/cL0zsMNMk4TJ2MXQYTIBFJHjZYyw9 9PzVWuXoY7yQehF0x7HqrInGoZ1XuGeunJ9I+kBQ3uk2ng49DBRT6vr69UrwxQygXIOe VYVw== X-Gm-Message-State: AO0yUKXj8Nqv5ArHSV0cmJK/CGrKinYSFLYceCGP3cHneOkuZHP4NG6R uE64KVcjmrlSxE6ZFGYe/tMjEDprqqP+2ja5MW8= X-Google-Smtp-Source: AK7set+5Akl05v/cg4ZM6LHFCfqqdMiVIZTFH9XeDIbWQz5YaywKmQYckO6ISPTGe2jNN/lrZ27PuQ== X-Received: by 2002:a05:6830:71b:b0:694:88fa:b82f with SMTP id y27-20020a056830071b00b0069488fab82fmr12928070ots.27.1678825507950; Tue, 14 Mar 2023 13:25:07 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:4698:95f9:b8d9:4b9:5297]) by smtp.gmail.com with ESMTPSA id 103-20020a9d0870000000b00690e783b729sm1509278oty.52.2023.03.14.13.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 13:25:07 -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, Pedro Tammela Subject: [PATCH net-next v2 4/4] net/sched: act_pedit: rate limit datapath messages Date: Tue, 14 Mar 2023 17:24:48 -0300 Message-Id: <20230314202448.603841-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230314202448.603841-1-pctammela@mojatatu.com> References: <20230314202448.603841-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 Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- 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 b09e931f23d5..ffcbc83dd5c5 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; }