From: Andrew Stellman 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 Signed-off-by: Andrew Stellman --- 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