From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796439937; b=ojeBoaPYEGgbJDBd6E1vEjq1jMy3Zgu4FbOGXSaL0PzZ8lOXw/7oqZRpXLRFSHT3rHgx K+BNeQqRUt9a0yxoMzgdwQIiy3KavB4Gu3tEFTPr4LvantSVNxWAZoFcRKPuUlRqYHInO iaPJ0mFhr04kObSW5bYfOyeuHtjbX4GDA+qoKkDFa+r8aqfCHO0eEOLFZiANoRkk+wfuB hZRgLjXmUsKwTmE0Z+3bUQR+HFYzcg/X7md4a8kIm7otPmRGwI2t2qUywn3k0dEYcnqCU QJeFjvAIAQblbKPZCDrbU2lM7CxEQFsMYeU+oj5dcz2l+tI0c87UJD00V4UpvTG9fCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796439937; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=HrP7AvY4c/hrL1LtkE1+Bt1mSn2C5jxe2w96c6qBYwc=; b=fRJa4y28+o7wDicSujSV+2Er1LQd31GRTXlmbuVBO3z9EcIECfnRxbfirHel+wYavxZd 29Iphzwpc8Eavt9QEH2wluOsK9gEV5ot6OAIya1KKGhx8Adp0/xuNEILQCq5zoPOQaT/k ORvJAS30Lt/iE65zV0SxBAfOW3MyFMK2ymBXweVRoQBhRFpQX5VObZ5CJ1VF9NhmM0faE ZX42bqEK4gHDaoM73UkvrD987ps+kApEJfERPjc9lqK3XD4ccJrIDJNJTFPr3y/XORy82 pX0wWmyiOMuNSB6b7MAmoJ7Q831QK0kOTE87BbZqp12yeSzi9f33/LKuF2RkdKDFqsg== 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="aWa/iydr"; arc=none smtp.remote-ip=100.103.45.18 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)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 949C0606A335; Sat, 5 Dec 2026 03:05:37 +0000 (UTC) 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=aWa/iydr Received: by smtp.kernel.org (Postfix) with ESMTPSA id E53DD1F00936; Sat, 5 Dec 2026 03:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796439937; bh=HrP7AvY4c/hrL1LtkE1+Bt1mSn2C5jxe2w96c6qBYwc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=aWa/iydr0lisLitgd5tnyZcoX3LAbgyAvPq2tBZlMP59L/7DOTqkUj377OgIEGbpa XWrPJNwlt13hYL1ocs15oaLqhLkjTswlmt/vsBudbIqoyD02OhzdZ9a2NlgxiF/UvM 1IkeOlHheByeTt2/p1NoS9L7Xp4xOt+xLvKnjQ7wxMB04mFzBElA29jWSE0wAcGxBu ck0eZI4DXFlIAVmJpPJ8KFozOrsyLYV4wWFWYeEXHL0sA6+uxdSftJXz7gjA5i3X9O gOHiwnJa4O8mnf90XR+d37+shL27MobYwVl9gR09cESAujD+MhiyHCBJ7qq++HqYGR PI6UELC0g1A5A== Subject: Re: [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() 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 Date: Sat, 05 Dec 2026 03:05:36 +0000 Message-ID: <179643993645.3146.654080921540306554@kernel.org> In-Reply-To: <20261204022245.381-3-chenaibing@cmss.chinamobile.com> References: <20261204022245.381-3-chenaibing@cmss.chinamobile.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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: stable@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/d83709308a038467b3a4849d814978b84328d2bc.camel@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/6f68f3e15dcbe159ccb4503f27329de05c125047.camel@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/20261204022245.381-1-chenaibing%40cmss.chinamobile.com