🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22331

Re: [PATCH net] tcp: fix CA module refcount underflow in tcp_v4_syn_recv_sock()

#22331
From: Jiayuan Chen
Date: Wed, 25 Nov 2026 06:37
165 lines
14262 bytes

On 11/25/26 2:26 PM, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [Medium] The new error path in tcp_v4_syn_recv_sock()
>   (net/ipv4/tcp_ipv4.c) jumps to clear_ca_and_exit when…
> - [Low] The commit message presents the bug as a module refcount
>   underflow that shows up as a module_put() WARNING.
> 
> --
> 
> tcp: fix CA module refcount underflow in tcp_v4_syn_recv_sock()
> 
> The child socket inherits icsk_ca_ops from the listener without taking a
> reference. If inet_csk_route_child_sock() fails, the child then puts the
> listener's reference. This patch clears icsk_ca_ops on that error path and
> makes tcp_cleanup_congestion_control() skip a socket that has no CA.
> 
>> If inet_csk_route_child_sock() fails in between, we go to put_and_exit
>> and tcp_done() ends up in tcp_cleanup_congestion_control(), which puts
>> the reference unconditionally. The one dropped belongs to the listener.
> 
> [Severity: Low]
> 
> Is the impact larger than a refcount underflow warning?
> 

> module_put() uses atomic_dec_if_positive() and only warns when the count
> would go negative:
> 
> kernel/module/main.c:module_put() {
>     ...
> 		ret = atomic_dec_if_positive(&module->refcnt);
> 		WARN_ON(ret < 0);	/* Failed to put refcount */
>     ...
> }
> 
> While the listener still holds its reference, the child's put in
> tcp_cleanup_congestion_control() succeeds silently and uses up the
> listener's reference. The quoted WARN only fires after earlier occurrences
> have already drained that reference.
> 
> Once that has happened, try_release_module_ref() lets rmmod of tcp_bbr
> succeed while the listener's icsk_ca_ops still points into the module.
> Later children read icsk_ca_ops->owner through bpf_try_module_get() in
> tcp_ca_openreq_child(), and closing the listener calls ->release() on it.
> Could either of these be a use-after-free?
> 
> If the count has dropped below the base instead, rmmod would hit
> BUG_ON(ret < 0) in try_release_module_ref().
> 
> For BPF struct_ops congestion control, bpf_module_put() goes through
> bpf_struct_ops_put() -> bpf_map_put():
> 
> include/linux/bpf.h:bpf_module_put() {
> 	if (owner == BPF_MODULE_OWNER)
> 		bpf_struct_ops_put(data);
> 	else
> 		module_put(owner);
> }
> 
> In that case the extra put drops a struct_ops map reference while the
> listener is still using the map.
> 
> Could the commit message describe this impact, for the benefit of stable
> maintainers?
> 

It's meanless, we can't enumerate all cases‌ into commit message.


>> diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
>> index e3f462f161dd6..0f99405a78b11 100644
>> --- a/net/ipv4/tcp_cong.c
>> +++ b/net/ipv4/tcp_cong.c
>> @@ -271,6 +271,9 @@ void tcp_cleanup_congestion_control(struct sock *sk)
>>  {
>>  	struct inet_connection_sock *icsk = inet_csk(sk);
>>  
>> +	if (!icsk->icsk_ca_ops)
>> +		return;
>> +
>>  	if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release)
>>  		icsk->icsk_ca_ops->release(sk);
>>  	icsk->icsk_ca_initialized = 0;
>> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
>> index 2fc92a7884fc8..8aa52376cf0aa 100644
>> --- a/net/ipv4/tcp_ipv4.c
>> +++ b/net/ipv4/tcp_ipv4.c
>> @@ -1732,7 +1732,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
>>  	if (!dst) {
>>  		dst = inet_csk_route_child_sock(sk, newsk, req);
>>  		if (!dst)
>> -			goto put_and_exit;
>> +			goto clear_ca_and_exit;
>>  	} else {
>>  		/* syncookie case : see end of cookie_v4_check() */
>>  	}
>> @@ -1789,6 +1789,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
>>  exit:
>>  	tcp_listendrop(sk);
>>  	return NULL;
>> +clear_ca_and_exit:
>> +	/* newsk holds no reference on the inherited CA yet. */
>> +	inet_csk(newsk)->icsk_ca_ops = NULL;
> 
> [Severity: Medium]
> 
> Does this comment hold in all cases?
> 



> tcp_create_openreq_child() calls inet_csk_clone_lock(). That function moves
> the child to TCP_SYN_RECV and then calls security_inet_csk_clone(), all
> before the route lookup above:
> 
> net/ipv4/inet_connection_sock.c:inet_csk_clone_lock() {
>     ...
> 	inet_sk_set_state(newsk, TCP_SYN_RECV);
> 
> 	inet_clone_ulp(req, newsk, priority);
> 
> 	security_inet_csk_clone(newsk, req);
>     ...
> }
> 
> bpf_lsm_inet_csk_clone is listed in bpf_lsm_locked_sockopt_hooks in
> kernel/bpf/bpf_lsm.c. A BPF_LSM_CGROUP program attached there can
> therefore call bpf_setsockopt(TCP_CONGESTION) on the child:
> 
> sol_tcp_sockopt_congestion()
>   do_tcp_setsockopt()
>     tcp_set_congestion_control()
>       bpf_try_module_get(ca, ca->owner)  <- takes a reference on the new CA
>       tcp_reinit_congestion_control()
>         tcp_init_congestion_control()    <- ca->init(),
>                                             icsk_ca_initialized = 1
> 

It's not for net tree and I have already sent a fix to bpf tree. 

I also intentionally mentioned it under diff stat to suppress this review
but I think I failed:

'''
   ...
   Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
   ---
   security_inet_csk_clone() -> bpf_setsockopt(TCP_CONGESTION) from a
   lsm_cgroup prog has a similar problem, the child puts a reference it
   never took. That one is being fixed in the bpf tree.
   ...
'''
Technical Details
Message-ID: <663c0be8-60c8-45d6-baf6-5bc4ac0ae173@linux.dev>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371072-linux-kernel-netdev=dewy.ru
References: <20261124062625.264148-1-jiayuan.chen@linux.dev> <179558800299.3135.4905748131998876050@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371072-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: fix CA module refcount underflow in
 tcp_v4_syn_recv_sock()
Date: Wed, 25 Nov 2026 14:37:10 +0800
Organization: Usenet Network
Message-ID: <663c0be8-60c8-45d6-baf6-5bc4ac0ae173@linux.dev>
References: <20261124062625.264148-1-jiayuan.chen@linux.dev>
 <179558800299.3135.4905748131998876050@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="134175"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VxeyG1/P52ncigyfT071k1dfbxU= sha256:2Ex4D94+0KsNy3qokkbZx6YR7n2v2EfjNIhDEChvlwQ=
	sha1:Y0C0gvNxDrzGR1Ehf8XaygigslU= sha256:orsQQuKQN0UiXpjAiYukvDac0BJJMZ96VQItsmk2XU0=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 5E017125E3F; Wed, 25 Nov 2026 09:37:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.05
X-Spam-Status: No, score=-2.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	HK_RANDOM_FROM=1, 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 (1024-bit key)
	header.d=linux.dev
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 akUWsO7iqMjm;
	Wed, 25 Nov 2026 09:37:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-371072-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id C6643125E3D; Wed, 25 Nov 2026 09:37:24 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 4180C2F3AF; Wed, 25 Nov 2026 06:37:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795588642;
	b=HyEmoUvaXMNDhFw/1Mi0t71VKTX+isLajwHNMBLNVwVXG0qCMqpJsCnUKMXZ+dV4EOGE
	 ZPw00tkhcw4q2PYSihzhGk7TNoCqCddp+zpnYPlSi30n0KZZ+TSlyCD/PkMaFMhF2ny4R
	 LQFnJM5X4N8qOOLAxUjIMNPsaLIaKGN1rMB8dbU722O20NWj/Rz4Qn299wpS/LJPUIv2p
	 ssf6YecA6u5hUeFLUWA0CuI7HnmurPpK12ftad21ypRgbLpLYTNvTJQwZLafETZU0T0F/
	 DclnQjDFoVfQjXSDiFnSbUh3/tX77MxI7SZgFgBRsVZOZ5cw0q+DKXcLic/N0vOzyNw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795588642;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=q/Rj58SaH5amWTyNmer9CsZ6IqXDXPNCk/zSC3unopI=;
	b=qGdkJgT6VRQ9L31q2DKwFOLbYIa5K3Zkpn93nPmtM18yuYv32hbOQLIJEMwse/fCTJL6
	 Kpi9SFk6arD1j9necGgbuB6xnITBED3CD/MjfDVvDlUWQeEsnkGAS5Tk2Sne6CnSwVPjN
	 5rarZNhESBC2oJR55HSUnPNpbGnNLF8X3tTGvxYCp/QkJSaGZhfijX6TF1RNfVKD0o/GX
	 cg2hPQ/AbV3YT7xEVYPhZi0veLXJhrMixIJk70NLKiJOLFkRiQua9cY/pwYIXGfp+a7CI
	 /WN8mVhFTVRe/ZJA0/THTDfJI2143ynCQ6bpdJtSdsOMNfBbrJHZBNzr6HKCNoFpjNw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=q5d6DVJR;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FA37606A334;
	Wed, 25 Nov 2026 06:37:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=q5d6DVJR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.109
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795588641;
	b=FQN98xYP9fhDRMpUYDnLm6mroE55z2PIbE0BTN2e/4TFukIAix8emIMVr27QvVkPF/uv
	 d4vax0PZFbh/Nxcr87MRzY75qv0RuaXTf9oLig35h4xUVExu4Fb1iENyetJhLdrMMSuw4
	 mj2Xrz2GvFlCkUa1wmPiM39F+f24oIjHjPnFu3N9Euywo0DX5omd/jdqaUCyTIorZ413E
	 WPLPhcBU5BkWdWKL00iNIA+E6yB0pOkCHbGV1yibDSGmYGBGfYuOGXWCz7UoQvVCFwSdW
	 drj5UyHVKSCZs7eISCYGzAnmdKhMCeO5BDCmykNN9gjygVEtHSFzGAumMv6fBWzDu8Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795588641;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=q/Rj58SaH5amWTyNmer9CsZ6IqXDXPNCk/zSC3unopI=;
	b=FrIz+dfuA1z2qetJNblXaIDAp9qkB790FUbkSEQWresoAHqkAU9lm5ZAwUSP3dfyP8bi
	 VwwI19JgTR8/4uDxgabdERLAMaskOqhGtzfC5je153QAa8h2+D7qSEazV9pvrV3p/k7XS
	 q4nLBC0xtYnC4sBKKFInXUrerey3heBHIz312lRvrsd7Fd69qG7cB+gNMF4BgmXRyqHCY
	 yl/xfXBQRnSrLlpjPTG/So5SfZI5CK7EGn0WOjcPtLWRi4q0AG0+34pmS2OSQ3HTUkIkB
	 NAZnKAz2Cg+I/1aMBbnuinGIPtIQkQR5DPgB4JF8j/TUJKk2vyg85579TD1Bfj/TzlQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=q5d6DVJR;
	arc=none smtp.remote-ip=91.218.175.109
X-Received: from mta0.migadu.com (out-109.mta0.migadu.com [91.218.175.109])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95E4A606A323
	for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 06:37:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 95E4A606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=Rue6WWUDqbUiDGZQOImbpN9tuORsHUiNUGcW6y17oMA=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795588638; v=1; x=1796193438;
 b=q5d6DVJRa8oAnf8vyrkzerITtkrT4wiX6G9nDh5BbJ4elSbjbcPOb0p1hagSUsbbtuAP9WWg
 +UxdMf+FdxYmKXg94zEJq2QJAiTTQdQ9Pzo3JqHN9hEZdkmjAu3uIzjd3UJWINIXtyEKktd3pqJ
 qQg7xqQdikA3H7se/iDAORhE=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 52e2bc64e5274c4c;
	Wed, 25 Nov 2026 06:37:17 +0000
X-Mizu-Trace-ID: 52e2bc64e5274c4c
X-Migadu-Flow: FLOW_OUT
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: netdev@vger.kernel.org, edumazet@kernel.org, ncardwell@google.com,
 kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, fw@strlen.de, daniel@iogearbox.net,
 linux-kernel@vger.kernel.org, bpf@vger.kernel.org
X-In-Reply-To: <179558800299.3135.4905748131998876050@kernel.org>