From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.181 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== 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== 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 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 ; Wed, 2 Dec 2026 16:50:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9C598606A331 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-f181.google.com with SMTP id af79cd13be357-9495f083657so1411400385a.0 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=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) 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: netdev@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