🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26508

Re: [PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering

#26508
From: Allison Henderson
Date: Thu, 03 Dec 2026 16:40
153 lines
13907 bytes
On Wed, 2026-12-02 at 10:40 +0800, Aibing Chen wrote:
> syzbot reported a circular locking dependency between rds_trans_sem and
> rdma_cm's handler_mutex:
> 
>   CPU0 (passive connection)          CPU1 (bind)
>   ----                               ----
>   mutex_lock(&handler_mutex)         down_read(&rds_trans_sem)
>   rds_ib_cm_handle_connect()         rds_ib_laddr_check()
>     rds_conn_create()                  rdma_destroy_id()
>       rds_trans_get_preferred()          mutex_lock(&handler_mutex)
>         down_read(&rds_trans_sem)
> 
> Patch 1 fixes the cycle the way the review asked for: take the module
> reference for the candidate transport under rds_trans_sem, drop the
> semaphore, and only then call ->laddr_check().
> 
> Running that on a two-node rxe setup showed one more problem on the same
> path, which patch 2 fixes: when ->laddr_check() runs from the passive
> connection path, cma_ib_req_handler() already holds the listener's
> handler_mutex, and rds_ib_laddr_check() creates and destroys a probe
> cm_id whose rdma_destroy_id() takes the handler mutex of the probe id.
> Both are instances of the same lock class, so lockdep reports a
> recursive locking dependency.  Destroy the probe id from rds_wq, where
> neither lock is held.

Hi Aibing,

Thanks for the follow up and the rxe testing.  The sashiko findings on
both patches are valid, but I think we're getting closer, and I think your
testing points at a simpler fix.  Both reports come from the same call of
__rds_conn_create() calling rds_trans_get_preferred() from inside an
rdma_cm handler.  But all we really need it for here is deciding whether
faddr is local.  So I think if we just hoist that logic out of
rds_trans_get_preferred() and make a helper that checks directly instead
of asking the transports, then both reports go away.  Something like:

#include  <net/route.h> 

...

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;
} 

and then in __rds_conn_create():

-       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;


That should get us the same check rds_tcp_laddr_check() does, but without
taking rds_trans_sem under handler_mutex.  So if we do this, we would only
need this one patch in place of the other two.  Please re-run your rxe
setup with lockdep, ideally with active and passive connections, plus a
bind() to an address that isn't on an RDMA device.

Also cc'ing stable is fine since this is pretty small, but we should leave
a note for stable maintainers below the --- that stable trees where IPv6 can
still be a module would need "depends on IPV6 || !IPV6" on  CONFIG_RDS since
this fix uses ipv6_chk_addr().

Thanks again for working on this!
Allison

pw-bot: cr


> 
> Evidence, both nodes on a PROVE_LOCKING kernel, rxe0 on each node, an RDS
> connection established and then a bind() to an address that is not on an
> RDMA device (which is what reaches rds_ib_laddr_check_cm()):
> 
>   mainline:  WARNING: possible circular locking dependency detected
>              rds_trans_sem --> &id_priv->handler_mutex
>                            --> &id_priv->handler_mutex/1
>              ... rdma_destroy_id <- rds_ib_laddr_check
>                  <- rds_trans_get_preferred <- rds_bind
>                  and down_read(rds_trans_sem) <- rds_trans_get_preferred
>                  <- __rds_conn_create
> 
>   this series: no lockdep report at all in the same run.
> 
> I could not run syzbot's reproducer; the setup above is a hand-made
> equivalent.  No runtime testing on real RDMA hardware was done, so the
> patches are compile tested (W=1) and tested on rxe only.
> 
> v6:
> - add patch 2: the ordering fix alone still leaves the probe cm_id
>   destroy nested under the CM handler's mutex, which lockdep reports as
>   recursive locking once the semaphore cycle is gone.
> - patch 2 fails the address check with -ENOMEM above the bound instead
>   of returning -EAGAIN, so rds_trans_get_preferred() cannot fall back to
>   another transport.
> 
> v5:
> - implement the ordering fix in rds_trans_get_preferred() as requested
>   in the review (dropping the net/rds/ib.c workqueue, the global cap and
>   the rds_wq flush of v4) and describe the report as a lock class
>   conflict rather than a deadlock.
> 
> v4 and earlier:
> - deferred rdma_destroy_id() to a workqueue and bounded the backlog.
> 
> Reported-by: syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
> Suggested-by: Allison Henderson <achender@kernel.org>
> Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/
> Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
> 
> Aibing Chen (2):
>   net/rds: drop rds_trans_sem around laddr_check()
>   net/rds: defer the probe cm_id destroy to rds_wq
> 
>  net/rds/ib.c        | 50 +++++++++++++++++++++++++++++++++++++++++++++++--
>  net/rds/transport.c | 24 +++++++++++++++-------
>  2 files changed, 67 insertions(+), 7 deletions(-)
> 
Technical Details
Message-ID: <6f68f3e15dcbe159ccb4503f27329de05c125047.camel@kernel.org>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376762-linux-kernel-netdev=dewy.ru
References: <20261202024054.1945-1-chenaibing@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376762-linux-kernel-netdev=dewy.ru
From: achender@kernel.org (Allison Henderson)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering
Date: Thu, 03 Dec 2026 09:40:43 -0700
Organization: Usenet Network
Message-ID: <6f68f3e15dcbe159ccb4503f27329de05c125047.camel@kernel.org>
References: <20261202024054.1945-1-chenaibing@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2543751"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+SK74hEYyMXd3K8X2BlVE5fLQls= sha256:fMzdccPmLeD1SLnQ4E+ESFTCbchT/g/HOMkJ6fvlFd4=
	sha1:nvSR9YbS8zjoFQQ6al1yRsW/p1Y= sha256:koJIJXi3HMbOJEv7fSvDrtqOFXOz+4oRcWegwCdpBEE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1D3311179D5; Thu,  3 Dec 2026 19:41:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.74
X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id cj3rRQuOocUI;
	Thu,  3 Dec 2026 19:41:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376762-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 604E91179CE; Thu,  3 Dec 2026 19:40:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id EBE57262A3; Thu,  3 Dec 2026 16:40:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796316050;
	b=cMOqg1TIBfSef+1nFU34Rw3eW9C01afBejdfuX+HUVONvc+YeLVCYQ3NFDMaaV7B2gUj
	 fBcyYDQHfA3w2goUYsQfxSAIdSICw98QHLIs8sY94JGfmP8eb3M2YUK/XUjBiK1IEgB35
	 7+5hz4x4CPulX6Tki+0I9qwlTXB3b2ZKm+s+33t9ZUNbZJeFkK5tKiMiGoSjtb8N6eeLA
	 7YtmVqlF7dUoyNMFiQcrUvxQIGyGzDMy0PvH8WfgCU2u1MmycsryG/GZ3E/TBt8LQ+Nsp
	 SHnRy5HNIaLN6gmP9bKw1CCefZ64fWeXA1B+OuITOtfDEYBvEaxeGcChxWwh8eFaU1Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796316050;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject:
	 From:To:Cc:Date:In-Reply-To:References:Content-Type:
	 Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version;
	bh=oWrPnRRLvhJCS9rph2zFiKa1U2EBOzSzBn6MwQHBtQU=;
	b=q04oItZJwI6mchG0IDfTFUZhiD2OQUSz8SMnL+FJAkrK/Z+465Kq47z2V06XV4sv8fL+
	 Biuhjl63IFYJ+4KjHQ33FhsVGGFYGL/RIO4htekFgmDLtLFBMIe7NK1GFdgkTTMNlvGqJ
	 wwX52jLlbrylyegDfjtEkdZmJzcRr1RfsfkJZjyRXZ+gD1GhMFPoIS8YjRTYNWm4MHGPj
	 BnL+58FaWc7XZOkIkwGkqP++uCJ/PKqXC5Ve6bmqArb3qx8s7l33vE2f9eFHJXBZHrVGV
	 TYtqbZoVN4lH9aAqMQNtchPPjgTqyTW3YOIbbvqLuoSu+rRgTENTshXaHw8R+V+eLdQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iZV+QxeO;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 90D16606A334;
	Thu,  3 Dec 2026 16:40:50 +0000 (UTC)
X-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=iZV+QxeO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796316044;
	b=OUp7gzpH73/Zifze37HW28vq+bAajXjPexnW+u+KlhqetNd7U4yoEzoe43Mc8kpb3/tN
	 t3TsWKXSdiIfpM/pgfiMfbnk/QrOeM2yX989wl2uWSXmCAKlSTppVfOLQozrouCg/U6Md
	 u/Vr3p8oEqPGNI+5B7Umat1Yqj5Rb6X+rVVvdV+q1RGDDmnPectCUunj4yv7sxd7O4o8v
	 wixd1sjlCgJOlqFgmujQY/E8JTg15WiCfOM9Td8DchgNy4BtOs8rwmsCCS2qwOvd4zVSF
	 RdRT6HLeyprPfMwdGwYHBDIKr5BgMOch3djCo6L9P8UIrcV25w5VfTroQJnKu0RR03A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796316044;
	h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date:
	 In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 User-Agent:MIME-Version;
	bh=oWrPnRRLvhJCS9rph2zFiKa1U2EBOzSzBn6MwQHBtQU=;
	b=Qz3ZTn8QQaWTh9Tr2Lvvir6d7Xr950hQou811tMirUA+83Q4HyIEvqG2zDhc6tZffH3+
	 VQ5jwCg/nFjXRSsLA4cc5hrFZ77WNqBPYqYRJBc98eCAKy7cvPi8tHNHXtFUwih/5c80O
	 tAqV+6ucCPil88Uz3zFcgGW9awqGUR81DUZKgvjAXNKNWXCIn6XVCh1QgkFdagXfmGc83
	 ha53Cs6YjUBbufHTXVqC5YtlX0H2CyshxFEV6cyZSAr3RKxx19gemWQS29+aBFKdTh2IH
	 oDeERtp7AgO/FW4Yq8UD4VoNf1frJC/Gazv8Bn8UhnuFAkYzwYJw7AKrFpcfklHBHOg==
X-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=iZV+QxeO;
	arc=none smtp.remote-ip=100.103.45.18
X-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 AD297606A322;
	Thu,  3 Dec 2026 16:40:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 024D91F000C1;
	Thu,  3 Dec 2026 16:40:43 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796316044;
	bh=oWrPnRRLvhJCS9rph2zFiKa1U2EBOzSzBn6MwQHBtQU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=iZV+QxeOhtJ4ITP18G3tbL1Pawp7bnUBTmbkPvZgeXLoQSBkap6Yt6pSsI8ijYrJ/
	 stRLXvH/S3sYWp0bSxUBpVWNJzABEanOJrkObsEyRnk9UJVRL8xKWuOkMm/iQYEsQn
	 c8uX8QYeeg5I8x2Zj2zKjEpEFU30EuoXQCwjqJa0RCOwRYf6A+dV2nmGekmSAb+oQZ
	 Z5atnTTVGlJBo2EJaa2HNtvg2rBdZbEl1mtkwWT527XalvhzYaJD0pRs4cmOe3VcXa
	 i03viEKr7N6MbR57f7c9o//Xr8JvJ/bXC5XFAHwlguVLxiu1ceXe6lH809aloS/4DA
	 33L/LsXEX/K0g==
X-Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261202024054.1945-1-chenaibing@cmss.chinamobile.com>
X-User-Agent: Evolution 3.52.3-0ubuntu1.1 
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list