From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Mahanta Jambigi <mjambigi@linux.ibm.com>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12 008/555] net/smc: fix link group ownership in handshake abort
Date: Fri, 4 Dec 2026 19:00:51 +0900 [thread overview]
Message-ID: <20261204100604.247759268@linuxfoundation.org> (raw)
In-Reply-To: <20261204100603.988357525@linuxfoundation.org>
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahanta Jambigi <mjambigi@linux.ibm.com>
[ Upstream commit e227b511582828c5a6513f70fc6a71211e5efbf0 ]
An aborted first-contact handshake can hang the handshake worker on the
socket lock it already holds, reset the clcsock of a socket that has
fallen back to TCP, or corrupt the alert-node lookup when the handshake
retries with the same connection.
The abort leaves a connection registered in a link group that another
context has already unlinked for termination: smc_conn_free() skips the
unregister when lgr->list is empty, so the alert token and alert node
stay in lgr->conns_all. If the handshake retries another device or SMC
version, smc_conn_create() creates a second link group and
smc_lgr_register_conn() inserts the same alert node into it: the token
loop is skipped, rb_link_node() links a node that is still in the old
tree into the new one, and a second sock_hold() is taken where only one
sock_put() will follow. The old group's terminator then keeps returning
that node from rb_first() and can kill a connection that now belongs to
the new group.
smc_lgr_cleanup_early() also starts a second termination of the link
group that is already being terminated, which takes lock_sock() on the
socket the handshake worker holds; if the termination work wins the race
instead, it later kills the freed connection and aborts the clcsock of a
socket that has fallen back to TCP. Making the unregister unconditional
also lets smc_conn_free() reach the delayed free work on a claimed link
group, where the lockless freeing check can arm it after the owner has
cancelled it.
Always unregister the connection, claim a link group for termination
once under lgr_lock, keep the link group alive across the abort, and arm
the delayed free work only under the same lock and cancel it
synchronously before the teardown. Drop an already freed connection in
smc_conn_kill() without running the connection and socket teardown.
Fixes: 2a0674fffb6b ("net/smc: improve abnormal termination of link groups")
Fixes: f9aab6f2ce57 ("net/smc: immediate freeing in smc_lgr_cleanup_early()")
Cc: stable@vger.kernel.org
Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
Link: https://patch.msgid.link/20261106130457.1092203-1-mjambigi@linux.ibm.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/smc/af_smc.c | 11 ++++---
net/smc/smc_core.c | 78 +++++++++++++++++++++++++++++++++-------------
net/smc/smc_core.h | 6 ++--
3 files changed, 65 insertions(+), 30 deletions(-)
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 0d00fa56a9002..0adc46c691312 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1010,14 +1010,15 @@ static void smc_conn_abort(struct smc_sock *smc, int local_first)
{
struct smc_connection *conn = &smc->conn;
struct smc_link_group *lgr = conn->lgr;
- bool lgr_valid = false;
-
- if (smc_conn_lgr_valid(conn))
- lgr_valid = true;
+ bool lgr_valid = local_first && smc_conn_lgr_valid(conn);
+ if (lgr_valid)
+ smc_lgr_hold(lgr); /* lgr_put below */
smc_conn_free(conn);
- if (local_first && lgr_valid)
+ if (lgr_valid) {
smc_lgr_cleanup_early(lgr);
+ smc_lgr_put(lgr);
+ }
}
/* check if there is a rdma device available for this connection. */
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index 1f340de96ec83..982c9cf39ba6a 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -80,16 +80,21 @@ static void smc_ibdev_cnt_dec(struct smc_link *lnk)
static void smc_lgr_schedule_free_work(struct smc_link_group *lgr)
{
+ spinlock_t *lgr_lock;
+
/* client link group creation always follows the server link group
* creation. For client use a somewhat higher removal delay time,
* otherwise there is a risk of out-of-sync link groups.
*/
+ smc_lgr_list_head(lgr, &lgr_lock);
+ spin_lock_bh(lgr_lock);
if (!lgr->freeing) {
mod_delayed_work(system_wq, &lgr->free_work,
(!lgr->is_smcd && lgr->role == SMC_CLNT) ?
SMC_LGR_FREE_DELAY_CLNT :
SMC_LGR_FREE_DELAY_SERV);
}
+ spin_unlock_bh(lgr_lock);
}
/* Register connection's alert token in our lookup structure.
@@ -679,19 +684,34 @@ int smcd_nl_get_lgr(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len;
}
-void smc_lgr_cleanup_early(struct smc_link_group *lgr)
+/* Claim a link group for termination. Only one context can succeed: the
+ * lgr is removed from its list and marked freeing under lgr_lock.
+ * Returns false if @lgr is NULL or another context owns it.
+ */
+static bool smc_lgr_claim(struct smc_link_group *lgr)
{
spinlock_t *lgr_lock;
if (!lgr)
- return;
-
+ return false;
smc_lgr_list_head(lgr, &lgr_lock);
spin_lock_bh(lgr_lock);
+ if (lgr->freeing || lgr->terminating || list_empty(&lgr->list)) {
+ spin_unlock_bh(lgr_lock);
+ return false;
+ }
/* do not use this link group for new connections */
- if (!list_empty(&lgr->list))
- list_del_init(&lgr->list);
+ list_del_init(&lgr->list);
+ lgr->freeing = 1;
spin_unlock_bh(lgr_lock);
+ return true;
+}
+
+/* The caller must keep @lgr alive for the duration of the call. */
+void smc_lgr_cleanup_early(struct smc_link_group *lgr)
+{
+ if (!smc_lgr_claim(lgr))
+ return; /* another context owns the termination */
__smc_lgr_terminate(lgr, true);
}
@@ -1260,10 +1280,12 @@ void smc_conn_free(struct smc_connection *conn)
if (current_work() != &conn->abort_work)
cancel_work_sync(&conn->abort_work);
}
- if (!list_empty(&lgr->list)) {
+ /* The handshake can retry another device or SMC version with this
+ * connection, so it must never stay registered in an lgr it left.
+ */
+ if (!list_empty(&lgr->list))
smc_buf_unuse(conn, lgr); /* allow buffer reuse */
- smc_lgr_unregister_conn(conn);
- }
+ smc_lgr_unregister_conn(conn);
if (!lgr->conns_num)
smc_lgr_schedule_free_work(lgr);
@@ -1498,6 +1520,15 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft)
{
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
+ if (conn->freed) {
+ /* The connection was already freed, e.g. by a close or
+ * a handshake that fell back to TCP. Do not abort a socket
+ * that is no longer part of this link group.
+ */
+ smc_lgr_unregister_conn(conn);
+ return;
+ }
+
if (conn->lgr->is_smcd && conn->lgr->peer_shutdown)
conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
else
@@ -1545,12 +1576,20 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft)
struct smc_connection *conn;
struct smc_sock *smc;
struct rb_node *node;
+ spinlock_t *lgr_lock;
- if (lgr->terminating)
+ smc_lgr_list_head(lgr, &lgr_lock);
+ spin_lock_bh(lgr_lock);
+ if (lgr->terminating) {
+ spin_unlock_bh(lgr_lock);
return; /* lgr already terminating */
- /* cancel free_work sync, will terminate when lgr->freeing is set */
- cancel_delayed_work(&lgr->free_work);
+ }
lgr->terminating = 1;
+ spin_unlock_bh(lgr_lock);
+ /* The lgr is claimed, so no new free_work can be armed; wait for
+ * one that is already queued or running.
+ */
+ cancel_delayed_work_sync(&lgr->free_work);
/* kill remaining link group connections */
read_lock_bh(&lgr->conns_lock);
@@ -1561,7 +1600,11 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft)
sock_hold(&smc->sk); /* sock_put below */
read_unlock_bh(&lgr->conns_lock);
lock_sock(&smc->sk);
- smc_conn_kill(conn, soft);
+ /* The connection may have been re-registered in another
+ * link group by a retried handshake in the meantime.
+ */
+ if (conn->lgr == lgr)
+ smc_conn_kill(conn, soft);
release_sock(&smc->sk);
sock_put(&smc->sk); /* sock_hold above */
read_lock_bh(&lgr->conns_lock);
@@ -1575,17 +1618,8 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft)
/* unlink link group and schedule termination */
void smc_lgr_terminate_sched(struct smc_link_group *lgr)
{
- spinlock_t *lgr_lock;
-
- smc_lgr_list_head(lgr, &lgr_lock);
- spin_lock_bh(lgr_lock);
- if (list_empty(&lgr->list) || lgr->terminating || lgr->freeing) {
- spin_unlock_bh(lgr_lock);
+ if (!smc_lgr_claim(lgr))
return; /* lgr already terminating */
- }
- list_del_init(&lgr->list);
- lgr->freeing = 1;
- spin_unlock_bh(lgr_lock);
schedule_work(&lgr->terminate_work);
}
diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h
index 69b54ecd65031..bc32e6c08fb56 100644
--- a/net/smc/smc_core.h
+++ b/net/smc/smc_core.h
@@ -288,9 +288,9 @@ struct smc_link_group {
struct delayed_work free_work; /* delayed freeing of an lgr */
struct work_struct terminate_work; /* abnormal lgr termination */
struct workqueue_struct *tx_wq; /* wq for conn. tx workers */
- u8 sync_err : 1; /* lgr no longer fits to peer */
- u8 terminating : 1;/* lgr is terminating */
- u8 freeing : 1; /* lgr is being freed */
+ u8 sync_err; /* lgr no longer fits to peer */
+ u8 terminating; /* lgr is terminating */
+ u8 freeing; /* lgr is being freed */
refcount_t refcnt; /* lgr reference count */
bool is_smcd; /* SMC-R or SMC-D */
--
2.53.0
next prev parent reply other threads:[~2026-12-04 10:16 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:00 [PATCH 6.12 000/555] 6.12.121-rc1 review Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 001/555] net: ipv6: keep room for the mac header in dst_dev_overhead() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 002/555] virtgpu: dont reset on shutdown Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 003/555] virtio: add virtio_device_shutdown() helper Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 004/555] virtio_balloon: factor out virtballoon_quiesce() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 005/555] virtio_balloon: quiesce balloon work before device shutdown Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 006/555] mm/page_alloc: snapshot the preferred zone against shrink rebuilds Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 007/555] pidfd: restrict task access ioctls to the callers pid namespace Greg Kroah-Hartman
2026-12-04 10:00 ` Greg Kroah-Hartman [this message]
2026-12-04 10:00 ` [PATCH 6.12 009/555] net/mlx5e: Fix queue stats access to queues without stats Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 010/555] tcp: do not coalesce segments after FIN Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 011/555] tcp: fastopen: note that a child socket was created Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 012/555] tcp: fix request_sock use-after-free during Fast Open accept() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 013/555] net: gro: invalidate frag0 after a pull Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 014/555] wifi: mac80211: fix use-after-free on TTLM disconnect Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 015/555] dm: fix infinite loop in dm_blk_do_report_zones() Greg Kroah-Hartman
2026-12-04 10:00 ` [PATCH 6.12 016/555] iio: common: scmi_sensors: fix truncating 64-bit divisions Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 017/555] iio: proximity: sx9500: ignore event config writes that dont change state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 018/555] iio: imu: inv_mpu6050: fix swapped accel and gyro startup times Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 019/555] mmc: jz4740: Remove the host before resetting the controller Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 020/555] ALSA: hda: Fix [codec] ID matching in patch files for IDs with bit 31 set Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 021/555] kprobes: Adopt guard() and scoped_guard() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 022/555] mmc: omap: synchronize clock timer before disabling fclk Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 023/555] mmc: sunxi: Use devm_mmc_alloc_host() helper Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 024/555] mmc: sunxi: fix clock and runtime PM leaks on probe failure Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 025/555] errseq: eliminate special limitation for macro MAX_ERRNO Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 026/555] errseq: dont let errseq_check_and_advance() hide later errors Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 027/555] xsk: defer software checksum until the skb is complete Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 028/555] cpufreq: Improve suspend-resume synchronization Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 029/555] tpm: flush timeout work outside buffer_mutex to avoid deadlock Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 030/555] spi: tegra210-quad: Track DMA mapping state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 031/555] watchdog: npcm: Remove unnecessary NULL check before clk_prepare_enable/clk_disable_unprepare Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 032/555] watchdog: npcm: fix clock prepare leak when setting timeout on a running watchdog Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 033/555] tracing/probes: Enable newly appended probe when target event is enabled Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 034/555] tracing/probes: Fix missing BTF kind checks in char pointer/array helpers Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 035/555] xfrm: Dont clobber inner headers when already set Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 036/555] Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 037/555] mtd: core: avoid double-free of OTP NVMEM device Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 038/555] bpf: Introduce jit_required flag and remove bpf_prog_has_kfunc_call() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 039/555] bpf: Reject programs with inlined helpers if JIT is not available Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 040/555] bpf: Disallow interpreter fallback for arena-related insns Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 041/555] bpf: Disallow interpreter fallback for BPF_ADDR_PERCPU insn Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 042/555] mm/page_alloc: dont increase highatomic reserve after pcp alloc Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 043/555] mm/page_alloc: use existing highatomic reserves on the buddy fastpath Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 044/555] xprtrdma: serialize unmap_sync with xprt_disconnect Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 045/555] gve: Fix race between stats query and queue reconfig Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 046/555] gve: Block invalid ring sizes when device options are 0 Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 047/555] net: wait for in-flight device unregistrations before netns dismantle Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 048/555] ksmbd: pin parent dentries in SMB2 CREATE ACL path Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 049/555] ksmbd: refuse to read a handle that is not open for reading Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 050/555] tracing/probes: Fix BTF bitfield parsing and out-of-bounds buffer write Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 051/555] comedi: comedi_bond: Fix leak of opened device references Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 052/555] Bluetooth: btusb: fix use-after-free in force_poll_sync Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 053/555] tools/bootconfig: Close only opened braces in compact output Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 054/555] ipv6: Remove IPV6_ADDRFORM Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 055/555] iio: proximity: sx9360: fix sampling frequency write and available range Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 056/555] KEYS: Expand key->{datalen,quotalen} to unsigned int Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 057/555] keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 058/555] KEYS: Protect pkey method checks against type removal Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 059/555] tcp: move __reqsk_free() out of line Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 060/555] tcp: free saved_syn after an RCU grace period Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 061/555] cgroup/cpuset: Correctly set isolated_cpus when switching partition state Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 062/555] arm64: suspend: rely on daif helpers to handle PMR Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 063/555] arm64: suspend: Only track cpuidle context for idle tasks Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 064/555] pNFS: avoid repeatedly cancelling I/O for the same lseg Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 065/555] watchdog: rz: Discard pm_runtime_put() return values Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 066/555] watchdog: rzv2h: Use pm_runtime_put_sync() Greg Kroah-Hartman
2026-12-04 10:01 ` [PATCH 6.12 067/555] hwmon: (nct6775) Handle dual use registers Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204100604.247759268@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=mjambigi@linux.ibm.com \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox