๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15568

Re: [PATCH net-next v11 08/12] net/rds: hold a connection reference from struct rds_incoming

#15568
From: Allison Henderson
Date: Fri, 13 Nov 2026 04:39
144 lines
13641 bytes
On Tue, 2026-11-10 at 13:57 +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0
> 
> 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] With this patch, every rds_incoming holds a reference on its
>   connection.
> 
> --
> 
> net/rds: hold a connection reference from struct rds_incoming
> 
> This patch makes every holder of rds_incoming->i_conn own a connection
> reference. The references are taken in rds_inc_init(), rds_inc_path_init(),
> rds_recv_incoming() and the three m_inc assignment sites in send.c. They
> are dropped from rds_inc_put() and from a new rds_message_free() helper,
> which fixes a use-after-free when a transport unload destroys a connection
> that queued incs still point at.
> 
> Closes: https://lore.kernel.org/netdev/20260720184955.3008978-1-nicoyip.dev@gmail.com/
> 
> [ ... ]
> 
> > diff --git a/net/rds/recv.c b/net/rds/recv.c
> > index 00ab60f2d9969..e4cae82c16818 100644
> > --- a/net/rds/recv.c
> > +++ b/net/rds/recv.c
> > @@ -46,6 +46,7 @@ void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn,
> >  {
> >  	refcount_set(&inc->i_refcount, 1);
> >  	INIT_LIST_HEAD(&inc->i_item);
> > +	rds_conn_get(conn);	/* put in rds_inc_put() */
> >  	inc->i_conn = conn;
> >  	inc->i_conn_path = NULL;
> >  	inc->i_saddr = *saddr;
> 
> [Severity: Medium]
> With this reference, an unread inc on a socket receive queue keeps its
> connection, and so the transport's t_conn_count, elevated until the
> application reads the datagram or closes the socket. Can that block
> rmmod of a transport forever?

Yes, but the the alternative to waiting is an unclean unload.  Without the
wait, the same sequence described above unloads rds_tcp with the inc still
queued.  Then the next rds_inc_put() calls conn->c_trans->inc_free, and for
an IB inc dereferences the freed connection which turns into a uaf.  So
waiting avoids the uaf and as well as a working unload.

Also the wait cannot be made interruptible/abortable in any way useful.
By the time rds_tcp_exit() runs, delete_module() has moved the module to
MODULE_STATE_GOING and the exit function has no way to fail. An early return
on a signal would unload over the live references, which is a UAF again.
If we purged the incs from the socket receive queues, it silently discards
datagrams that have been acknowledged to the peer from sockets nobody closed.ย 
Not discarding queued data is the one rule the teardown in this series follows
throughout, so I would rather keep it than add a drop path for a case that
today crashes.

Finally who controls the wait is not new.  The app owning the socket ends it by
reading or closing, or being killed by an admin. An unprivileged socket can
already keep the transport loaded for as long as it wants, and an rmmod simply
returns -EBUSY until the socket closes. The cross-transport case differs only in
that an inc holds no module reference, so the same hold shows up as a wait rather
than an immediate -EBUSY.

In any case, this complaint has come up a few times in prior reviews, and we've
added commentary around it as well as a warning that prints every 10 seconds.
I will send a v12 for the other sashiko reviews on patches 4 and 11, but I wanted
to explain why this review wouldnt be in it.

Thanks for the reviews!
Allison

> 
> rds_tcp_exit() and rds_ib_exit() both call rds_conn_wait_conns_freed().
> That loop exits only when t_conn_count reaches zero:
> 
> net/rds/connection.c:rds_conn_wait_conns_freed() {
>     ...
> 	while (!wait_event_timeout(rds_conn_freed_waitq,
> 				   !atomic_read(&trans->t_conn_count),
> 				   msecs_to_jiffies(RDS_CONN_FREE_POLL_MS))) {
>     ...
> }
> 
> The loop never checks for signals, so nobody can kill the rmmod task, and
> the module stays in MODULE_STATE_GOING. The task wakes every 100ms, so the
> hung-task detector doesn't report it either. The only sign is the pr_warn
> every 10 seconds.
> 
> rds_find_bound() matches only on address, port and scope_id. It doesn't
> compare rs->rs_transport with conn->c_trans. A socket bound with one
> transport (through SO_RDS_TRANSPORT or rds_trans_get_preferred()) can
> therefore queue incs that arrived over another transport's connection,
> without holding a module reference on that transport:
> 
>   unprivileged process: binds an RDS socket using IB, never reads it
>   remote peer: connects to the rds_tcp listener and sends to that port
>     rds_recv_incoming()->rds_find_bound() matches the IB-bound socket
>     the inc is queued on rs_recv_queue, holding a TCP conn reference
>   admin: rmmod rds_tcp
>     rds_tcp_exit()->rds_conn_wait_conns_freed() never returns
> 
> Before this patch, only the hash-table reference and short-lived
> references pinned a connection, so the wait added earlier in the series
> always finished.
> 
> The commit message says this is intended:
> 
>   "It also means the transport cannot unload while such a datagram is
>    unread ... That is the intended behaviour"
> 
> However, it lets an unprivileged application decide how long a privileged
> unload stays stuck. Could the unload path instead purge the departing
> transport's incs from socket receive queues? Or could the wait be made
> interruptible or abortable?
> 
> [ ... ]
> 
Technical Details
Message-ID: <8b6dcadbe3bad9ae0aa512c04f1aaf42755bd575.camel@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362410-linux-kernel-netdev=dewy.ru
References: <20261106031615.1047052-9-achender@kernel.org> <179431907345.994134.1298028433995703002@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362410-linux-kernel-netdev=dewy.ru
From: achender@kernel.org (Allison Henderson)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v11 08/12] net/rds: hold a connection reference
 from struct rds_incoming
Date: Thu, 12 Nov 2026 21:39:44 -0700
Organization: Usenet Network
Message-ID: <8b6dcadbe3bad9ae0aa512c04f1aaf42755bd575.camel@kernel.org>
References: <20261106031615.1047052-9-achender@kernel.org>
	 <179431907345.994134.1298028433995703002@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1266037"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:QPVZSu9DDBFmHzp3GMys2DeTjeI= sha256:CEPwSnrKHc04Dg/qupPRVpg0KLW+96TWoczyemdrWBA=
	sha1:fwBZuull3mrknRH3K71rn1b0+i8= sha256:WSrYDttuVgmyuigEzga+BesRGFXrCz2istvbaqFZkPE=
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 A01BC11447B; Fri, 13 Nov 2026 07:59:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 49rypolkVWjc;
	Fri, 13 Nov 2026 07:59:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-362410-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 970B5114464; Fri, 13 Nov 2026 07:59:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id EEBC761C075; Fri, 13 Nov 2026 04:39:47 +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=1794544786;
	b=dVewVmYdNlWzXq4mGkwsydG55Ys9F9j1aRGtMIkZLOqRsWkS21qyECLghQHiliu3wyGq
	 RAr1n5SMfPOJcOaVNFXddwBt5I3KpglwfVLcUdhq/UWHuuY/V6mw5RWpakIc3fbS2dmsX
	 Ir2bALHUWafMU4RjRu9ZUHqc7EbR2I/rhAP46ZZJfDZaww/6PRpvqXHmIMbdi+YjjzW6O
	 om+euPoyGwXiwEWaAlrfNhTMKVGXl5XH94jmIHngwkK6lyUCXxKp6N/zmO2tFjcclSnHQ
	 SvzbmoP0Gc2HAvqC3Tr36PChH4HE/W3Ako8l7kZU4/CIi4qEnCYHwAm+n20SyBtV7yw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794544786;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject:
	 From:To:Cc:Date:In-Reply-To:References:Content-Type:
	 Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version;
	bh=fXGKHVaiJkSmI+q7FxtmVVmezBLhB3VGu6cDO74aKuw=;
	b=DwXDGoYJPM0U4vzwviwl/n5HolQmPmhYK2SmWsJRFuu6mvP00g3qM+SvPpTytq+hy0ez
	 RMgPw8Ps7mzFG0YfthZo102vkluAN6OCFdJx//iyMML0+hC22Cu1MEzHVhcpq97D2SXrP
	 knUWcMIgRu9eRNwvdrJEKRqSSBH951VLLfNXjvUGNsi8S3pL0uiryaBn8YVqrSgUN2mhe
	 eI3efbi7Kl6vfoOLexgLpsW8UGg3Z7KFZlpHn3fMQdCs9CsbnYm22kQBoEZF/2EpwbLjC
	 rR9L8bUZsOqrF3jx6YjueiSOeOLM74n8kL4P3a/7Sao03Z9wyFhp4vUNIfD/zl4Rp3A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AkA62sIK;
	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 B7A4B606A331;
	Fri, 13 Nov 2026 04:39:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AkA62sIK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794544785;
	b=S3/KHMaYLMwl6Hmy0lQGFqU1nzzpF0dgm4yfIbbvYv1rf81BiRpUjvRV9zS5mZj7mWzY
	 NeKJZ/xjUAu73Mqi7T3sgTFpfuETxCtj2II2L3EuNvQXA/H7/WXiihHqUY06YZ1d/z2Lr
	 5fG+Pf69EfLSJaLQePkIbDPKo9t5vFISQysjyTiPgY9DvThBVznRjMjoPIcHL+3gQmd83
	 iApd5c9XrPL8Mw4j8cpF6G2aqTUQLvfnBpVrMYW/Gs1LW19X7FzGp+e8Eis4mnTjsJbdm
	 YOt2RVbDoPu4t3nJDLpz4k0W7pBQdgDmY6gmOMnXnmds0YX77h0mSTSVqADsv9m7nhw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794544785;
	h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date:
	 In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 User-Agent:MIME-Version;
	bh=fXGKHVaiJkSmI+q7FxtmVVmezBLhB3VGu6cDO74aKuw=;
	b=jKtJnh+ik86IoydjvvOZaD7OMWx1feYwChuVJg+kDISGaD8BtiWVUfTjY8KtVFYYABSy
	 VKvDJuAT+spsmRavIjzzjv31of2Pez/8enWQ2Bd8keeUeN2VdASbb5eTLYwutE3g/TENv
	 5KKpUIONSwKpXp88b3e/kbAGG6cENmpidV4nt4ZaFbhASIoDwcJxV3qZw6OOobZW5OMSR
	 Pm85EmCnfrhog/PIrlijoSQ4G9rycvDcAoymoGbGIz+Kys3mheN8YdMItopmZwHArPjpe
	 SUXBhvwPZOY1TcKNwyZWaib4QWFoDBjqy0tlP1XBiQYt6fPAQK76kZoDK8VkzUb5wxw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AkA62sIK;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D57B6606A31C;
	Fri, 13 Nov 2026 04:39:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D5611F000C4;
	Fri, 13 Nov 2026 04:39:45 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794544785;
	bh=fXGKHVaiJkSmI+q7FxtmVVmezBLhB3VGu6cDO74aKuw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=AkA62sIK9hFy/QIhwKyhnns3VeUMNfNRiFM/41Tr/DcvH19g9g9PHRbj5VYeAgl2m
	 k+11s15J1+bl7ztFpwx9UggJndE2OOBid+ZSpnGra+FV69BH61t48aDC9ngIqxGorG
	 CmGxMnEFIM7dbzxPy+ifq59XjvhqlHaYH+qrdceNoe2bNEAn2s0GL2xbbG9TvZa/dx
	 jcAXvcFM9Bw0oZ1dQ9YL/X7ChOVxONrXGMGEV3EP0U2JjUittYa2PB+E3yGO9Qu0uu
	 oKBOM4QDzkYFAYO3ub0u8gt6Dusqkpt9LRnyv7F9WDw+SLYGXEPthc18mvdFqnBsgL
	 76ZTRJo43lUlw==
X-Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, pabeni@redhat.com, 
	edumazet@google.com, kuba@kernel.org, horms@kernel.org
X-In-Reply-To: <179431907345.994134.1298028433995703002@kernel.org>
X-User-Agent: Evolution 3.52.3-0ubuntu1.1 
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