🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25884

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

#25884
From: Andrew Stellman
Date: Wed, 02 Dec 2026 16:49
46 lines
12733 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.

Fixes: de8a6b15d965 ("net: mctp: add an explicit reference from a mctp_sk_key to sock")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Tested on net-next 19c484e12ed2 (7.4.0-rc4) in arm64 QEMU with a private
KUnit case that set a zero sk_refcnt on a bound socket (I didn't
reproduce the close race itself): without the fix it hit the "addition
on 0" and "underflow" refcount warnings, and with the fix it passed with
no warning.
Found with Quality Playbook
(https://github.com/andrewstellman/quality-playbook) running Claude Opus
5.5 and Claude Fable 5.2; the fix was drafted with OpenAI GPT-6 (Codex).
A reproducer is available on request.

 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 96fd75ea791b..5bc3a8e091d8 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: <20261202164958.49945-1-bugs@stellman-greene.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375939-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375939-linux-kernel-netdev=dewy.ru
From: bugs@stellman-greene.com (Andrew Stellman)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] net: mctp: don't hold a zero-refcount socket in mctp_key_alloc()
Date: Wed,  2 Dec 2026 11:49:58 -0500
Organization: Usenet Network
Message-ID: <20261202164958.49945-1-bugs@stellman-greene.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2013407"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vJ1QQfW/pJWlw/SDD1n8u42ZU1Y= sha256:RhArkrLyQGidlcd4vU1tUSr8qQbTssjU7Q/HHoa/X0w=
	sha1:GyKLCTVjN0GQJKF2DaSwGInOiQk= sha256:MqTvWxcZzrHlSalg7I4ZnVMBsDb0YCw/GCNBdrQ9Rg4=
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 493DA1176BB; Wed,  2 Dec 2026 19:50:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 aSlpPJa6j7L3;
	Wed,  2 Dec 2026 19:50:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375939-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 BF56B117634; Wed,  2 Dec 2026 19:50:15 +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 E093429335; Wed,  2 Dec 2026 16:50:05 +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=1796230202;
	b=GJB9ZF8xt0mdNUiazSbreq2WxLndbFAyXG2vxSZUKbyNQU3RIaESOUofG9Z1kDBbIFie
	 pdT+FDq8tyMPiAiGSJ3ZJDgV9DQQzRGLwJWGFz+nvl3nh2tsY8n+SVw0K7Q8QH3KD8Prw
	 OZ/psSlk2IzAX4pa6F80/luVGsWWNaLximZzzryTIaRrWYlagLLAVp+PKHh9TtYyPW5z0
	 O0qrp1pTexXhogMiAannidhvYTgJYXWu8dbzw8Q+RRCymuPEHqMPO5nt1R+wTZlditYzK
	 EYwv4Y7Ha10coQmKGYc4+ZKMhLMSrbNdkngXH2xd8IHweDLa8VSmlTP4H7QxiSj8qXw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796230202;
	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:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=DQ3HEmt04+Zs5EzrUQxYNA1FGk24Jgz/neEe9jlSdmU=;
	b=A0nEPXKO5QvnUzLvwINPN+tBK8AVVWwWUxuQybgNBxrDkF1Z0K255Ouv3CjEK3H2V+Cw
	 Uco9zseVZ87axqeb4FE7HXiPm2hXRWpg+RPu80gMXnekKuk/VnxUWKPNjPqlvXbROjTYa
	 XJaftONyg8uoEBlGOaJYYjTiwlQdf7UtZ8Y9NdM+1m8J1bOXllkWZNJ1AyqeMU53HLw5b
	 /R978v5DEacLM15+crFMERxf3ovkz0IEGrIcZCrANqUqWGCABK0gBf4Uez7bnwzoAYeog
	 mfYBqAEyyNJuCgSdE+dElsiN5mfI5IJFxJ6Iyr1ZlWSglIzVsDoG2VB5RFYiTqLdi2A==
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=PsfOkmoN;
	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 2BFD7606A681;
	Wed,  2 Dec 2026 16:50: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=PsfOkmoN
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.181
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796230201;
	b=k579InrFaooZ6TCoODOInAMhMOMFpKalr7OwV6i7QS5Ez4CwxfQF69IkhpYjCpPe9XPq
	 KINORG0cHfkWs8WJrTYMdMEDgpk8FR+NkBFSOSQMZGO7mVZU1Xcylzhgb/aUue1qAHICP
	 f0oNtZZY8y/Slyx3QKkXDlNXWnFwgEvnMdNV35scJTSbeqmDjwlfzu721EaWTF84hxt3H
	 x0jR8GXimW1xzcM0cGyYn9NVYbw4WQPfPM1SHTgGs+X4U/j+AlSXhUTTKuyxsF3WSYOQX
	 QnKZ7Kqhu1tKjzULmRePD9g8Wz/k2ZFnh/sVwOJUTNxBHcMGhgvW+YPC58SqF+WmORA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796230201;
	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:MIME-Version:
	 Content-Transfer-Encoding;
	bh=DQ3HEmt04+Zs5EzrUQxYNA1FGk24Jgz/neEe9jlSdmU=;
	b=nmokt1GQkulVSSlMKf4j+sWxXp1wjxtU9Dto0AODM7Qz4dXCuXMvX5fnDANVGqGemDg+
	 XpbXWSbYyQq2CIXE3PwrcbqME65oo/L3MQXBKycB+T36S752MIWa5dARDrprXXAIe88a5
	 w5uYldqbR4ezmfL+2PnbYEioldwWvUcPnL7+d0MUmYCZgqPm1lYv/lP1otjf+6y9X5pfN
	 FGZMsms+/Ak1hved8c5ovkMFo5Nw31B7DaFGfEgYnNoPlJ5nSu79P7tjF6hjkceln5CHE
	 dwWPxbcJqn8ZKPLgH10PEwhiL3xzsMA2TFS0biAPI9zu3zwNY5hwPMhXLiOpTSUt/Ew==
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=PsfOkmoN;
	arc=none smtp.remote-ip=209.85.222.181
X-Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181])
	(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 9C598606A331
	for <netdev@vger.kernel.org>; Wed,  2 Dec 2026 16:50:00 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C598606A331
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-qk1-f181.google.com with SMTP id af79cd13be357-9495f083657so1411400385a.0
        for <netdev@vger.kernel.org>; Wed, 02 Dec 2026 08:50:00 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1796230200; x=1796835000; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:message-id:date:subject:cc
         :to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=DQ3HEmt04+Zs5EzrUQxYNA1FGk24Jgz/neEe9jlSdmU=;
        b=PsfOkmoNmllcoHzkzpEubthAcA5C5DeSP68DPQ/PiAIdjIeQ2yVpbnho3pLv8Y+mwM
         a3yUJm2IXlF7nP3pzTr3uj9RTI2MQHYuob3CHtFBPHaPIwy0E2003Iu/rY/x5kQroXfE
         JXxkkeJtLmcH94faytvvAxd/c4r4tgNMm566kTi+qm9tu4l0dLkRsTluIzjg6tHhNypz
         pcZ33TtD3LR4kDCVe6ysAVOy4tbQ3IIZXn8BRngngFRRY4rUpYFOHyz9hsxm3l4bKGLR
         XL3/xXrIDf9y7mtdbHmyTykXhdJryxmvvmAIMjcjI++LWS2pEi6Q5wfueBeWzmOB6DeB
         K6qw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796230200; x=1796835000;
        h=content-transfer-encoding:mime-version: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=DQ3HEmt04+Zs5EzrUQxYNA1FGk24Jgz/neEe9jlSdmU=;
        b=hIJbCRspqThTaV91qAjk9ZJ8adxqsV+3Vl/E8gKVzi9c7V2BuvG6GVIzqD52YEFKAE
         BmzudPP6XABtT0OW/7GR5cQ/scTgozZ4fWAhJKvRz3MQhfmwtSc5CDlviFaFh0YNwmDW
         +susMthS6z76WsSiVM5qxOtjKttF+Nxih2WcekMty0EyKPkdGJZ041a2JfzLYnyDbhvA
         7AkWN3F3D6u2urMFtrBz+LCHylV/I8plt2d87lDbM8i26HkHsb7wTRyVhDbMdLafLG7u
         Q0Cx95/zNeerlcFkjvkTaktcNEJt/C91HVxRU1hjushUO46g6jiH4unJGs4d6j9q2fIj
         1OpQ==
X-Forwarded-Encrypted: i=1; AL+hErHXwvH4ZZI199fjdSYq1t9pZjL9KEkOf0TCxfk/sYn7VT5ikWW0uekXkhNJkIIWspBC+q2qyWQ=@vger.kernel.org
X-Gm-Message-State: APuU4Z+AVI6tSN/AunwZvPmI0MENwxGr7+dWpaWFe6TsUFWdpcI8Kwcv
	DxtMevNwia9CpJspF8bZN2JyeYYGopLQn5oA22GCUhwpb7YAHWhdyDLYMrfXJd8STog=
X-Gm-Gg: AZFdTZdDRN4ilj/c7TKRQtsg12c1wio7mMQTo78qhuFFEwWkG7yxRa0Zat1WcujGUfg
	FgESclMXEUB4cx5PlAhnc/ex2Swth9lRu3/8+K5Zt8fndX202Ncjh+Tq0vbWNZF2bToYGl79wkA
	dNiUDi+zYb8bD7+OPQ0RP/SNT9pacKIeezZRNMdb1PleE2gPucCTgv0bo25Jh9LTDv694FQyt4y
	htYcb37bwatX+j4LD4IGGyLP6lDmv/t+UIK0suw7ivcP93/PONNS6rR6InoF3C8+vkW5JcIhTdZ
	RF6OjztbSQk4ePr6+Jjn4aRZ8CxNAOJB6ljszxUaNh0i9xeT266lKLPeml7jaIWwL+rClGpeHNQ
	rh9LDjjU7kXSboVenpFgYvFRtrapsNnjDA0FQsAsWJehA7c4J4coMDjXx9rZ/5Zs2EACDt17GRM
	IKNvlxSfpR0snuNhncxMmWthRzPZM6lFk1OsYQX2bvHPhybC9i+Emhdy8X1KqMSDi3ehZOqDOCA
	YECUvid5wdMpNREz5J1p6Q0HZy2vCkx+zmuy/s1iykHdExs3chsx11oO6TNdcjhU+Ex8PvCAMOd
	IgqHzd8sB0N0THyY7kLQmiC59SFhHo3tSTv5pfne2kne8diFFgqJ/gq2KGrhJcey15+CS9R6A6h
	n
X-Received: by 2002:a05:620a:3726:b0:949:66eb:77eb with SMTP id af79cd13be357-949ba827b33mr7613665185a.10.1796230199687;
        Wed, 02 Dec 2026 08:49:59 -0800 (PST)
X-Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:9fd:9761:5b78:f32c])
        by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb3a646fsm3159971685a.22.2026.12.02.08.49.59
        (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
        Wed, 02 Dec 2026 08:49: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-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