From patchwork Tue Apr 18 23:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13216238 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 395A1C6FD18 for ; Tue, 18 Apr 2023 23:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbjDRXov (ORCPT ); Tue, 18 Apr 2023 19:44:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjDRXop (ORCPT ); Tue, 18 Apr 2023 19:44:45 -0400 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 D67027AA1 for ; Tue, 18 Apr 2023 16:44:44 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5416faa1f2cso706378eaf.0 for ; Tue, 18 Apr 2023 16:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1681861484; x=1684453484; 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=Ba0qF/rc0XT7HspkuZIoGRu2q/iy/JtWq3jiGeoj8lI=; b=bBYKVb8Lw20l5DnYNdUwahXIqPI6UEVvGXzgf3KZXHTgYKXc8G7MXSLphlrBON5zUg hsdaMVKw2vYgos7SZ5BUSD/1yvyFojV77ocZHg4CAQQZsM9O3XB3z7k1rHtnR83l4fev gmPVRAEh96O1pm/eWmE5/CbCctK0v+4+tTbSna88ViKvUek6u0zD95ssaDsGNljQSG38 rbBs+/W7UL29Upg07VVSxmyozxyhQzYxPrgt3tzOKbY4CZZ72UL3eM0E4/nmbKA0GD+A UyIkBvcpk+r+qFn3P99UVxyIWzUck+n2c3kGFa8224yvok9zNfNzIuflg6Vu7JDMMuld nbEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681861484; x=1684453484; 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=Ba0qF/rc0XT7HspkuZIoGRu2q/iy/JtWq3jiGeoj8lI=; b=VBzTxJZ5wM184KVmDlmWRkheLfl7efwxOuGVmRCid3cAWoLAFtQg8dfUz92SmG72+e Q5vCSBK1OFxMXgJyqf64hgtfniuiLkS8HDnLhR+EN34nYFMnosEjnjNuflg+nu5EPzLG H3j7dL5DibwULan4v2dd/OlbgbXABeW+jNe3TzmcYiLc9nvDnF5Q6UsVt7tQL5HG05/t eNuvDHhxP9wP3PgCmnjU3HKEW4MAaWkj2P33+AN26ztJ4zwhLKqVFt6gKbPhjfyQHS0C xGs7qlS+7GNirrGmLRAj9MuFn5Tjw9H95MedIYY3lmAeQyhYHaS0QSY0YhR0BEvdkGSA p07w== X-Gm-Message-State: AAQBX9dM6BSuAPaag7cbUYKHqTc5bmVG/JQznhq4zooKoAUQWAnwWxEu OVGBh9xkJ8Cfk4HXbu3YF09JOVl6VwxXwY6CBUE= X-Google-Smtp-Source: AKy350ZVIR/T/n4jXac7XP5Rd/CNmCRi3y10fL0/KZ2MQyzO896TL2aPGti016y/ReO+jNsE3PsqTA== X-Received: by 2002:a05:6808:120c:b0:38e:2cca:12d8 with SMTP id a12-20020a056808120c00b0038e2cca12d8mr2233349oil.14.1681861484015; Tue, 18 Apr 2023 16:44:44 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:44fb:4981:84ab:7cf2:bd9a]) by smtp.gmail.com with ESMTPSA id o10-20020acad70a000000b0038bae910f7bsm5084357oig.1.2023.04.18.16.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:44:43 -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 v4 1/5] net/sched: act_pedit: simplify 'ex' key parsing error propagation Date: Tue, 18 Apr 2023 20:43:50 -0300 Message-Id: <20230418234354.582693-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418234354.582693-1-pctammela@mojatatu.com> References: <20230418234354.582693-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 'err' is returned -EINVAL most of the time. Make the exception be the netlink parsing and remove the redundant error assignments in the other code paths. Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/act_pedit.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 4559a1507ea5..90f5214e679e 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -54,46 +54,39 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, nla_for_each_nested(ka, nla, rem) { struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1]; + int ret; - if (!n) { - err = -EINVAL; + if (!n) goto err_out; - } n--; - if (nla_type(ka) != TCA_PEDIT_KEY_EX) { - err = -EINVAL; + if (nla_type(ka) != TCA_PEDIT_KEY_EX) goto err_out; - } - err = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, + ret = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, ka, pedit_key_ex_policy, NULL); - if (err) + if (ret) { + err = ret; goto err_out; + } if (!tb[TCA_PEDIT_KEY_EX_HTYPE] || - !tb[TCA_PEDIT_KEY_EX_CMD]) { - err = -EINVAL; + !tb[TCA_PEDIT_KEY_EX_CMD]) goto err_out; - } k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]); k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]); if (k->htype > TCA_PEDIT_HDR_TYPE_MAX || - k->cmd > TCA_PEDIT_CMD_MAX) { - err = -EINVAL; + k->cmd > TCA_PEDIT_CMD_MAX) goto err_out; - } k++; } - if (n) { - err = -EINVAL; + if (n) goto err_out; - } return keys_ex; From patchwork Tue Apr 18 23:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13216239 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 DD48AC77B76 for ; Tue, 18 Apr 2023 23:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbjDRXow (ORCPT ); Tue, 18 Apr 2023 19:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjDRXou (ORCPT ); Tue, 18 Apr 2023 19:44:50 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4878E76B6 for ; Tue, 18 Apr 2023 16:44:48 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-187b70ab997so6838231fac.0 for ; Tue, 18 Apr 2023 16:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1681861487; x=1684453487; 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=CQAPu1eSvMoNXmbccMUUpKP9ooQvfH4HvgAuLdI+JQ4=; b=ukLM4tGj+IPi5r7C3zWDm3+SQwIC7IjL2u1ZdSuBwAbyTHmh4vAAuJSJE4m16tIUpB zbeSnLaHaLLzjHvC2IvK/j1oKhj+lx/3649zN8evNHnsqX2y8in+8VDbGr9OsmOY/QEQ lxvSlZZ9CVGjXcVwhdhJHSaIfcsrXc5zXDeEWzmPWnlhvf5aPIbRGAxhLgCKa4Z3yIP0 aVXuWWmpsOOkWW7SgKTru8oMRPzrfXRdLoA3FjdvbT5uleAnI4AV+5iAg1YmoL7WW4+0 ZLGFaaaM5X+OcAy4nAj1uZ557h0ivtj/vxr77FrkwC7kIn6FE35yn6Rr+GbpJRSMEbyA eL1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681861487; x=1684453487; 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=CQAPu1eSvMoNXmbccMUUpKP9ooQvfH4HvgAuLdI+JQ4=; b=j7+y9ZM4tRKyOn0sgSIzjZ6pJwBuuOiRyIOONzxPtz7fSW9JdOtvDQbH3M99JnaVMO s/oXesPXGXoC3WCK+vqKgXC/JkTQ5g7pQHNdFsZgODD7HmcZaqnB8Sira+ed/dP/aKCB /AAFVSM6ik90fZRzduza9qQFrz2tajlPEnNdS4MejGoUpMqfAfOwmlbpPG47mzCNP36i geMYyo+ljEEjOCu42Rhq3Dy26aUNn5A2KfGT9UPxAWl84Ab5AZEuF+sZQWbJkjhIuzvt bBo6Ra8GoVRmIw7/LS0NQmalCBW8KxG3eQZ/AmIDaEc8AY+matOL2HuasF5XYtkshWf9 evCA== X-Gm-Message-State: AAQBX9dc05KRSdsPaWlRE8L6Jff4TATtyqNe9ppjs6MKKclCN4Wp3LAp INGHsHfQAgobZKNigp61+1yeW5uSvVWyv+hKaHc= X-Google-Smtp-Source: AKy350bphb7cGNXTSzYZkvbmHL9w2lKweQPW0REyAFjIrfo2NrqMaoiY9ENUikcna4XIDqh1nAr/fA== X-Received: by 2002:a05:6808:210b:b0:387:4229:c48f with SMTP id r11-20020a056808210b00b003874229c48fmr310614oiw.26.1681861487182; Tue, 18 Apr 2023 16:44:47 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:44fb:4981:84ab:7cf2:bd9a]) by smtp.gmail.com with ESMTPSA id o10-20020acad70a000000b0038bae910f7bsm5084357oig.1.2023.04.18.16.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:44:46 -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 v4 2/5] net/sched: act_pedit: use extack in 'ex' parsing errors Date: Tue, 18 Apr 2023 20:43:51 -0300 Message-Id: <20230418234354.582693-3-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418234354.582693-1-pctammela@mojatatu.com> References: <20230418234354.582693-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. Signed-off-by: Pedro Tammela Reviewed-by: Simon Horman --- net/sched/act_pedit.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 90f5214e679e..c8f27a384800 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,37 +56,51 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla, struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1]; int ret; - if (!n) + if (!n) { + 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) + if (nla_type(ka) != TCA_PEDIT_KEY_EX) { + NL_SET_ERR_MSG_MOD(extack, "Unknown attribute, expected extended key"); goto err_out; + } - ret = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, - ka, pedit_key_ex_policy, - NULL); + ret = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, ka, + pedit_key_ex_policy, extack); if (ret) { err = ret; goto err_out; } - if (!tb[TCA_PEDIT_KEY_EX_HTYPE] || - !tb[TCA_PEDIT_KEY_EX_CMD]) + if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_HTYPE)) { + NL_SET_ERR_MSG(extack, "Missing required attribute"); goto err_out; + } + + if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_CMD)) { + NL_SET_ERR_MSG(extack, "Missing required attribute"); + goto err_out; + } k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]); k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]); if (k->htype > TCA_PEDIT_HDR_TYPE_MAX || - k->cmd > TCA_PEDIT_CMD_MAX) + k->cmd > TCA_PEDIT_CMD_MAX) { + NL_SET_ERR_MSG_MOD(extack, "Extended key is malformed"); goto err_out; + } k++; } - if (n) + if (n) { + NL_SET_ERR_MSG_MOD(extack, "Not enough extended keys to parse"); goto err_out; + } return keys_ex; @@ -215,7 +229,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 Apr 18 23:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13216240 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 680D1C6FD18 for ; Tue, 18 Apr 2023 23:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231400AbjDRXpB (ORCPT ); Tue, 18 Apr 2023 19:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231423AbjDRXoz (ORCPT ); Tue, 18 Apr 2023 19:44:55 -0400 Received: from mail-oo1-xc30.google.com (mail-oo1-xc30.google.com [IPv6:2607:f8b0:4864:20::c30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D0D9A5E2 for ; Tue, 18 Apr 2023 16:44:51 -0700 (PDT) Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-546ec98b2e2so531539eaf.2 for ; Tue, 18 Apr 2023 16:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1681861490; x=1684453490; 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=GxgK6hoycq0EQWv2MTQ00IogRcEaKtcIwR30qqhff54=; b=B8nJ4NoRWfBs6AuoP+EqciSJdlyGQV7klJC6kgZSlqc94+2WTGrhh4nvMftVMJeGu1 nw7X+F5v26vMaPVw0awy/SUmsuZJJ0pWv2fFYQtCABnik1tCjd1R+hzYjl4E40qa7EWY 7HYJItvDROL8ep4/3iAmRM7Y3TRv5wdR9nH4VEl4KuIHM1Y9ZM1dAAT6R15/8tDglwYv eo0Ho0QHjIPi5Vor+I/MENvCkzaYxVnMHLR0YFDst2ua/Ol46cELWC7160/doOKcwRCi 6NboLNS9EuJ72ZTHbMDcPMsWN07L3ALTPbd7mh+i+DMwr007hCc1rQIKdUKxaXU353pK WWYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681861490; x=1684453490; 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=GxgK6hoycq0EQWv2MTQ00IogRcEaKtcIwR30qqhff54=; b=Hmsg0xm8j/73qfRZkmNwo5wuoz5hnbcgzjefpqQNCRpml2EuKg2iaIpkTVH6SP45NX /1LY7FKKTQNNCGCnIsM041UmoutbsA7RwNpy58m02oiHPVlpLp5Or9QUoIim+ovAAsXr dD+d8u11hymEZeqAr/zTVMRrWdV/+PZIfSYFitqnUR1aI+IdlSZyHAC08p5tZv4+8Q6Y KX92PvQUhSYqhOz44k68fQNSrt7YU9GPIRL10FRnd1t8XAlpyq2/XfRraXDeEE7IDKhH war6JkgQ/GE66Ihx8nQFK8AET8cnMJLhHLdAYnUJj9u65c3lqGiMruZQr/nuDuiQ7+pL Qrhg== X-Gm-Message-State: AAQBX9eWvs8jFpGkDWLZ6FPSWcaA3CjA34yJ3EHUAjv6dsBOGnq+u+el Swg/+bKjyz9P2F6S6WcjAoj3Lg0g7Q0RpvLSuvs= X-Google-Smtp-Source: AKy350bUWgObcyJEzz58gzRz6vxIH6gqU5rGKeh5mkAjQqvhNMSbnUdJDU3y14ky2OBLmFfINbEZFw== X-Received: by 2002:a05:6808:2389:b0:389:340e:be3f with SMTP id bp9-20020a056808238900b00389340ebe3fmr2212895oib.2.1681861490388; Tue, 18 Apr 2023 16:44:50 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:44fb:4981:84ab:7cf2:bd9a]) by smtp.gmail.com with ESMTPSA id o10-20020acad70a000000b0038bae910f7bsm5084357oig.1.2023.04.18.16.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:44:50 -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 v4 3/5] net/sched: act_pedit: check static offsets a priori Date: Tue, 18 Apr 2023 20:43:52 -0300 Message-Id: <20230418234354.582693-4-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418234354.582693-1-pctammela@mojatatu.com> References: <20230418234354.582693-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 c8f27a384800..ef6cdf17743b 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -256,6 +256,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, "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, @@ -414,12 +420,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 Apr 18 23:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13216241 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 A6393C77B75 for ; Tue, 18 Apr 2023 23:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbjDRXpF (ORCPT ); Tue, 18 Apr 2023 19:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231355AbjDRXpA (ORCPT ); Tue, 18 Apr 2023 19:45:00 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B62AAD3D for ; Tue, 18 Apr 2023 16:44:54 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-38dfa504391so843146b6e.3 for ; Tue, 18 Apr 2023 16:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1681861493; x=1684453493; 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=JiWip3RINkgGCsgi6Ojl9PsC/9Wzqn7IEpqRFkuApfA=; b=W1DJLRQaLSD8YyySIV6qqdtjZ8wu1C8lBdXuQHSjfdrzdjaNaIBcH3ar1Bx5R6CGSj +xc7MwWdUJ94NO92ebVvDGXFmkyKro5UJcR7ErLz1Sh8miqbvC47VmvTE2vnTeNYZwIh glX472qElC+9vN7AO5fvM6bDkRBR18mBZ6VbkNskGSGhMS/j7I4gIeY23RGPYQPPuSQg EViaEVv6Do38LOS996sZfAkBH0jhLYsWHg8nDGWJ21zSvTc5h8th6pwKBfn5u0OZBzxr t7HYWLOhALNmdTOUoYi54CIfAkkvPDFkRI7qB/fmrrYTjE7hxX6bMGBEoqkn9hbnliqz qytw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681861493; x=1684453493; 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=JiWip3RINkgGCsgi6Ojl9PsC/9Wzqn7IEpqRFkuApfA=; b=dOPR6B9BR2Yrjfy7wfqplYJqs0/HdPPP/bj8J6BOQBQ6T5apmi2BHM7FVz5tvjf7Gt W9QiKbA0+5TSjf4FTUlRiowP+ChWOOrkpCeEFhp0cwrPlnnqnZ0LjzTWII/uHgCvYx/K llFCAVDXBiSmCy3wukedrsAkgBZc3a5KJTz6BWHGVmxVWstdGLSt8IjbMS1TD+1pwhVB 68x+B1rokvgbarLeNqG6VD3v0v5xcQ71eK0/6mJl/mrAbse1vtzI7FtBBK9Ifva5slTQ pGbnhW4mAyN4ifuMFa7OoxuaT7sqMrhQK16TKOFeOI1OoQZvgHGsGVzmp7QGPdpBnQVQ P2IA== X-Gm-Message-State: AAQBX9dm1cBtcqWlplvhkV9vngpUkT9eZy51fJg8Rdtpy7FoM3YmyPFH yPVsQ5IbCCfjCQwFyu4U3zYAl/kIPgQez156MQY= X-Google-Smtp-Source: AKy350Zo2dFJ2TR+DCLMaeOtaLi/rpLOP4gXpvYtg672RiS4KIDRglXLxcJQsjjlEUkg6V+F7QVfBQ== X-Received: by 2002:a05:6808:287:b0:38c:6997:ca18 with SMTP id z7-20020a056808028700b0038c6997ca18mr1698627oic.46.1681861493633; Tue, 18 Apr 2023 16:44:53 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:44fb:4981:84ab:7cf2:bd9a]) by smtp.gmail.com with ESMTPSA id o10-20020acad70a000000b0038bae910f7bsm5084357oig.1.2023.04.18.16.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:44:53 -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 v4 4/5] net/sched: act_pedit: remove extra check for key type Date: Tue, 18 Apr 2023 20:43:53 -0300 Message-Id: <20230418234354.582693-5-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418234354.582693-1-pctammela@mojatatu.com> References: <20230418234354.582693-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 ef6cdf17743b..2eacada5dcbb 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -326,37 +326,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, @@ -389,10 +380,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; @@ -401,12 +391,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 Apr 18 23:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Tammela X-Patchwork-Id: 13216242 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 B5C13C77B75 for ; Tue, 18 Apr 2023 23:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231520AbjDRXpR (ORCPT ); Tue, 18 Apr 2023 19:45:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231590AbjDRXpI (ORCPT ); Tue, 18 Apr 2023 19:45:08 -0400 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF7F196 for ; Tue, 18 Apr 2023 16:44:57 -0700 (PDT) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-541af0d27d8so453282eaf.3 for ; Tue, 18 Apr 2023 16:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1681861497; x=1684453497; 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=GdIUZtQy0YH9bPACPF7kkjB6snFDfJMGHK0km93mha4=; b=Ftk9RTyxLAn48h925YQwII0eNYdcEFthM6UnP/rsKMJU8ZE1/K2T4TU9WuOHKfGScT 1nmCjtMBF9gG/crzFvNBW7kkwGtmyljzjv3AGRAPXI4/shrRA7X54YZFB3meqUujtTNE eno8CtmHwkAw5VmFhkzrxVRkl+q0/0ASilIegJZ0+W6NWIXSIYm98DBHafpcuLUVbDrQ MuvOkwP0DeXc93BDjYuEYFu4JszIbB64pSQyi8Z3sDHdA2LebKUKGYd9BDPm2o/X2TrX vob3ktz1q/gJ8Ex+ojWjHwp1ByOtOpBbWCS7ZnC5ljV1DMKi09DAq6f+yuka1YzFctUL 9SOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681861497; x=1684453497; 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=GdIUZtQy0YH9bPACPF7kkjB6snFDfJMGHK0km93mha4=; b=GeWE/KzKTe8KR65Z+5YN7QosoIg5tVgp0f8If7wLtRm3t8QpkLbwC4bNoUYNVU8fts Mj7+h5SSCm1W3cU2/4Cw9UO1mQwQDb25XN3hOaVNX1IJo9ODcll+5+OI1LCdc7OnoGsz B51i1L2i93Ktjov+Z2Bn58Jta41aEbAvCQtY44y6YM0uLJ35lqzB7rAvL/4uAUMbIQPx gd0kN3p+hEqbAjdNpar/wCKQl3ui8M0adxf3rX8Nk1vGft+ZWxSjk48pg2osi2JwXphR BbMbBt1mIuELBhBwV2ZzuDMVXuYBlejPQyVpVZR6txoJ9Sxyv4GtoYB5HlaNRF1cWSaV 5/eg== X-Gm-Message-State: AAQBX9fqboI/7IhhUzgrPL5ldSsZU/nFY4ayZ2QgJBqrDe1EpevM7rcm iG0r7ntSCXpSYpfUM52o3QOPj/hZJgVzFV1baOU= X-Google-Smtp-Source: AKy350bbN6W7l75vRSjYUNz3SNKziZjnqh/jU79OYalun04Rxss/A7oZ/Xs1bQQuLRY9yVk+7ng+gw== X-Received: by 2002:a05:6808:3a1:b0:384:833:2a79 with SMTP id n1-20020a05680803a100b0038408332a79mr1853683oie.48.1681861496876; Tue, 18 Apr 2023 16:44:56 -0700 (PDT) Received: from localhost.localdomain ([2804:14d:5c5e:44fb:4981:84ab:7cf2:bd9a]) by smtp.gmail.com with ESMTPSA id o10-20020acad70a000000b0038bae910f7bsm5084357oig.1.2023.04.18.16.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 16:44:56 -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 v4 5/5] net/sched: act_pedit: rate limit datapath messages Date: Tue, 18 Apr 2023 20:43:54 -0300 Message-Id: <20230418234354.582693-6-pctammela@mojatatu.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418234354.582693-1-pctammela@mojatatu.com> References: <20230418234354.582693-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 2eacada5dcbb..791144012c91 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -397,8 +397,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, @@ -408,14 +408,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; } @@ -432,8 +431,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; }