Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 (1) · Medium: 2 · 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] This patch carries `Cc: stab…@vger.kernel.org` and `Fixes: ec16227e1414` ("RDS/IB: Infiniband transport"), which covers every… - [Medium] net/rds: unaddressed v6 maintainer CR to avoid rds_trans_get_preferred() Pre-existing issues: - [High] This problem wasn't introduced by this patch, but it is in the direct caller of the modified function and it is reachable without… -- net/rds: drop rds_trans_sem around laddr_check() This patch changes rds_trans_get_preferred() so that it takes the transport module reference under rds_trans_sem, drops the semaphore and only then calls ->laddr_check(). This avoids a lockdep-reported dependency between rds_trans_sem and rdma_cm's handler_mutex. A transport that fails its check is put and the scan continues. Link: https://lore.kernel.org/all/d837…@kernel.org/
> diff --git a/net/rds/transport.c b/net/rds/transport.c > index f8001ec808671..4e667580f8739 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 an rdma_cm id and take > + * 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] Allison's review of v6 asked for a different approach to this bug: https://lore.kernel.org/r/6f68…@kernel.org That reply was marked pw-bot: cr. It suggested replacing the series with a single patch that adds a direct local-address helper, rds_conn_addr_is_local(), and uses it in __rds_conn_create() instead of calling rds_trans_get_preferred(). v7 keeps the three-patch approach. Neither the changelog nor the cover letter seems to say why the change request was not adopted. In __rds_conn_create(), the result of rds_trans_get_preferred() is only used as a boolean: net/rds/connection.c:__rds_conn_create() { ... loop_trans = rds_trans_get_preferred(net, faddr, conn->c_dev_if); if (loop_trans) { rds_trans_put(loop_trans); conn->c_loopback = 1; ... } That is also the only place where rds_trans_sem is taken, or rds_ib_laddr_check() is called, with rdma_cm's handler_mutex held. The path is rds_ib_cm_handle_connect() -> rds_conn_create(). The other caller, rds_bind(), runs from syscall context without handler_mutex. Local IB, IPoIB and RoCE addresses are ordinary local interface addresses. So __rds_conn_create() could check faddr directly with inet_addr_type() == RTN_LOCAL and ipv6_chk_addr(). That removes both the handler_mutex -> rds_trans_sem dependency and the handler_mutex -> probe rdma_destroy_id() dependency. With that change, none of the following would be needed: - dropping and retaking rds_trans_sem around ->laddr_check() here - reordering the IB transport registration - deferring the probe cm_id destroy to rds_wq with a 64-entry pending cap, as patch 3 does Dropping the semaphore in this loop is also what creates the stable ordering dependency raised above. Was the v6 suggestion considered and rejected for a technical reason? If so, could the changelog explain it? If not, would a respin along the lines Allison proposed be simpler and easier to backport? [Severity: Medium] Is this safe in the stable trees this patch is tagged for? The commit message says: The transport is only registered once rds_rdma_init() can no longer fail, so the reference cannot be taken on a module that is about to be freed. That is true in mainline. There, rds_rdma_init() calls rds_trans_register(&rds_ib_transport) only after rds_rdma_listen_init() succeeds. That ordering seems to come from the earlier commit "net/rds: register the IB transport last". That commit has no Fixes: or Cc: stable tag, and this patch doesn't list it as a stable prerequisite. With Fixes: ec16227e1414 and Cc: stable, this patch would go back to trees where rds_ib_init() still registers the transport before rds_rdma_listen_init(). That function can fail and call rds_ib_exit(). Before this patch, ->laddr_check() ran under down_read(&rds_trans_sem). That meant rds_trans_unregister()'s down_write() in the failed init path had to wait for it. Now try_module_get() succeeds on a module in MODULE_STATE_COMING, and do_init_module() frees a module whose init failed regardless of its refcount: CPU1 (bind) CPU2 (modprobe rds_rdma) rds_trans_get_preferred() try_module_get(trans->t_owner) up_read(&rds_trans_sem) rds_rdma_listen_init() fails rds_ib_exit() rds_trans_unregister() do_init_module() frees the module trans->laddr_check() or rds_trans_put(trans) Could this run rds_ib_laddr_check() from freed module text, or call module_put() on a freed struct module? The baseline already had a related problem: a successful bind leaves rs->rs_transport pointing into the freed module. The prerequisite commit fixes that as well. Would it make sense to tag "net/rds: register the IB transport last" with Fixes: and Cc: stable, or to list it as a prerequisite in this patch's stable tag?
> + > + rds_trans_put(trans); > + down_read(&rds_trans_sem); > } > up_read(&rds_trans_sem); > > - return ret; > + return NULL; > }
[Severity: High] This is a pre-existing issue and wasn't introduced by this patch. It is in the direct caller of rds_trans_get_preferred(), though. Does rds_bind() leak the transport module reference when rds_add_bound() fails? net/rds/bind.c:rds_bind() { ... } else { trans = rds_trans_get_preferred(sock_net(sock->sk), binding_addr, scope_id); ... rs->rs_transport = trans; } sock_set_flag(sk, SOCK_RCU_FREE); ret = rds_add_bound(rs, binding_addr, &port, scope_id); if (ret) rs->rs_transport = NULL; ... } The reference may come from rds_trans_get_preferred(), or from rds_trans_get() when SO_RDS_TRANSPORT was set earlier. Either way it is dropped by clearing the pointer, with no call to rds_trans_put(trans). rds_release() later calls rds_trans_put(rs->rs_transport) on NULL, so module_put() never happens. Because rs_transport is reset to NULL, this check in rds_set_transport() no longer stops SO_RDS_TRANSPORT from being set again on the same socket: if (rs->rs_transport) return -EOPNOTSUPP; /* previously attached to transport */ An unprivileged user can bind one RDS socket to an addr:port and then call bind() over and over on a second socket with the same addr:port. Each -EADDRINUSE from rds_add_bound() leaks one reference on rds_tcp or rds_rdma. Besides making the module impossible to unload, this can wrap struct module::refcnt, which is an unsaturated atomic_t, after around 2^32 leaks. Once the count reaches 0, try_module_get() fails and rds_trans_get_preferred() returns NULL for every caller. This looks to have been present since commit 05733434ee9a. Should the failure path call rds_trans_put(trans) before clearing rs->rs_transport?
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40cmss.chinamobile.com