Article View: linux.kernel.netdev
Article #571Re: [PATCH net v2] net/smc: serialize clcsock access with its release
From: Chengfeng Ye
Date: Thu, 08 Oct 2026 08:47
Date: Thu, 08 Oct 2026 08:47
147 lines
15424 bytes
15424 bytes
On Thu, Oct 8, 2026 at 3:32 PM Mahanta Jambigi <mjambigi@linux.ibm.com> wrote:
>
>
>
> On 04/10/26 12:03 am, Chengfeng Ye wrote:
> > Link-group termination can release the CLC socket through
> > smc_close_active_abort() while the SMC socket is still open, for example
> > after shutdown(SHUT_WR). A file reference keeps the SMC socket alive but
> > does not prevent this asynchronous release of its CLC socket.
> >
> > smc_getname() can race the pointer removal and sock_release(). The same
> > missing lifetime synchronization affects smc_set_keepalive(), diagnostic
> > address copying and an in-flight SMC-R CDC receiver. smc_shutdown() can
> > also reach its final CLC shutdown after its close helper drops the socket
> > lock and a concurrent abort closes the socket. Holding the SMC socket
> > lock alone is insufficient because CLC release runs outside that lock.
> >
> > KASAN reported the getname failure:
> >
> > BUG: KASAN: slab-use-after-free in smc_getname+0x19e/0x1b0
> > Read of size 8 at addr ffff888109abb4e0 by task poc/103
> > Call Trace:
> > smc_getname+0x19e/0x1b0
> > do_getsockname+0xe5/0x170
> > __sys_getsockname+0x8c/0x100
> >
> > Allocated by task 95:
> > sock_alloc_inode+0x1e/0x280
> > sock_alloc+0x3d/0x240
> > __sock_create+0x7e/0x430
> > smc_create+0x121/0x240
> >
> > Freed by task 0:
> > kmem_cache_free+0xcc/0x340
> > rcu_core+0x50a/0x1850
> >
> > Last potentially related work creation:
> > evict+0x446/0x6c0
> > smc_clcsock_release+0xa8/0xd0
> > smc_close_active_abort+0x26a/0x3a0
> > __smc_lgr_terminate.part.0+0x137/0x2e0
>
> Hi Chengfeng,
>
> Thanks for the KASAN report and the fix. The UAF in smc_getname is real
> and needs to go to net and stable. However, I think the v2 approach of
> adding a new spinlock and extending clcsock_release_lock to cover more
> readers is treating symptoms rather than the root cause. Let me explain
> what I think should happen instead. What to keep from your patch.
>
> Please send a v3 with only the smc_getname fix:
>
> int smc_getname(struct socket *sock, struct sockaddr *addr,
> int peer)
> {
> struct smc_sock *smc;
> + int rc = -EBADF;
>
> if (peer && (sock->sk->sk_state != SMC_ACTIVE) &&
> (sock->sk->sk_state != SMC_APPCLOSEWAIT1))
> return -ENOTCONN;
>
> smc = smc_sk(sock->sk);
>
> - return smc->clcsock->ops->getname(smc->clcsock, addr, peer);
> + mutex_lock(&smc->clcsock_release_lock);
> + if (smc->clcsock)
> + rc = smc->clcsock->ops->getname(smc->clcsock, addr, peer);
> + mutex_unlock(&smc->clcsock_release_lock);
> + return rc;
> }
>
> That is 4 lines against the confirmed KASAN-reported UAF, uses
> infrastructure that already exists (clcsock_release_lock is already held
> by smc_clcsock_release() when it frees clcsock, and already initialized
> in smc_sk_init()), and is a clean candidate for stable. Nothing else
> from v2 is needed for this specific bug.
>
> Drop the clcsock_lock spinlock, the CDC change, the diag change, the
> shutdown change, the connect-abort change, and the smc_accept_dequeue
> change. Those races are real but I will address them with a proper
> structural fix as Me & Dust Li have already discussed on LKML in August[1].
>
> Why the other races exist and what the right fix is
>
> Every race in your v2 — keepalive, CDC, diag, shutdown, the
> connect-abort path — has the same root cause: clcsock can be freed while
> the SMC socket is still alive. Several close paths call
> sock_release(clcsock) before the SMC socket's own refcount reaches zero:
>
> 1) smc_close_active_abort() — for PEERCLOSEWAIT*, PROCESSABORT,
> APPFINCLOSEWAIT states
> 2) smc_close_passive_work() — when the passive close work transitions to
> SMC_CLOSED
> 3) __smc_release() — when sk_state == SMC_CLOSED
>
> Every access site that can race with those releases is then forced to
> take clcsock_release_lock and check if (!smc->clcsock). Your v2 adds a
> second lock on top of this for the BH/atomic readers that cannot take a
> mutex. This complexity is unnecessary because none of those early paths
> actually need to destroy the socket — they only need to stop it.
> tcp_abort() and kernel_sock_shutdown() are sufficient for that, and both
> are safe to call more than once. sock_release() is the exception: it
> frees memory and must happen exactly once.
>
> The fix is to move that single sock_release() call to smc_destruct() —
> the sk->sk_destruct callback that fires from __sk_free() when the last
> sock reference drops. At that point no concurrent user can exist:
>
> 1) fd users are gone: smc_release() calls sock_orphan() before dropping
> its reference, so no file descriptor can reach the socket after that point
> 2) workqueue contexts (close_work, smc_listen_work) hold a sock_hold()
> and therefore keep smc_destruct() from running while they are active
> 3) accept-queue entries hold a sock_hold() via smc_accept_enqueue() for
> the same reason
>
> This gives us a simple invariant: clcsock is non-NULL for the entire
> lifetime of the SMC socket. With that invariant every reader becomes
> trivially safe — no lock needed, no NULL check needed, the race
> condition simply cannot occur.
>
> [1] https://lore.kernel.org/netdev/ao5bB9OCbJ5PQbEp@linux.alibaba.com/
Hi Mahanta,
Thanks for the detailed response. I just sent v3 with only the
smc_getname() fix.
The additional locking in v2 was added in response to Sashiko’s review
of v1. I should have checked the August discussion before expanding
the scope of the patch.
Best regards,
Chengfeng
Technical Details
Message-ID:
<CAAo+4rVmRy7Hj-PRuCzuzXg=r5HDib2ztNnBa6On9+Lx1W1Ysw@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342837-linux-kernel-netdev=dewy.ruReferences:
<20261003183325.2289707-1-nicoyip.dev@gmail.com> <4bb7f15e-2cd8-4598-9bab-1ea5f5d2bb59@linux.ibm.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342837-linux-kernel-netdev=dewy.ru
From: nicoyip.dev@gmail.com (Chengfeng Ye)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] net/smc: serialize clcsock access with its release
Date: Thu, 8 Oct 2026 16:47:17 +0800
Organization: Usenet Network
Message-ID: <CAAo+4rVmRy7Hj-PRuCzuzXg=r5HDib2ztNnBa6On9+Lx1W1Ysw@mail.gmail.com>
References: <20261003183325.2289707-1-nicoyip.dev@gmail.com> <4bb7f15e-2cd8-4598-9bab-1ea5f5d2bb59@linux.ibm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="838609"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:isa3vM//X95KjZ0MOlyr+MVhul4= sha256:4RjV4TRRBFKjnfrvHeSIdCBthw1ic1P8Zaj38+xnzTw=
sha1:D3kPITBF7PaJPwTnnfGa1xxDvSg= sha256:K02OW0en+1mwnYxHv/pjSIr7UmSSwSQzZhWf7UZw2dM=
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 E777D10F35C; Thu, 8 Oct 2026 11:48:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
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=gmail.com
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 MOfwVE2eWcry;
Thu, 8 Oct 2026 11:48:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-342837-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id CEA0210F335; Thu, 8 Oct 2026 11:48:04 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 6CC4835872; Thu, 8 Oct 2026 08:47:40 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 870E93EC829;
Thu, 8 Oct 2026 08:47:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kuUSni7h"
X-Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F11A4718FB
for <netdev@vger.kernel.org>; Thu, 8 Oct 2026 08:47:32 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.218.52
X-ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791449255; cv=pass; b=dtJJut9KkIUkG+Dsy3dss1T37zfFua1amGKVgxRNiL2pTWV+uiiQ9zD9Bp8LUdfwn5/JSBrR+Dx7gZiu8qyF0bZiLu3AklkYT0FS3F/8gqav9qtC/Bsv8gr397DqWlfoHlNAntvS+FixewmZfzoYUyLDBMLuVutvxSeUq7N6xr4=
X-ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791449255; c=relaxed/simple;
bh=wnf1Rxz7GOXO2mt1drF6YwLshKbYBKmoC34txj8aINc=;
h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
To:Cc:Content-Type; b=pfdA40VBf5rDU2Eq2G7EFblJJPOB3nJURZM+c9sx5hHLgwpMeCGzbEoIlM3YASl+Fnry61iksDReoNQrU48RaxkVKvDQZMTZSp0P+/OXm+8ypFDLDs4RuAFY47eD6GkjYm8jrB+BwPcDWZkPxJbjvvPS4eEHOH1GlKULBcDNDUs=
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kuUSni7h; arc=pass smtp.client-ip=209.85.218.52
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-c2e4e7351e8so9609066b.2
for <netdev@vger.kernel.org>; Thu, 08 Oct 2026 01:47:32 -0700 (PDT)
X-ARC-Seal: i=1; a=rsa-sha256; t=1791449250; cv=none;
d=google.com; s=arc-20260327;
b=ccP2Q81b/bK5UJdFEm1Jz934f75460YegXeFQGLNrENmr8q9+hvd+1rjCgUwK7JiV4
xBKzhhWZqYeANW8OQjDJDyislO206PzJGVg6j9O3wspuJdKZlgl0k+4sPeZQNKda2K2/
xVk3QWNuSJ9SbLMk1Aqr9Gg4F2i2FB4AlwAP9ueIom0jaMoL6WGBYBOSM5N2lQYw7FxA
b+yMqSZkHAVLRgDRZKtR/oRDSTr0+/k3AtmymVdDeoeKc/7siLspv2bmT8uSGKvgWVZI
EE9lIuO77SJ4N7a9nlzK4nbk5jaQoznBEKDZlzJFtY6E5q1eme6sD3xONIj0mTso47MR
cDiw==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:dkim-signature;
bh=0UcH2PL4jFdt0IAXyp77qe+AKdk/VbOyr7Y+0xZparU=;
fh=Egvy9/MbHyj99xLAYDtk8iTJmn5Y3mrnb9uGeNuwHFQ=;
b=eLsORtfYspDljLl+vJCLUWqUOBqDxFQg/a2VkQXDJ4qyJd4/TCu8rO+h2sPzaNZkec
NGgYyPTk/PidkIPwWyNqe2jSfdKEvCXQ1gRL91jqc/as0C+OTu15Xo7Sdn7KSqj7jhY4
wMfIqlCucf+6KOzRLA3i9CBjyZud0kmDS4ZlzsLfnA85VNhFzSFxq9dV9V3cGhPk7BtE
LwD8Hq4ZCsZ7sWTMea37Mct968z38xqgEH20TMjy9AuX2/VXfTv/4OXVzotbpeouBWF7
5XtuvLMeWd14hA49scuvwn8Wo8A/bEqZzlr70BSHpSUsAw7yX7WSkCJLQE1DxVy/IKtb
jFfQ==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791449250; x=1792054050; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=0UcH2PL4jFdt0IAXyp77qe+AKdk/VbOyr7Y+0xZparU=;
b=kuUSni7hlE4lksl+gPcGL9an60/cobuTciWPG0OHc+15BstRjhLcDuDM1OwQ9BGf/e
NjakGT8e6p5scau0Y74rF6mcakjRAxwRiRUzY3OiXBH05XesXmmD2g8dH6YnPFtS9p4t
bm7eTNGm7PywFocmIleZf/dVg+prWH4BgkWtOCKHsOdqbPzYyV4JyVGQHS2TTba6zoIm
2PLN65i+HaKPTU6OWXSYaJWZsUfNWjDO8UFmcGFkEZSk+erBZn/ydIUOHAkyNW81JN5d
GBzF+7ANa+901btPE0aYQwHRNiFzufhlKMI7tpulSek/nGkGgImRm25mO+8b9jX2gOJt
WMXw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791449250; x=1792054050;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=0UcH2PL4jFdt0IAXyp77qe+AKdk/VbOyr7Y+0xZparU=;
b=OwesruCn5Um0edM+q5iAsuzfrH+fvkulbO0bABM5+9X/1ZclJyqSDMhV9Rex+VITYK
SCfwpAyq75o/VoofhkTzzLxCY4sPQG6WjQoMzfIuTQ6MhltA6VIbg9k3VPeORd8JLYZx
0fC5Nscxv/eBClX0/NkBsVb2wtSdrYwgQlYPiWiOBUaet+PZA6SBa7VlQHQTEbPmTOlS
apR8ZGP4eWyfKjQWDOVp+3HBBKYGpUjfncwzxVag+tiONJzPFpBraN2WINlq1glzitzT
879rsZ/3F/wT4Gbaur1/g7dSpuhb1XkajTjd0JCLgCF8hHHlST4Ctk8lAipnaYKHDXM7
5WmA==
X-Forwarded-Encrypted: i=1; AKwUvBze6pd6zqeh3uLgr3LXdN40vpOcMzaptIZHOmwMcdvTjpuOlaTFgQ1YEGja8o69g1rXDraKxWY=@vger.kernel.org
X-Gm-Message-State: AFuF++mYYL9t3cZV43zztc2EGbe54Ax0P3wirBku0N0UmG4VYRH/s1HA
zL6uxBd+6Rtwjgl/XC6U7I3KL7/UACQE5sq+1R8BoupfwIUngGuCaO5gve/cFob+eIhxFwKt95n
LSJcUnzZhLACsh4iiDbUmwg2vIE7s9PM=
X-Gm-Gg: AYBFou0qujSEutklJyhPEqeplSMt53zhHXfnZvZQkF3URa5vwFAFfCr23SgNSI/oDmK
NggFJLZ27jMlbu5JLXhsXXhV9vWz/AagrCNfigKqRtAXFtNi9sR1hwGmXytxIZe9UF3gfkfqWe0
1wc5YLDfXvH2h8WLycjXxyNejzAB6KuKjD/cv3CrP9Q1/2MlcHakdTRbllvZAWt1hqSbHStbaP0
S49HdyX84+pX8nLyOLk0dKC/ZTbpHsqpabqka8wN31EbVe07v5pkQtQSvV6ZYKO0VbKbY0OpRyL
G04MRq+4uWn+7RZi+DPjXevx2FmnpkiUHDSZfY9YPl+dd8f4ZJhFF7GU/Ng0pcuPBnDjhtoPl+9
PMSRsEca9yg0=
X-Received: by 2002:a17:907:3f1a:b0:c29:5637:ed76 with SMTP id
a640c23a62f3a-c3190b7f237mr174970566b.2.1791449250106; Thu, 08 Oct 2026
01:47:30 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-In-Reply-To: <4bb7f15e-2cd8-4598-9bab-1ea5f5d2bb59@linux.ibm.com>
X-Gm-Features: AclHuK-HvCltyPhbBd2tQBXjDEN4keSNVUMLUN1JKqvwBHV5wUDOdUDGOh2UcnU
X-Cc: "D . Wythe" <alibuda@linux.alibaba.com>, Dust Li <dust.li@linux.alibaba.com>,
Sidraya Jayagond <sidraya@linux.ibm.com>, Tony Lu <tonylu@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>, "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org