From: Pedro Tammela <pctammela@mojatatu.com>
To: Ivan Vecera <ivecera@redhat.com>, netdev@vger.kernel.org
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Paul Blakey <paulb@nvidia.com>,
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net] net/sched: cls_api: Initialize miss_cookie_node when action miss is not used
Date: Thu, 20 Apr 2023 15:21:06 -0300 [thread overview]
Message-ID: <77920a21-96ab-54e5-db3d-5083a11d5691@mojatatu.com> (raw)
In-Reply-To: <20230420175952.1114302-1-ivecera@redhat.com>
On 20/04/2023 14:59, Ivan Vecera wrote:
> Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only
> when use_action_miss is true so it assumes in other case that
> the field is set to NULL by the caller. If not then the field
> contains garbage and subsequent tcf_exts_destroy() call results
> in a crash.
> Initialize .miss_cookie_node pointer to NULL when use_action_miss
> parameter is false to avoid this potential scenario.
>
> Fixes: 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action")
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> ---
> net/sched/cls_api.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
> index 35785a36c80298..8bc5b9d6a2916e 100644
> --- a/net/sched/cls_api.c
> +++ b/net/sched/cls_api.c
> @@ -3224,8 +3224,12 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,
> exts->action = action;
> exts->police = police;
>
> - if (!use_action_miss)
> + if (!use_action_miss) {
> +#ifdef CONFIG_NET_CLS_ACT
> + exts->miss_cookie_node = NULL;
> +#endif
> return 0;
> + }
>
> err = tcf_exts_miss_cookie_base_alloc(exts, tp, handle);
> if (err)
The problem described here also happens in the case some error happens
if the action array allocation fails and before the 'miss_cookie_node'
assignment inside 'tcf_exts_miss_cookie_base_alloc()'.
Seems like a better way to solve this issue is to just:
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 35785a36c802..3c3629c9e7b6 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct
net *net, int action,
#ifdef CONFIG_NET_CLS_ACT
exts->type = 0;
exts->nr_actions = 0;
+ exts->miss_cookie_node = NULL;
/* Note: we do not own yet a reference on net.
* This reference might be taken later from tcf_exts_get_net().
*/
next prev parent reply other threads:[~2023-04-20 18:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 17:59 Ivan Vecera
2023-04-20 18:21 ` Pedro Tammela [this message]
2023-04-20 18:35 ` Ivan Vecera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=77920a21-96ab-54e5-db3d-5083a11d5691@mojatatu.com \
--to=pctammela@mojatatu.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=ivecera@redhat.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paulb@nvidia.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®