🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27065

[PATCH net v2 1/2] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()

#27065
From: Andrew Stellman
Date: Fri, 04 Dec 2026 18:42
51 lines
13172 bytes
From: Andrew Stellman <astellman@stellman-greene.com>

mctp_dst_input() finds the bound socket with mctp_lookup_bind() under
RCU only, without holding a reference. If a concurrent close drops
the last reference after that lookup, mctp_key_alloc() calls
sock_hold() on a zero refcount, which saturates it and warns, and
mctp_key_unref() later underflows it.

Take the reference with refcount_inc_not_zero() and fail the key
allocation if the socket is already at 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 fix and this changelog were drafted with OpenAI GPT-6 (Codex)
and reviewed by me.

Fixes: de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au>
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v2: no code change; add Jeremy Kerr's Reviewed-by.
v1: https://lore.kernel.org/netdev/20261202164958.49945-1-bugs@stellman-greene.com/

Tested on net 3c8881ee9806 (7.4.0-rc5) in arm64 QEMU with KASAN, using
the KUnit case in 2/2, which sets a zero sk_refcnt on a bound socket
(the close race itself wasn't reproduced): it hit the "addition on 0"
and "underflow" refcount warnings without this fix and passed with it.

 net/mctp/route.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/mctp/route.c b/net/mctp/route.c
index 96fd75ea7..5bc3a8e09 100644
--- a/net/mctp/route.c
+++ b/net/mctp/route.c
@@ -239,7 +239,10 @@ static struct mctp_sk_key *mctp_key_alloc(struct mctp_sock *msk,
 	key->valid = true;
 	spin_lock_init(&key->lock);
 	refcount_set(&key->refs, 1);
-	sock_hold(key->sk);
+	if (!refcount_inc_not_zero(&msk->sk.sk_refcnt)) {
+		kfree(key);
+		return NULL;
+	}
 
 	return key;
 }
-- 
2.53.0
Technical Details
Message-ID: <20261204184258.70828-2-bugs@stellman-greene.com>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377545-linux-kernel-netdev=dewy.ru
References: <20261204184258.70828-1-bugs@stellman-greene.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377545-linux-kernel-netdev=dewy.ru
From: bugs@stellman-greene.com (Andrew Stellman)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 1/2] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()
Date: Fri,  4 Dec 2026 13:42:57 -0500
Organization: Usenet Network
Message-ID: <20261204184258.70828-2-bugs@stellman-greene.com>
References: <20261204184258.70828-1-bugs@stellman-greene.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2834022"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/XshGbr9TC47xvfXCniwgayAYC0= sha256:/CJZKjzKqnnWm76bAlvN802PCKhIIS3IZ0vbLvpzCZA=
	sha1:9RzsjUxd6aGgs6oV8Q5FeOvBz1o= sha256:YsbP/67LXAmlYgdJsTTl0eMtZ4/1mf6a7mO5DDxpHWY=
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 DAEF8117C99; Fri,  4 Dec 2026 21:43:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.299
X-Spam-Status: No, score=-3.299 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.001, 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=stellman-greene-com.20260707.gappssmtp.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 IVzdo6WVTEEM;
	Fri,  4 Dec 2026 21:43:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377545-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=stellman-greene.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id A88E3117C67; Fri,  4 Dec 2026 21:43:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 74628228FA; Fri,  4 Dec 2026 18:43:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796409782;
	b=CruKTPHHhIYQ9xrBcYZsHuFmIi0ElcZwnxJ7pkVWy7hThWwaCgUtPnegkD8OgMIjtKbO
	 3XG1VcQ2VZZkB9ACbyRuTLv0Q4S1mdfS8f3vVaB9VIBlCwcEOYwp7QwHSKitT+KKF1T4y
	 omOsDt5i7SbGUT4NB/knFUuRdjfFVoV4CE8VSNMkHaK6BobzK4od7bAXJHzJzvISXh+K8
	 BLafra1hdqVx0LyMOXoUy9ke/m+Zob0CKH/lTR6+DPTK76FiMvPqRFJp+VpA/ulEhyxlq
	 jt1G8L3d/NENGCeTNQj1Zi1MJRDZPh0k8pe9CHGmH8hPA1MeOeSOXv7va6T3++j+r3w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796409782;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=6/ZDVtEy4DJ7cDuAVy+6RzLINk1FwDTcvxKe3dBzAkE=;
	b=N9mn79r0QxIoU/8LYOespcq7Yc044N/nZk1ZO7Y4HxtPHlN9VU0UUXz+83O8Wsobl8l5
	 sicYsmL5D8mkTksZmUmzSX37R+0tiMSbSqVifI4Uoz4C7ck5+JbRvxz2b54IFAkF0PQN4
	 kM28ajB+TBNW9NPNkCjC3RwrcewwPMKWeEP/2fb/lMuUf3uYbWz6E9oYNjZlD3ZCYj6e/
	 ZYsAwcBn/0bNC4XFRu15ZksGXe9b56/6Kdl/G/YN+6XXEMAxqW8J864lNYYSo9RKwvTY8
	 NAVwx2jjxMWLLCjcrcxJfqQoFawXDlLi2IEwtFJUmbF+6afWIKxGA0lF5MEw/k0WItw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=P8UxTbji;
	dmarc=none header.from=stellman-greene.com;
	spf=none smtp.mailfrom=stellman-greene.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 40251606A68D;
	Fri,  4 Dec 2026 18:43:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=P8UxTbji
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796409781;
	b=FyQgkIckIg5Hbpu5ic+43drOnxeZjsIyo5o08GC8RTLlvmDeiq3Zut76k7IPXC4TU1cz
	 3DtTO9mk7A/C3ayihCEZjeeilBC0h8VWoOqScbWhDcpsYtw+9sOETSMHpjKLitLSsjzB9
	 pnJYkWRuTsZz04g6ycvOt8WBISWAXkM1Aq1YMnc3KhNtbrtlsgXt3dXMUTE8k5R18Aym8
	 CuZmYFQYah7h4BzV/xOq2uL4sdjgTwvTCgFvmCRlsJ2LPgr72bDfXad5ZKareUEK90TxK
	 O7GAkf37mqZZO4axhutJdNQN8XRSyrjNWjojySEYSWLEQd8jAg2zxtjFpmfWCKfeTGg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796409781;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=6/ZDVtEy4DJ7cDuAVy+6RzLINk1FwDTcvxKe3dBzAkE=;
	b=jjyw4uovIabJqOw0vVY8gzLDeYNXPGLp6bvur1tAt9AV1MXTD/Ud/m8+8ld1s7WCBffK
	 ATU6w1Jpsno4kFmiLypedGVBXnJljEh+F1nsvAdkahke47Qs0N95PXXA3jd6HWNdhUQzO
	 J/JGDhxWEgwp3jJM+Qo7mHD8qeB4BPZv2dy7OpEEZso+uCAij98p/Izg9omIZgj0h7Stv
	 7gFQYk4pyE+MtcUbaac78SsvL53p6I+6h9d5DmSKtfCkiBK8eik9g/CQdKyAqGONDiGIE
	 /7rEqi+squUgGkHwgSP/OTBIujCfi33ccZQZT/p3xWO2yST53LLmwKPg0zOPWmzyFHw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=stellman-greene.com;
	spf=none smtp.mailfrom=stellman-greene.com;
	dkim=pass header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=P8UxTbji;
	arc=none smtp.remote-ip=209.85.219.47
X-Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16E5E606A335
	for <netdev@vger.kernel.org>; Fri,  4 Dec 2026 18:43:00 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16E5E606A335
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stellman-greene.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=stellman-greene.com
X-Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-921d2f3d65dso13772066d6.2
        for <netdev@vger.kernel.org>; Fri, 04 Dec 2026 10:43:00 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1796409780; x=1797014580; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=6/ZDVtEy4DJ7cDuAVy+6RzLINk1FwDTcvxKe3dBzAkE=;
        b=P8UxTbjii6Mv43ecd+gRdEW2NHeFitWEuf4/Rg7g+tYFOKG6xmATqpMhNgVPIGh8px
         Po8igAsy7umIzzBRWlONsokZkigFYCYTltEPkLa8TR1Cwq/OqT4H7jyQKthwR/o4ujEa
         vJMRgjsdTwkxEVh3vZ/oIFDumYPrC+RU8tZwRlpT39zdFPWNYDWjF6SiAjs2Z6pEGi1w
         Ji12Kv48odqRaAxjHPbJOVGB1eFjnd7jEAp4QyAiFuLCQN5PKFtwYVyUxvDjJywM64f6
         inYgdk4YVaj2Jw0L1umJNKkAb4iBdEy6a+qCCxulDhmKZinf7Ie276NwarKlgV1l+uSt
         d2cA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796409780; x=1797014580;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
         :to:cc:subject:date:message-id:reply-to:content-type;
        bh=6/ZDVtEy4DJ7cDuAVy+6RzLINk1FwDTcvxKe3dBzAkE=;
        b=f67PKOPXgebqLkvrUP9tS4vyudtwNtQ4yo8P8w6nxl/FR2afnFVJEJ41UNkqJ/qIqR
         v7LkICfpjiFf8LBJZtLD5NuYsVKwhkjJjFg7KMbE/AOxBZjtFznzjUX5PEPfKTsIGdJm
         Km9dAR6b7ILEkwS+c4RycKnBPqFSe08BrNVvfkBB7NiaN+pk6UxL+qywDMreA5R9+5mN
         t+W7Gr0PVRCQWt01txHDviznTQ8vggM8g+1FS1WZETmSU564+t6rLZ2aoCCFvsLh61/i
         FwGk9ZkInwOg98oA4ne0Y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df08f44-921e26a362emr46657666d6.55.1796409780029;
        Fri, 04 Dec 2026 10:43:00 -0800 (PST)
X-Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:62:766c:1c4a:276e])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921e05801f1sm28228006d6.23.2026.12.04.10.42.59
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Fri, 04 Dec 2026 10:42:59 -0800 (PST)
X-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
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261204184258.70828-1-bugs@stellman-greene.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list