From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230201; b=FE4no4CMgQAb+ey941S6lz+2K3aJ9noEHZMZxJQY31gdpeBQoCunxdzZyYlUi4nSa1vb FskWunhPXeSm2W1TGynTNz5y2ZH5BnXsHW0VAYWF1xuDr06+2ta7QGWhKAHbVO1GbNStX Yz4ReRsrUmFQNIaZvVG+XxGPTmG5JPcNw3Yti/aWUmaZ8CUbAoh8PumSjIBGPi7oQmycQ a8Gt3IF+IrmXxNPx1Dykdsfe6+MX1T9vYaON/TPNaPijKecWOErVPuF89kCa9tZRZbPZ+ RzESJsmxJhChKFmw9Qp6hF1Hdao0+OcYQZCyMzZvuPY26thWje/mhLlgCjnc6b0NF7g== 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=X4DYpMv32wbepRCVGg5IbjKpB17b8HNHGqyuutVImR6oEoCQS68pAX1UfhTxnOOtOENI aZecuzgaKsibcJKrGB5Xa3xem6zxVPAumlUgtpVddCtY4IGR7hA1g1WvYmQRJvSzBITY0 WCwoHFdvPntPdiMwpWU1Swm6QnAq3FBoPEt1YhdGwPhq6MWBeW0q/4qAWFadtczpxEG2b n9O3PuB+4n8otwi/AIKew+qUk7tlDjofV77a2MsgHnygiDXCeGs5s91+Pb8kZjaQtXs4r NYFzevJymGQTcbC7360lfskrjH753iRqFwHHSPBf3FXHLzlMqCD6xlt6i1nomECE7cA== 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.177 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 9C812606A332 for ; Wed, 2 Dec 2026 16:50:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C812606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=stellman-greene.com 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 Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-94961ed97bcso1286849985a.1 for ; Wed, 02 Dec 2026 08:50:00 -0800 (PST) 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=EdHIgyW2m6wdU/xpwsl+G0n1KHx+Y53jFndf0xbAVdHdRMUPXNd86IleKVqqJtv9mZ adtHJc1Rg38W1ynAlMMHoIwX2ayMW6Zg2yoVnukIgweTp3koJj8zg2sRLj8WkuAM3kbA mIgRVck9ViJEoUDZiYzAJE5GGycIOCX2b648mQoEvaN6Ip4w9VvhnES4lKtAeKAaKnQ7 0w5IZiMa29lls/HqcJd3dq32vS2B9tub3FboBX8f3waZgFG5U5ZhiPAV1pasqfzl6gZe cRKYzfW1tVuTQgQ+VDF2u5eE1El6luSna6vh9xc20//GTfOIeniY56t+FGI5QRFzGqbm eduQ== X-Forwarded-Encrypted: i=1; AL+hErHwj/fSsraKOGQ8DahcxCvr6dZJe/ihwhMt9Ld0ozixsz8iC4kzSN28owjM0O3SRcj1l615+LRpDP8/sFc=@vger.kernel.org X-Gm-Message-State: APuU4Z+l85BK/P1fhCaFAM+FA5X089ZwedPvv9Z++gLwIlD3PQgFhH7a jV7UkDeRIDprFW4S6lhgfkIYBz/3A5j+QMrzj3rq7F1O4vjB/iKxdXGvurMsw6SzZcA= X-Gm-Gg: AZFdTZe0bCRQ04ccowquK6jVL5re1kOu87Al32asZCbxPG9Ti5svy3Mah0tUmB1cV0l fcYKDyKy/lLQ8/W4/OXUCRHpFdq5otvJD7PXLzBBlPghj+trjARRwTMjJwMAH517leTkp+2hmU0 nWu7uKPE+TY6LW41HQLrpxluKt4YsDukkcCy/wKye7IMfEZBlUVe9AHUbk9CEM0l+mCGnYMZObP zTP6XSbDmEIPJLYDMspjiP6spUcdHjs40X7oMdPBMQU8x0hv0Al4grhww4Vx/lW9n+LLBkoQLoJ MmQop3uKjHyaY4LC1n5jmA69ZzyIseySzxPSsuCDUzF/Oe5ZtKFJsxEevIhXIjAMAKNOA/1T2p5 HhUb1/sX6wML146iijmyUw/KwJRdRr+GzMQGQmZvqF5LSHoCoKxhGk2If8zcAStfCpeliepm7zh rOaaTiOZ9+bz7RaBtdwMxe+llAelJRmKBznyJ6z0srPMI97foNc/PjUEuseeMLMviunAUZiWOJt Bmf9YDhh825xdO/pzDu9Shr/GRieymncSuS7ylm7p9uddqU1VFVZ/2ZYrAzBvTBugxMyeLw3/Wl q193XcHJj6VJZYiOivDIouKPQEOiVjOC79kMZveF7CbrDjfODglOsAP+8zclhO3pdZsnKpwXVhO M 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) 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) From: Andrew Stellman To: Jeremy Kerr , Matt Johnston Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org 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 Message-ID: <20261202164958.49945-1-bugs@stellman-greene.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrew Stellman 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 --- 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