🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #576

Re: [PATCH net] net/sched: fix use-after-free in __tcf_action_put()

#576
From: Jérémy Jean
Date: Thu, 08 Oct 2026 09:03
72 lines
8761 bytes
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;
  }
Technical Details
Message-ID: <776ed0c422ace98fd907468f78ea9cb0@oss.cyber.gouv.fr>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342844-linux-kernel-netdev=dewy.ru
References: <20260930211839.620410-2-Jeremy.Jean@oss.cyber.gouv.fr> <20261007173503.588b9c7f@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342844-linux-kernel-netdev=dewy.ru
From: jeremy.jean@oss.cyber.gouv.fr (Jérémy Jean)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/sched: fix use-after-free in __tcf_action_put()
Date: Thu, 08 Oct 2026 11:03:42 +0200
Organization: Usenet Network
Message-ID: <776ed0c422ace98fd907468f78ea9cb0@oss.cyber.gouv.fr>
References: <20260930211839.620410-2-Jeremy.Jean@oss.cyber.gouv.fr>
 <20261007173503.588b9c7f@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8;
 format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="841258"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:76hFK94cWI3Ih5kAhZhqjnAXDt4= sha256:9hiFC8lauMVESBdW+rLkFDetus8qk3T7gE0eNEK6j5M=
	sha1:eoZ2fyGHhMEx6QvtmMkweDaU8LU= sha256:riJrAD1JgpENj4EsWFrWSfZ5AX6UcLRANaHKTXjrHgg=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
	X-Source
	X-Source-Args
	X-Source-Dir
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 5DEC410F365; Thu,  8 Oct 2026 12:04:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.391
X-Spam-Status: No, score=-3.391 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=oss.cyber.gouv.fr
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id S2frwV_pSRa6;
	Thu,  8 Oct 2026 12:04:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-342844-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=oss.cyber.gouv.fr
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id CC0C310EE88; Thu,  8 Oct 2026 12:04:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sto.lore.kernel.org (Postfix) with ESMTP id 77D806036EF; Thu,  8 Oct 2026 09:03:55 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A4B9D47C107;
	Thu,  8 Oct 2026 09:03:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.b="j7PDxMYR"
X-Received: from oss.cyber.gouv.fr (oss.cyber.gouv.fr [51.159.188.251])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9374E47F2F8;
	Thu,  8 Oct 2026 09:03:44 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.188.251
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791450232; cv=none; b=uDdShGwUuHXP+Qz6tlavl4SU27oOVdD9vV0OeOjbj2qVhYmpZrbjqeAa7RkD3B0bDXibclTd1b6GoONZ0HRXlfjexRxePbC87hr4RJjtkgv/creWlJdplSXRzCRLSa2sUadPKNi1S8VlsREH1+nhE0EfIZhs4gDW3F7oNeUvK4M=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791450232; c=relaxed/simple;
	bh=j6pSGeC1MTs7/YddTI+AU/X+Y599J5vImXbUeyZlGkg=;
	h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References:
	 Message-ID:Content-Type; b=Xh+Vy4kNdsk/R5WqmMniAukTTgi0ah6QPyYBXFzhwb88j5w2kiNg7bq/M2zGAmyTzdaTmubo0dsLJ8BQoOE1xyA9rVHb7Sr5w+XEw8ZBT90+4qG/lOwAXUdPoth3cWW/7jiMB0Kh98+LjqYIGyaXB3ZNfNTnKmfW9My0dGlAHwQ=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr; spf=pass smtp.mailfrom=oss.cyber.gouv.fr; dkim=pass (2048-bit key) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.b=j7PDxMYR; arc=none smtp.client-ip=51.159.188.251
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.cyber.gouv.fr
X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
	d=oss.cyber.gouv.fr; s=default; h=Content-Transfer-Encoding:Content-Type:
	Message-ID:References:In-Reply-To:Subject:Cc:To:From:Date:MIME-Version:
	Reply-To:Sender:Content-ID:Content-Description:Resent-Date:Resent-From:
	Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
	bh=0vXi5kAmq0ktXNfJ32duwtCOreHH5Rg+dCEdNRfBLi4=; b=j7PDxMYR6urzqEAbV4dlCqZenP
	xDiB+Td+MaUXvUQLMp7m1SrSnaKViCe8na81FdSHxCnjx7BG2oc3zhUfk7RqpdWfaIfrHl/15IycI
	C/uyz64txrPxwXMms6NDhzk/2VDoPRr8RPFSBJ5C0wEwAAprXseTXwMw0rtSk/P9u2IBjd+XaVUcu
	S880hTd4wYREGnuhAlCbGYNJoXF58iyh/ue5Zntx5iEe7CqhyadpMltCwwC2JQvcrtyI2lURHuVwU
	QBLwaZSljDi8UPsk10lzP32bSmd76OdYTTVb3ds/kiE2FHAjB1XxsJXJxIr/irwAUMuNITd8uCGSq
	BlXkM66Q==;
X-Received: from [::1] (port=53148 helo=pf-012.whm.fr-par.scw.cloud)
	by pf-012.whm.fr-par.scw.cloud with esmtpa (Exim 4.100.1)
	(envelope-from <jeremy.jean@oss.cyber.gouv.fr>)
	id 1xEk2Q-00000002Mkl-1DKP;
	Thu, 08 Oct 2026 11:03:42 +0200
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-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
X-In-Reply-To: <20261007173503.588b9c7f@kernel.org>
X-User-Agent: Roundcube Webmail/1.6.19
X-Sender: jeremy.jean@oss.cyber.gouv.fr
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - pf-012.whm.fr-par.scw.cloud
X-AntiAbuse: Original Domain - vger.kernel.org
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - oss.cyber.gouv.fr
X-Get-Message-Sender-Via: pf-012.whm.fr-par.scw.cloud: authenticated_id: jeremy.jean@oss.cyber.gouv.fr
X-Authenticated-Sender: pf-012.whm.fr-par.scw.cloud: jeremy.jean@oss.cyber.gouv.fr