From: Dust Li <dust.li@linux.alibaba.com>
To: Xiang Mei <xmei5@asu.edu>, netdev@vger.kernel.org
Cc: alibuda@linux.alibaba.com, sidraya@linux.ibm.com,
wenjia@linux.ibm.com, ubraun@linux.ibm.com,
linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
bestswngs@gmail.com
Subject: Re: [PATCH net] net/smc: reject CHID-0 ACCEPT that matches an empty ism_dev slot
Date: Thu, 14 May 2026 19:54:46 +0800 [thread overview]
Message-ID: <agW4Bpp5NAka9ebS@linux.alibaba.com> (raw)
In-Reply-To: <20260511062138.2839584-1-xmei5@asu.edu>
On 2026-05-10 23:21:38, Xiang Mei wrote:
>On the SMC-D client, slot 0 of ini->ism_dev[]/ini->ism_chid[] is
>reserved for an SMC-Dv1 device. smc_find_ism_v2_device_clnt()
>populates V2 entries starting at index 1, so when no V1 device is
>selected slot 0 is left in its kzalloc()'ed state with ism_dev[0] ==
>NULL and ism_chid[0] == 0.
>
>smc_v2_determine_accepted_chid() then matches the peer's CHID against
>the array starting from index 0 using the CHID alone. A malicious
>peer replying to a SMC-Dv2-only proposal with d1.chid == 0 matches
>the empty slot, ini->ism_selected becomes 0, and the subsequent
>ism_dev[0]->lgr_lock dereference in smc_conn_create() faults at
>offsetof(struct smcd_dev, lgr_lock) == 0x68:
>
> BUG: KASAN: null-ptr-deref in _raw_spin_lock_bh+0x79/0xe0
> Write of size 4 at addr 0000000000000068 by task exploit/144
> Call Trace:
> _raw_spin_lock_bh
> smc_conn_create (net/smc/smc_core.c:1997)
> __smc_connect (net/smc/af_smc.c:1447)
> smc_connect (net/smc/af_smc.c:1720)
> __sys_connect
> __x64_sys_connect
> do_syscall_64
>
>Require ism_dev[i] to be non-NULL before accepting a CHID match.
>
>Fixes: a7c9c5f4af7f ("net/smc: CLC accept / confirm V2")
>Reported-by: Weiming Shi <bestswngs@gmail.com>
>Assisted-by: Claude:claude-opus-4-7
>Signed-off-by: Xiang Mei <xmei5@asu.edu>
>---
> net/smc/af_smc.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
>index 185dbed7de5d..12ea3b6dbc64 100644
>--- a/net/smc/af_smc.c
>+++ b/net/smc/af_smc.c
>@@ -1400,7 +1400,8 @@ smc_v2_determine_accepted_chid(struct smc_clc_msg_accept_confirm *aclc,
> int i;
>
> for (i = 0; i < ini->ism_offered_cnt + 1; i++) {
>- if (ini->ism_chid[i] == ntohs(aclc->d1.chid)) {
>+ if (ini->ism_dev[i] &&
>+ ini->ism_chid[i] == ntohs(aclc->d1.chid)) {
I agree this can solve the bug you rised, but I also agree with
shashiko's comments here, we should have a better solution solving
this null-ptr-deref and use-after-free.
Does this check leave us vulnerable to a use-after-free if the device
is removed during the CLC handshake?
smc_find_ism_v2_device_clnt() populates ini->ism_dev[i] with pointers to
struct smcd_dev while holding the smcd_dev_list.mutex. However, it doesn't
appear that struct smcd_dev has a reference counting mechanism.
The client then drops the mutex and calls __smc_connect() ->
smc_connect_clc(), which sleeps waiting for an ACCEPT message from the
network peer.
During this unbounded blocking wait, can the underlying ISM device be
unregistered (e.g., via hardware unplug)?
If smcd_unregister_dev() runs, it removes the device from the list and
frees the memory using kfree(). It seems smc_smcd_terminate_all() only
waits for fully established Link Groups, not for in-progress connection
attempts.
When the server accept message eventually arrives, ini->ism_dev[i] will
still hold the dangling non-NULL pointer. This check evaluates to true,
and the code will assign ini->ism_selected = i.
Could this lead to smc_conn_create() actively dereferencing freed memory
via &ini->ism_dev[ini->ism_selected]->lgr_lock?
Best regards,
Dust
> ini->ism_selected = i;
> return 0;
> }
>--
>2.43.0
prev parent reply other threads:[~2026-05-14 11:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 6:21 [PATCH net] net/smc: reject CHID-0 ACCEPT that matches an empty ism_dev slot Xiang Mei
2026-05-11 6:28 ` Xiang Mei
2026-05-14 10:19 ` Paolo Abeni
2026-05-14 11:57 ` Dust Li
2026-05-14 10:40 ` patchwork-bot+netdevbpf
2026-05-14 11:54 ` Dust Li [this message]
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=agW4Bpp5NAka9ebS@linux.alibaba.com \
--to=dust.li@linux.alibaba.com \
--cc=alibuda@linux.alibaba.com \
--cc=bestswngs@gmail.com \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sidraya@linux.ibm.com \
--cc=ubraun@linux.ibm.com \
--cc=wenjia@linux.ibm.com \
--cc=xmei5@asu.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.