Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: chenaibing@cmss.chinamobile.com
Cc: achender@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check()
Date: Thu, 03 Dec 2026 03:38:08 +0000	[thread overview]
Message-ID: <179626908850.3146.14670637682082504192@kernel.org> (raw)
In-Reply-To: <20261202024054.1945-2-chenaibing@cmss.chinamobile.com>

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] rds_trans_get_preferred() (net/rds/transport.c) now takes the
  transport's module reference with try_module_get(), drops…

--

net/rds: drop rds_trans_sem around laddr_check()

This commit changes rds_trans_get_preferred() so that it takes the module
reference for each candidate transport while holding rds_trans_sem. It then
drops the semaphore before calling ->laddr_check(). The goal is to break a
lockdep-reported circular dependency between rds_trans_sem and rdma_cm's
handler_mutex.

Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/

> diff --git a/net/rds/transport.c b/net/rds/transport.c
> index f8001ec808671..904b9351e7613 100644
> --- a/net/rds/transport.c
> +++ b/net/rds/transport.c

[ ... ]

> @@ -101,15 +100,26 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
>  	for (i = 0; i < RDS_TRANS_COUNT; i++) {
>  		trans = transports[i];
>  
> -		if (trans && (trans->laddr_check(net, addr, scope_id) == 0) &&
> -		    (!trans->t_owner || try_module_get(trans->t_owner))) {
> -			ret = trans;
> -			break;
> -		}
> +		if (!trans ||
> +		    (trans->t_owner && !try_module_get(trans->t_owner)))
> +			continue;
> +
> +		/*
> +		 * ->laddr_check() may create and destroy an rdma_cm id, which
> +		 * takes rdma_cm's handler_mutex.  Don't hold rds_trans_sem
> +		 * across it: the module reference keeps trans alive.
> +		 */
> +		up_read(&rds_trans_sem);
> +
> +		if (trans->laddr_check(net, addr, scope_id) == 0)
> +			return trans;

[Severity: Medium]
Does the module reference keep trans and ->laddr_check() alive while
rds_rdma is still in MODULE_STATE_COMING? The commit message says:

  "The module reference keeps the transport and its callback alive"

However, try_module_get() only refuses modules that are in
MODULE_STATE_GOING:

include/linux/module.h:module_is_live() {
	return mod->state != MODULE_STATE_GOING;
}

rds_ib_init() publishes rds_ib_transport through rds_trans_register() during
module init. rds_rdma_init() can still fail after that point:

net/rds/rdma_transport.c:rds_rdma_init() {
    ...
	ret = rds_ib_init();
	if (ret)
		goto out;

	ret = rds_rdma_listen_init();
	if (ret)
		rds_ib_exit();
    ...
}

rds_rdma_listen_init() can fail with -ENOMEM from rdma_create_id(). It can
also fail if rdma_bind_addr() or rdma_listen() fails, for example when
RDS_PORT is already bound in RDMA_PS_TCP.

On that failure, do_init_module() frees the module and does not wait for
references taken by try_module_get() during COMING:

kernel/module/main.c:do_init_module() {
    ...
fail:
	mod->state = MODULE_STATE_GOING;
	synchronize_rcu();
	module_put(mod);
    ...
	free_module(mod);
}

Before this patch, laddr_check ran under down_read(&rds_trans_sem). The
down_write() in rds_trans_unregister() therefore waited for it to finish.
Now that the semaphore is dropped, can this interleaving happen?

CPU1 (unprivileged, bind() on AF_RDS without SO_RDS_TRANSPORT)
rds_bind()->rds_trans_get_preferred()
    try_module_get(trans->t_owner)    /* succeeds in COMING */
    up_read(&rds_trans_sem);
    trans->laddr_check()              /* rds_ib_laddr_check() */

CPU2
rds_rdma_init()
    rds_rdma_listen_init()            /* fails */
    rds_ib_exit()
        rds_trans_unregister()        /* down_write no longer waits */
do_init_module() fail path
    free_module()

In that case CPU1 would run freed module text and touch freed module data,
such as rds_ib_devices and rds_rdma_cm_event_handler.

The follow-up patch in this series, "net/rds: defer the probe cm_id destroy
to rds_wq", seems to make the window larger. With that patch,
rds_ib_laddr_check_cm() queues module text on rds.ko's workqueue:

	INIT_WORK(&pw->work, rds_ib_probe_work_fn);
	pw->cm_id = cm_id;
	queue_work(rds_wq, &pw->work);

rds_ib_exit() flushes that workqueue right after unregistering:

	rds_trans_unregister(&rds_ib_transport);
	...
	flush_workqueue(rds_wq);

A probe that is still running in the window above can queue its work after
that flush. rds_wq belongs to rds.ko and outlives rds_rdma. Could
rds_ib_probe_work_fn() then run after rds_rdma has been freed? It would also
be touching rds_ib_probe_pending.

> +
> +		rds_trans_put(trans);
> +		down_read(&rds_trans_sem);
>  	}
>  	up_read(&rds_trans_sem);
>  
> -	return ret;
> +	return NULL;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202024054.1945-1-chenaibing%40cmss.chinamobile.com

  reply	other threads:[~2026-12-03  3:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  2:40 [PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering Aibing Chen
2026-12-02  2:40 ` [PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-03  3:38   ` netdev-bot+sashiko [this message]
2026-12-02  2:40 ` [PATCH net v6 2/2] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-03  3:38   ` netdev-bot+sashiko

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=179626908850.3146.14670637682082504192@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=achender@kernel.org \
    --cc=chenaibing@cmss.chinamobile.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@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