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=1795997872; b=i/x1/MKXmbWIsmtVPNsgIx5239iaItxDwlve0zj/44NMmdOMaL8FjVqrsMveIYIRvan5 Lqnsoy3lvaeGeNcXXT89r5LTPpqPYjcM2+clYV8LjvY1YIFNmbtmW9GojobgE5WZ5eC9h tpwCXG7ZgDqO6Uyi5aywCQyIl711E+HEZj4ZNT/UuItAU32YmLijNxIwmlht35hgd0NNE mJIy4I0aL1KRvkB5uoW9XYg2jqGPSMAb0Ej3UCy8P3K9NhV6Sy9ro2ZZzSRy/pgzK6XQT 6pL0L1rYLZyztY7rOY7i0p07OYpOHp0zWe16TY0tbXgbCIyGPuo81R76AoOB7DJ6cwQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795997872; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=6HnRw6kcT96XNupVBI4JBgRVe8oHf/0bT2HxDlw4yk4=; b=SLxBRrNkrWTAH56yW/dKOyBhd0yINcfA1IZOqJqWQpWFxM2D8AwK/HDY4Yi7Uu5NZ5mt 7e5aoM1m6cmzsaWE9X+ycjNCQUfpb7l+WMOWV+JI1qaVFkUbrk0jtSNuDETU/cDx+3fXb JBq9uo4XftEaSKdkJMhfpLpyeqdYLpdmajTbvUokySPdX1kikwZuiKHHTEFWP9KHWVFD8 fSogr6Qz+3Wi6OWoKJz8AUwk2JnN0rH629ePd1Wwe7qU4KJtp1lnJmBnJaQKxOKP/BHRY wLKFprPXZGb7PjSGx5QeEMF5sQs4p1SnUv6lCwRyySAlHmCFUylamy844OrMtceCVbA== 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=jzh6OSU+; 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 51C40606A31C; Mon, 30 Nov 2026 00:17:52 +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=jzh6OSU+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D880C1F000C1; Mon, 30 Nov 2026 00:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795997872; bh=6HnRw6kcT96XNupVBI4JBgRVe8oHf/0bT2HxDlw4yk4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jzh6OSU+KhGi14AZ86grdMAsUTUhijFm46FfRZbKbO+3tkKavcFNhwUETNKj3hfZ1 2Apv/LJgZQerpZgUaHnWOs29Jz2vE/uIziSj+f1WYqUfyWHGSvOiKZg0yandQV4RYj 48Is/4Pe2OOrn8iCYFyNm9+cTdyB7ZnJrhDisE+hxiAxHaf4leczLmp0PKT0ytZgrD 3UCG2676ib6MpIWoGa/B/LcRQOLL9TeUhrLxdCYdxnUsKvkYuPDnuvHg53dLNz39yc B4MVXj30pFEHmNUK28CZwinbYTUX7cCmjB6aVqashVE1cky/0tkPMl3PR2S355zTr8 nN+pm7U2jkZqQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net] net/smc: abort old connection when peer reuses RMB element Reply-To: sashiko-reviews@lists.linux.dev To: "Andrew Stellman" Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261129001734.78551-1-bugs@stellman-greene.com> References: <20261129001734.78551-1-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 00:17:51 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] net/smc: leak of lgr buffers and rkeys when smc_conn_kill() aborts conn - [Medium] net/smc: race in smc_listen_work() misses rtoken conflict before peer_rmbe_idx set - [Medium] net/smc: lockdep subclass and work-flush inversions in smc_rtoken_resolve_conflict() It also noticed 1 related pre-existing issue this patch does not introduce: - [Critical] net/smc: use-after-free in smc_conn_create() [1] -- commit 4e5079bdaa97283bcbcfcf6f66e253a14973ca98 Author: Andrew Stellman net/smc: abort old connection when peer reuses RMB element This commit aborts any existing SMC-R connection in a link group whose peer RMB rtoken and element index are reused by a later CLC handshake. > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > index a3164201c1420..cb45c36cdce66 100644 > --- a/net/smc/smc_core.c > +++ b/net/smc/smc_core.c [ ... ] > @@ -2024,6 +2024,7 @@ int smc_conn_create(struct smc_sock *smc, struct sm= c_init_info *ini) > spinlock_t *lgr_lock; > int rc =3D 0; > =20 > + conn->rtoken_idx =3D -1; > lgr_list =3D ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list : > &smc_lgr_list.list; > lgr_lock =3D ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock : [Severity: Critical] This problem wasn't introduced by this patch, but can smc_conn_create() hit= a use-after-free on lgr [1] when smc_lgr_register_conn() fails concurrently with link group teardown? CPU0 CPU1 smc_conn_create() smc_lgr_create() // lgr list refcnt =3D 1 smc_smcr_terminate_all() list_del_init(&lgr->list) __smc_lgr_terminate(lgr, false) write_lock_bh(&lgr->conns_lock) smc_lgr_register_conn() // fails write_unlock_bh(&lgr->conns_lock) read_lock_bh(&lgr->conns_lock) // 0 connections found read_unlock_bh(&lgr->conns_lock) smc_lgr_free(lgr) kfree(lgr) if (rc) smc_lgr_cleanup_early(lgr) <-- use-after-free smc_lgr_create() publishes lgr on lgr_list with only the list reference, and smc_conn_create() does not call smc_lgr_hold() until after smc_lgr_register_conn() succeeds: net/smc/smc_core.c:smc_conn_create() { ... if (ini->first_contact_local) { rc =3D smc_lgr_create(smc, ini); if (rc) goto out; lgr =3D conn->lgr; write_lock_bh(&lgr->conns_lock); rc =3D smc_lgr_register_conn(conn, true); write_unlock_bh(&lgr->conns_lock); if (rc) { smc_lgr_cleanup_early(lgr); goto out; } } ... } If teardown unlinks lgr while smc_lgr_register_conn() fails, __smc_lgr_terminate() sees an empty conns_all tree and frees lgr before smc_conn_create() runs smc_lgr_cleanup_early(lgr). > @@ -2757,6 +2758,42 @@ int smc_rtoken_delete(struct smc_link *lnk, __be32= nw_rkey) > return -ENOENT; > } > =20 > +/* Abort a connection if the peer reuses its RMB element for this handsh= ake. */ > +static void smc_rtoken_resolve_conflict(struct smc_connection *conn, u8 = rmbe_idx) > +{ > + struct smc_link_group *lgr =3D conn->lgr; > + struct smc_connection *old; > + struct smc_sock *old_smc; > + struct rb_node *node; > + > + for (;;) { > + read_lock_bh(&lgr->conns_lock); > + for (node =3D rb_first(&lgr->conns_all); node; node =3D rb_next(node))= { > + old =3D rb_entry(node, struct smc_connection, alert_node); > + if (old !=3D conn && !old->freed && > + old->rtoken_idx >=3D 0 && > + old->rtoken_idx =3D=3D conn->rtoken_idx && > + old->peer_rmbe_idx =3D=3D rmbe_idx) > + break; > + } [Severity: Medium] Can a concurrent server handshake on smc_hs_wq miss a conflicting connection here because peer_rmbe_idx is written only after smc_rmb_rtoken_handling() = and mutex_unlock(&smc_server_lgr_pending)? CPU0 (smc_listen_work #1) CPU1 (smc_listen_work #2) mutex_lock(&smc_server_lgr_pending) smc_listen_rdma_finish() smc_rmb_rtoken_handling() old->rtoken_idx =3D idx mutex_unlock(&smc_server_lgr_pending) mutex_lock(&smc_server_lgr_pending) smc_listen_rdma_finish() smc_rmb_rtoken_handling() smc_rtoken_resolve_conflict() old->peer_rmbe_idx =3D=3D rmbe_idx // still 0, no match smc_conn_save_peer_info() old->peer_rmbe_idx =3D rmbe_idx In smc_listen_work(), smc_listen_rdma_finish() sets new_smc->conn.rtoken_idx and smc_server_lgr_pending is released before smc_conn_save_peer_info() sto= res new_smc->conn.peer_rmbe_idx: net/smc/af_smc.c:smc_listen_work() { ... if (!ini->is_smcd) { rc =3D smc_listen_rdma_finish(new_smc, cclc, ini->first_contact_local, ini); if (rc) goto out_unlock; mutex_unlock(&smc_server_lgr_pending); } smc_conn_save_peer_info(new_smc, cclc); ... } Because the rbtree scan under lgr->conns_lock checks old->peer_rmbe_idx bef= ore taking old_smc->sk, the second server worker sees 0 instead of the 1-based rmbe_idx and leaves both connections sharing the same peer RMB element. > + if (!node) { > + read_unlock_bh(&lgr->conns_lock); > + return; > + } > + old_smc =3D container_of(old, struct smc_sock, conn); > + sock_hold(&old_smc->sk); > + read_unlock_bh(&lgr->conns_lock); > + > + lock_sock_nested(&old_smc->sk, SINGLE_DEPTH_NESTING); [Severity: Medium] Does locking old_smc->sk with SINGLE_DEPTH_NESTING and running smc_close_active_abort() while the caller still holds lock_sock() on the new socket invert the sk_lock-AF_SMC lockdep hierarchy and flush work items und= er the outer socket lock? CPU0 CPU1 ---- ---- lock_sock_nested(listen_sk, 1) lock_sock(new_sk) lock_sock(child_sk) lock_sock_nested(&old_smc->sk, 1) *** DEADLOCK *** CPU0: smc_release() -> __smc_release() -> smc_close_active() -> smc_close_cleanup_listen() -> smc_close_non_accepted() CPU1: smc_connect_rdma() / smc_listen_work() -> smc_rmb_rtoken_handling() -> smc_rtoken_resolve_conflict() In addition, smc_close_cancel_work(old_smc, true) and smc_clcsock_release() only release old_smc->sk (subclass 1) while the caller still holds the new socket lock (sk_lock-AF_SMC subclass 0) and smc_server_lgr_pending across cancel_work_sync(&close_work), cancel_delayed_work_sync(&tx_work), and cancel_work_sync(&smc_listen_work), whose callbacks acquire sk_lock-AF_SMC subclass 0 (and smc_server_lgr_pending). > + if (old->lgr =3D=3D lgr && old->alert_token_local && !old->freed && > + old->rtoken_idx =3D=3D conn->rtoken_idx && > + old->peer_rmbe_idx =3D=3D rmbe_idx) > + smc_conn_kill(old, true, true); [Severity: High] Does killing old on a live link group leak old->sndbuf_desc and old->rmb_de= sc in lgr? smc_conn_kill() calls smc_lgr_unregister_conn(old), which clears old->alert_token_local =3D 0 without calling smc_buf_unuse(). When smc_conn_free() later runs for old, smc_conn_lgr_valid(old) is already fals= e, so it jumps past smc_buf_unuse(): net/smc/smc_core.c:smc_conn_free() { ... conn->freed =3D 1; if (!smc_conn_lgr_valid(conn)) /* Connection has already unregistered from * link group. */ goto lgr_put; ... if (!list_empty(&lgr->list)) smc_buf_unuse(conn, lgr); /* allow buffer reuse */ ... } Unlike __smc_lgr_terminate(), where the entire link group is being torn dow= n, lgr stays active here, so old's send buffer and RMB remain marked used for = the rest of the link group's lifetime and their rkeys and rmbuse counters are n= ot released. [1] https://sashiko.dev/#/bug/linux-7780bd9b-22d1-46dc-9181-5d1b941b3794 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129001734.7855= 1-1-bugs@stellman-greene.com?part=3D1