mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jérémy Jean" <jeremy.jean@oss.cyber.gouv.fr>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>,
	Jiri Pirko <jiri@resnulli.us>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net] net/sched: fix use-after-free in __tcf_action_put()
Date: Thu, 08 Oct 2026 11:03:42 +0200	[thread overview]
Message-ID: <776ed0c422ace98fd907468f78ea9cb0@oss.cyber.gouv.fr> (raw)
In-Reply-To: <20261007173503.588b9c7f@kernel.org>

On 2026-10-08 02:35, Jakub Kicinski wrote:
> On Wed, 30 Sep 2026 21:18:40 +0000 Jérémy Jean wrote:
>>  {
>>  	struct tcf_idrinfo *idrinfo = p->idrinfo;
>> 
>> -	if (refcount_dec_and_mutex_lock(&p->tcfa_refcnt, &idrinfo->lock)) {
>> -		if (bind)
>> -			atomic_dec(&p->tcfa_bindcnt);
>> -		idr_remove(&idrinfo->action_idr, p->tcfa_index);
>> +	mutex_lock(&idrinfo->lock);
>> +	if (bind)
>> +		atomic_dec(&p->tcfa_bindcnt);
>> +	if (!refcount_dec_and_test(&p->tcfa_refcnt)) {
>>  		mutex_unlock(&idrinfo->lock);
>> -
>> -		tcf_action_cleanup(p);
>> -		return 1;
>> +		return 0;
>>  	}
>> 
>> -	if (bind)
>> -		atomic_dec(&p->tcfa_bindcnt);
>> +	idr_remove(&idrinfo->action_idr, p->tcfa_index);
>> +	mutex_unlock(&idrinfo->lock);
>> 
>> -	return 0;
>> +	tcf_action_cleanup(p);
>> +	return 1;
>>  }
> 
> Why did you decide to invert the condition?
> If nothing else the diff would be more readable without that

Indeed, you are right: there was no specific reason for the inversion.
Below is a new fix suggestion.
If you agree with it, I could send it as a v2.

Regards,
Jérémy

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index e45a63be397c..9eb1dec14cb1 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -372,9 +372,10 @@ static int __tcf_action_put(struct tc_action *p, 
bool bind)
  {
         struct tcf_idrinfo *idrinfo = p->idrinfo;

-       if (refcount_dec_and_mutex_lock(&p->tcfa_refcnt, 
&idrinfo->lock)) {
-               if (bind)
-                       atomic_dec(&p->tcfa_bindcnt);
+       mutex_lock(&idrinfo->lock);
+       if (bind)
+               atomic_dec(&p->tcfa_bindcnt);
+       if (refcount_dec_and_test(&p->tcfa_refcnt)) {
                 idr_remove(&idrinfo->action_idr, p->tcfa_index);
                 mutex_unlock(&idrinfo->lock);

@@ -382,9 +383,7 @@ static int __tcf_action_put(struct tc_action *p, 
bool bind)
                 return 1;
         }

-       if (bind)
-               atomic_dec(&p->tcfa_bindcnt);
-
+       mutex_unlock(&idrinfo->lock);
         return 0;
  }

  reply	other threads:[~2026-10-08  9:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 21:18 Jérémy Jean
2026-09-30 21:24 ` netdev-bot+sinfo
2026-10-08  0:35 ` Jakub Kicinski
2026-10-08  9:03   ` Jérémy Jean [this message]
2026-10-08 17:12     ` Jakub Kicinski

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=776ed0c422ace98fd907468f78ea9cb0@oss.cyber.gouv.fr \
    --to=jeremy.jean@oss.cyber.gouv.fr \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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®