Netdev List
 help / color / mirror / Atom feed
From: Andrew Stellman <bugs@stellman-greene.com>
To: Jeremy Kerr <jk@codeconstruct.com.au>,
	Matt Johnston <matt@codeconstruct.com.au>
Cc: "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>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v2 2/2] net: mctp: test route input with a zero-refcount socket
Date: Fri,  4 Dec 2026 13:42:58 -0500	[thread overview]
Message-ID: <20261204184258.70828-3-bugs@stellman-greene.com> (raw)
In-Reply-To: <20261204184258.70828-1-bugs@stellman-greene.com>

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

Add a KUnit case for the zero-refcount socket path in
mctp_key_alloc(). Send a start-of-message packet without EOM
while the bound socket is RCU-visible with no references, and check
that its count stays zero.

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

Suggested-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Tested on net 3c8881ee9806 (7.4.0-rc5) in arm64 QEMU with KASAN: this
case failed without 1/2 and passed with it, and both MCTP KUnit suites
passed with the series.

 net/mctp/test/route-test.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/net/mctp/test/route-test.c b/net/mctp/test/route-test.c
index f05f75bf9..6864dc732 100644
--- a/net/mctp/test/route-test.c
+++ b/net/mctp/test/route-test.c
@@ -1717,7 +1717,37 @@ static void mctp_test_route_output_extaddr_no_eids(struct kunit *test)
 	mctp_test_destroy_dev(dev);
 }
 
+static void mctp_test_route_input_sk_zero_ref(struct kunit *test)
+{
+	const struct mctp_hdr hdr = RX_HDR(1, 10, 8, FL_S | FL_TO);
+	struct mctp_test_dev *dev;
+	struct mctp_dst dst;
+	struct socket *sock;
+	struct sk_buff *skb;
+	struct sock *sk;
+	int refs, rc;
+
+	__mctp_route_test_init(test, &dev, &dst, &sock, MCTP_NET_ANY);
+	sk = sock->sk;
+	refs = refcount_read(&sk->sk_refcnt);
+	skb = mctp_test_create_skb(&hdr, 10);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
+	mctp_test_skb_set_dev(skb, dev);
+
+	/* Model a socket still visible to RCU lookup after its last put. */
+	sock_set_flag(sk, SOCK_DEAD);
+	refcount_set(&sk->sk_refcnt, 0);
+	rc = mctp_dst_input(&dst, skb);
+	KUNIT_EXPECT_NE(test, rc, 0);
+	KUNIT_EXPECT_EQ(test, refcount_read(&sk->sk_refcnt), 0);
+	refcount_set(&sk->sk_refcnt, refs + (rc == 0));
+	sock_reset_flag(sk, SOCK_DEAD);
+
+	__mctp_route_test_fini(test, dev, &dst, sock);
+}
+
 static struct kunit_case mctp_test_cases[] = {
+	KUNIT_CASE(mctp_test_route_input_sk_zero_ref),
 	KUNIT_CASE_PARAM(mctp_test_fragment, mctp_frag_gen_params),
 	KUNIT_CASE_PARAM(mctp_test_rx_input, mctp_rx_input_gen_params),
 	KUNIT_CASE_PARAM(mctp_test_route_input_sk, mctp_route_input_sk_gen_params),
-- 
2.53.0


      parent reply	other threads:[~2026-12-04 18:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:42 [PATCH net v2 0/2] net: mctp: avoid a zero-refcount socket hold Andrew Stellman
2026-12-04 18:42 ` [PATCH net v2 1/2] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc() Andrew Stellman
2026-12-04 18:42 ` Andrew Stellman [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=20261204184258.70828-3-bugs@stellman-greene.com \
    --to=bugs@stellman-greene.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jk@codeconstruct.com.au \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeconstruct.com.au \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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