[PATCH net v8] net/rds: check the loopback address directly
From: Aibing Chen
Date: Fri Dec 04 2026 - 05:40:11 EST
__rds_conn_create() decides whether a connection is loopback by calling
rds_trans_get_preferred() with the destination address. That runs from
the rdma_cm handler path, where cma_ib_req_handler() already holds
rdma_cm's handler_mutex, so the check either takes that mutex again
through the IB transport's ->laddr_check()/rdma_destroy_id() or holds
rds_trans_sem under it, which lockdep reports as circular or recursive
locking once a connection is established.
All the decision needs is whether the destination is a local address, so
check that directly instead of probing every transport: compare against
the loopback network for IPv4-mapped addresses, inet_addr_type() for
IPv4 and ipv6_chk_addr() for IPv6.
This is the same answer rds_tcp_laddr_check() gives, without taking any
transport lock in the rdma_cm handler context.
Reported-by: syzbot+ccdb5058c3df2d94811c@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <achender@xxxxxxxxxx>
Link: https://lore.kernel.org/all/6f68f3e15dcbe159ccb4503f27329de05c125047.camel@xxxxxxxxxx/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
Note for stable: this uses ipv6_chk_addr(), so stable trees where IPv6
can be built as a module need "depends on IPV6 || !IPV6" on CONFIG_RDS.
---
net/rds/connection.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/net/rds/connection.c b/net/rds/connection.c
index c752a8623..e4143907f 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -35,6 +35,7 @@
#include <linux/slab.h>
#include <linux/export.h>
#include <net/ipv6.h>
+#include <net/route.h>
#include <net/inet6_hashtables.h>
#include <net/addrconf.h>
@@ -169,6 +170,42 @@ static void __rds_conn_path_init(struct rds_connection *conn,
* For now they are not garbage collected once they're created. They
* are torn down as the module is removed, if ever.
*/
+/*
+ * Check whether addr is a local address without going through the
+ * transports: this runs from the rdma_cm handler path, where asking a
+ * transport's ->laddr_check() would take rdma_cm's handler_mutex again
+ * or call into RDS transports under rds_trans_sem.
+ */
+static bool rds_conn_addr_is_local(struct net *net,
+ const struct in6_addr *addr, int dev_if)
+{
+ bool ret = false;
+
+ if (ipv6_addr_v4mapped(addr)) {
+ if (*(u8 *)&addr->s6_addr32[3] == IN_LOOPBACKNET)
+ return true;
+ return inet_addr_type(net, addr->s6_addr32[3]) == RTN_LOCAL;
+ }
+
+ if (ipv6_addr_loopback(addr))
+ return true;
+
+#if IS_ENABLED(CONFIG_IPV6)
+ if (ipv6_mod_enabled()) {
+ struct net_device *dev = NULL;
+
+ rcu_read_lock();
+ if (dev_if)
+ dev = dev_get_by_index_rcu(net, dev_if);
+ if (!dev_if || dev)
+ ret = ipv6_chk_addr(net, addr, dev, 0);
+ rcu_read_unlock();
+ }
+#endif
+
+ return ret;
+}
+
static struct rds_connection *__rds_conn_create(struct net *net,
const struct in6_addr *laddr,
const struct in6_addr *faddr,
@@ -179,7 +216,6 @@ static struct rds_connection *__rds_conn_create(struct net *net,
{
struct rds_connection *conn, *parent = NULL;
struct hlist_head *head = rds_conn_bucket(laddr, faddr);
- struct rds_transport *loop_trans;
struct rds_conn_path *free_cp = NULL;
unsigned long flags;
int ret, i;
@@ -249,9 +285,7 @@ static struct rds_connection *__rds_conn_create(struct net *net,
* can bind to the destination address then we'd rather the messages
* flow through loopback rather than either transport.
*/
- loop_trans = rds_trans_get_preferred(net, faddr, conn->c_dev_if);
- if (loop_trans) {
- rds_trans_put(loop_trans);
+ if (rds_conn_addr_is_local(net, faddr, conn->c_dev_if)) {
conn->c_loopback = 1;
if (trans->t_prefer_loopback) {
if (likely(is_outgoing)) {