All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Allison Henderson" <achender@kernel.org>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH net-next v2 4/9] net/rds: wait for connections to be freed on transport unload
Date: Sun, 13 Sep 2026 03:50:41 +0000	[thread overview]
Message-ID: <20260913035041.68CEE1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260912035027.27447-5-achender@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Repeatedly calling `rds_ib_destroy_nodev_conns` as a resweep callback causes list corruption and an infinite loop because `list_splice` does not reinitialize the list head.
--

commit 597676df37a14231916bc15aaa2d2b879b415a67
Author: Sharath Srinivasan <sharath.srinivasan@oracle.com>

net/rds: wait for connections to be freed on transport unload

This patch tracks the number of live connections per transport and adds a
polling wait loop on transport unload to ensure all connections are fully
destroyed before the module exits. It also provides a resweep callback for
transports like IB that detach asynchronously.

> diff --git a/net/rds/connection.c b/net/rds/connection.c
> --- a/net/rds/connection.c
> +++ b/net/rds/connection.c
[ ... ]
> @@ -591,7 +596,51 @@ static void rds_conn_destroy_fini(struct kref *kref)
[ ... ]
> +void rds_conn_wait_conns_freed(struct rds_transport *trans,
> +			       void (*resweep)(void))
> +{
> +	unsigned long warn_interval =
> +			msecs_to_jiffies(RDS_CONN_FREE_WARN_INTERVAL_MS);
> +	unsigned long warn_at = jiffies + warn_interval;
> +
> +	while (!wait_event_timeout(rds_conn_freed_waitq,
> +				   !atomic_read(&trans->t_conn_count),
> +				   msecs_to_jiffies(RDS_CONN_FREE_POLL_MS))) {
> +		/* A transport whose teardown is asynchronous (IB moves a
> +		 * connection off its device from the shutdown work) gives
> +		 * us a resweep to destroy what has arrived since.
> +		 */
> +		if (resweep)
> +			resweep();
> +		if (time_after_eq(jiffies, warn_at)) {
[ ... ]
> diff --git a/net/rds/ib.c b/net/rds/ib.c
> --- a/net/rds/ib.c
> +++ b/net/rds/ib.c
[ ... ]
> @@ -537,7 +537,24 @@ void rds_ib_exit(void)
[ ... ]
> +	/* rds_ib_dev_shutdown() only dropped the connections still
> +	 * attached to a device; each moves itself to ib_nodev_conns
> +	 * from its shutdown work.  Destroy what is there now and keep
> +	 * sweeping the list while the wait sees connections outstanding,
> +	 * so a late arrival is destroyed rather than waited on forever.
> +	 */
>  	rds_ib_destroy_nodev_conns();
> +	rds_conn_wait_conns_freed(&rds_ib_transport,
> +				  rds_ib_destroy_nodev_conns);

[Severity: High]
Can this lead to list corruption if rds_ib_destroy_nodev_conns() is called
multiple times?

The new polling loop in rds_conn_wait_conns_freed() will repeatedly call the
resweep function if the transport connection count is greater than zero.

Looking at rds_ib_destroy_nodev_conns() in net/rds/ib_rdma.c, it uses
list_splice() without reinitializing the original list:

net/rds/ib_rdma.c:rds_ib_destroy_nodev_conns() {
    ...
    spin_lock_irq(&ib_nodev_conns_lock);
    list_splice(&ib_nodev_conns, &tmp_list);
    spin_unlock_irq(&ib_nodev_conns_lock);
    ...
}

Because list_splice() leaves the ib_nodev_conns head pointing to elements
that are then moved to tmp_list and freed, a second call to this function
during the wait loop will evaluate list_empty() as false and execute
__list_splice() with stale pointers.

This can result in a use-after-free write to the prev and next fields of
freed memory.

Could this use list_splice_init() instead so the list head is safely
emptied for subsequent polling iterations?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912035027.27447-1-achender@kernel.org?part=4

  reply	other threads:[~2026-09-13  3:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12  3:50 [PATCH net-next v2 0/9] net/rds: make connection lifetime reference-counted Allison Henderson
2026-09-12  3:50 ` [PATCH net-next v2 1/9] net/rds: guard every work-requeueing site with rds_destroy_pending() Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 2/9] net/rds: make rds_destroy_pending() cover single-connection destroy Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 3/9] net/rds: split connection destroy into quiesce and kref-governed free Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 4/9] net/rds: wait for connections to be freed on transport unload Allison Henderson
2026-09-13  3:50   ` sashiko-bot [this message]
2026-09-12  3:50 ` [PATCH net-next v2 5/9] net/rds: unlink transport nodes before a possibly deferred connection free Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 6/9] net/rds: hold connection references in lookup, sockets and c_passive Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 7/9] net/rds: pin the connection across RDMA-CM event handling Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 8/9] net/rds: drop rds_conn_count in favor of t_conn_count Allison Henderson
2026-09-13  3:50   ` sashiko-bot
2026-09-12  3:50 ` [PATCH net-next v2 9/9] net/rds: hold a connection reference from struct rds_incoming Allison Henderson
2026-09-13  3:50   ` sashiko-bot

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=20260913035041.68CEE1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=achender@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.