Netdev List
 help / color / mirror / Atom feed
From: Andrew Stellman <bugs@stellman-greene.com>
To: "D. Wythe" <alibuda@linux.alibaba.com>,
	Dust Li <dust.li@linux.alibaba.com>,
	Sidraya Jayagond <sidraya@linux.ibm.com>,
	Mahanta Jambigi <mjambigi@linux.ibm.com>
Cc: 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>,
	Willem de Bruijn <willemb@google.com>,
	linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
	netdev@vger.kernel.org
Subject: [PATCH net] net/smc: cap ADD LINK v2 rkeys to the receive limit
Date: Sat, 28 Nov 2026 14:17:30 -0500	[thread overview]
Message-ID: <20261128191730.30196-1-bugs@stellman-greene.com> (raw)

From: Andrew Stellman <astellman@stellman-greene.com>

smc_llc_fill_ext_v2() writes one 16-byte rkey entry per connection in
the link group into the 8192-byte SMC-Rv2 work-request buffer. The
count is lgr->conns_num and has no upper bound. After the headers there
is room for 507 entries, so a count of 508 writes eight bytes past the
buffer.

smc_conn_create() checks max_conns and the rtoken bitmap only for the
server role, and smc_rtoken_add() reuses an rtoken slot when the peer
repeats an RMB rkey and address, so a client link group isn't limited
to 255 connections. I didn't run a case where a peer brought a link
group to 508 connections.

Cap the count at SMC_LLC_RKEYS_PER_MSG_V2 (255), the limit that
smc_llc_save_add_link_rkeys() applies on receive. This changes existing
behaviour: in a group with more than 255 connections, ADD LINK now
carries only the first 255 rkeys, and later connections get no rkey on
the new link.

Tested on mainline (7.4.0-rc4) in arm64 QEMU with KASAN and SoftRoCE.
A test-only change forced a count of 508 and reused one RMB for the
extra entries, and KASAN reported an 8-byte out-of-bounds write. With
this patch there was no report, and reverting only the cap brought it
back. A two-connection SMC-R run with only this patch applied gave no
KASAN report.

The issue was found by Claude Opus 5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.

Fixes: b4ba4652b3f8 ("net/smc: extend LLC layer for SMC-Rv2")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 net/smc/smc_llc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c
index c9ccd8480369ca..9f6ba5f75b8f2b 100644
--- a/net/smc/smc_llc.c
+++ b/net/smc/smc_llc.c
@@ -638,7 +638,8 @@ static int smc_llc_fill_ext_v2(struct smc_llc_msg_add_link_v2_ext *ext,
 	prim_lnk_idx = link->link_idx;
 	lnk_idx = link_new->link_idx;
 	down_write(&lgr->rmbs_lock);
-	ext->num_rkeys = lgr->conns_num;
+	ext->num_rkeys = min_t(unsigned int, lgr->conns_num,
+			       SMC_LLC_RKEYS_PER_MSG_V2);
 	if (!ext->num_rkeys)
 		goto out;
 	buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst);
-- 
2.53.0


                 reply	other threads:[~2026-11-28 19:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261128191730.30196-1-bugs@stellman-greene.com \
    --to=bugs@stellman-greene.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@kernel.org \
    --cc=guwen@linux.alibaba.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    --cc=willemb@google.com \
    /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