Article View: linux.kernel.netdev
Article #10385Re: [PATCH net 2/2] connector/cn_proc: release socket state and listener count on close
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 13:10
Date: Tue, 03 Nov 2026 13:10
150 lines
13179 bytes
13179 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch makes cn_proc_release() (drivers/connector/cn_proc.c)
the single place that cleans up when a NETLINK_CONNECTOR socket closes.
--
connector/cn_proc: release socket state and listener count on close
This moves the NETLINK_CONNECTOR release cleanup into a new
cn_proc_release() helper, which now runs for every socket on close. The
helper frees sk->sk_user_data and decrements proc_event_num_listeners
when the stored mcast_op is PROC_CN_MCAST_LISTEN. The aim is to fix the
proc_input leak and the listener count imbalance.
> diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
> index 4f613c0648ae4..a4b62998095ea 100644
> --- a/drivers/connector/cn_proc.c
> +++ b/drivers/connector/cn_proc.c
> @@ -387,6 +387,20 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack)
> send_msg(msg);
> }
>
> +/* Called when a NETLINK_CONNECTOR socket is released. */
> +void cn_proc_release(struct sock *sk)
> +{
> + struct proc_input *input = sk->sk_user_data;
> +
> + if (!input)
> + return;
> +
> + if (input->mcast_op == PROC_CN_MCAST_LISTEN)
> + atomic_dec(&proc_event_num_listeners);
> + kfree(input);
> + sk->sk_user_data = NULL;
> +}
[Severity: High]
This cleanup assumes two things. Each socket owns at most one
proc_input, and proc_event_num_listeners holds exactly one increment for
each socket whose stored mcast_op is LISTEN. Does cn_proc_mcast_ctl()
actually guarantee either of these?
Nothing on the send path serialises it per socket. In
netlink_sendmsg()->netlink_unicast()->netlink_unicast_kernel(),
nlk->netlink_rcv() is called with no lock_sock(). cn_call_callback()
holds queue_lock only for the lookup:
drivers/connector/connector.c:cn_call_callback() {
...
spin_unlock_bh(&dev->cbdev->queue_lock);
if (cbq != NULL) {
cbq->callback(msg, nsp);
...
}
As a result, two threads sharing one fd can run this section of
cn_proc_mcast_ctl() at the same time:
drivers/connector/cn_proc.c:cn_proc_mcast_ctl() {
...
if (sk->sk_user_data == NULL) {
sk->sk_user_data = kzalloc_obj(struct proc_input);
...
initial = 1;
} else {
prev_mc_op =
((struct proc_input *)(sk->sk_user_data))->mcast_op;
}
...
((struct proc_input *)(sk->sk_user_data))->mcast_op = mc_op;
...
case PROC_CN_MCAST_LISTEN:
if (initial || (prev_mc_op != PROC_CN_MCAST_LISTEN))
atomic_inc(&proc_event_num_listeners);
break;
case PROC_CN_MCAST_IGNORE:
if (!initial && (prev_mc_op != PROC_CN_MCAST_IGNORE))
atomic_dec(&proc_event_num_listeners);
...
}
Can this still leak the proc_input? If both threads see sk_user_data as
NULL, each calls kzalloc and the second store overwrites the first
pointer. cn_proc_release() frees only the pointer that survives. A loop
of socket(), two concurrent control messages and close() would then
still leak kmalloc-8, much like the OOM reproducer in the commit
message.
Can the count still be left too high? Both threads can take the
increment path, for example when both are initial LISTENs, or when the
second thread reads the freshly published zeroed mcast_op (0, which is
not PROC_CN_MCAST_LISTEN) before the first thread stores LISTEN.
cn_proc_release() decrements only once.
There is also an interleaving where the new release-time decrement
seems to push the count too low:
thread A (LISTEN, fresh socket)
sk->sk_user_data = kzalloc_obj(...) /* mcast_op == 0 */
initial = 1
thread B (IGNORE)
prev_mc_op = 0
atomic_dec(&proc_event_num_listeners)
mcast_op = PROC_CN_MCAST_IGNORE
thread A
mcast_op = PROC_CN_MCAST_LISTEN
atomic_inc(&proc_event_num_listeners)
close()
cn_proc_release()
atomic_dec(&proc_event_num_listeners)
Before this patch that sequence left the counter balanced. With this
patch, each round lowers proc_event_num_listeners by one.
Once the count drops below 1, proc_fork_connector() and the other
proc_*_connector() hooks, as well as cn_proc_ack(), return early. Would
that stop process events for every listener on the system? The
reachability checks are cn_bind() for CN_IDX_PROC and the init user/pid
namespace test in cn_proc_mcast_ctl(), so an unprivileged user can
trigger this.
Would it make sense to serialise cn_proc_mcast_ctl() per socket, for
example with lock_sock(sk) or a mutex around the sk_user_data install
and the mcast_op transition plus counter update? Another option is a
cmpxchg() install of sk_user_data together with an xchg() of mcast_op,
using the old value to pick the inc or dec.
> /**
> * cn_proc_mcast_ctl
> * @msg: message sent from userspace via the connector
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102130922.75629-1-cenzhang%40linux.microsoft.com
Technical Details
Message-ID:
<179371141120.488856.13027523647862479080@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355623-linux-kernel-netdev=dewy.ruReferences:
<20261102130922.75629-3-cenzhang@linux.microsoft.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355623-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net 2/2] connector/cn_proc: release socket state and listener count on close Date: Tue, 03 Nov 2026 13:10:11 +0000 Organization: Usenet Network Message-ID: <179371141120.488856.13027523647862479080@kernel.org> References: <20261102130922.75629-3-cenzhang@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3175260"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:YJDXpqGVotFQjBH/Nlg1w2OgB2o= sha256:X1rykf9xCnctdYULSnqei8VLTI1jn8s7AtfGXCgJV+0= sha1:4sTzYipmNMOblLXAHqy0YY+Nulw= sha256:EhbNNj2dAWZ2zipjyWD1BTTlpn5VjaKPjvgAjkeSN3c= 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 E000C1128AF; Tue, 3 Nov 2026 16:37:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 x9hdfZbX37_3; Tue, 3 Nov 2026 16:37:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-355623-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 8165511289A; Tue, 3 Nov 2026 16:37:04 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 97F0CC8829; Tue, 3 Nov 2026 13:11:52 +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=1793711413; b=NIP4majTlEOd+/bpXPKeBn4NGYc83gwxrYB/pwr1scIhvM8bxRtzILfpnAbjB23qM4/i DjXVl19XJAF62fgHEvz4BbdPXRZCHyUPgwWtXL0GqByEIcfnGs7Rcwy6/tbKsXA0aYWWv Gv6GO1qzqWBZKwKHGwJ5SVSYjsvfWcQyRaNUkZzwVotWcgK0AhGEpz8geZ5nODlFbGbs/ KiR/7QlZeAlgG6gobh+04X6xIa+kxIvKfReTptRb8k5OBQiJ838sArS4+gwDxOcaf5WMc Xt6n4YFx6mepmFPSVzzV94eIvuSlSq/jZT00lhLR0coyvcsnku8x6hWF036roKYlmMQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793711413; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=PSDntGuIfgagBvAExwS6AxASDwHywut+hO3ZGe4XpBM=; b=ZfGYG6xKnmyblv3ATPalgw6iM7oO9kY5/9tmQX4lWTQhOj5rvlsgBsFF1aT2qL5MQE5I LB43bWoh8eQBx3Cs9V6ILQPr98us7BWclFPRZuDqHkRXzN5QYduy2e6UT/XPe+GIHCeQj Z1ktDp6UFqQIcKHGEtTA8VbvoLyr3azeEpMadOnCgB2shVJczSpUAZgXMh2BtduiuQGDF qrePeC1xatm8JSdA2AzxtCx616srlVIQOeSKjzHHEq8ksDox5Q0NFuHVqXfb9F2jvuA2G qzNxqWjsgDfi7pdd+E/utQ8LqfZ+Wg6ieOGIog7Jfwiwu2XgetM6gTUymEqeZOnPXpA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YEyqadUq; 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 9D9BD6082BEB; Tue, 3 Nov 2026 13:10:13 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YEyqadUq X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793711412; b=cfEPnnQHf7sEdl9Xmu/i2jTnka/DLcfG3uGwKLAUoN7Bd9mQPWw34bG76ByO01dfjygO dXULDu5vZJjf5tUsYPIw9toLZOEsPAn5YpUM+gmGhw8lkPBWo6Bplh42g55dGpi27SWGv SvpCupitCHFt1sH5osftgvbhw+DBE7yBZwLszxKkQt9EuOqEKF6TrKpEwgPKSZKjAq/dr VfyiTaF9/meIQRzllFugOBtjQbuEIuo1DJxfe58BlsSlJG4woEjLHcLeGQRV+Fo9DKRwf y8LGIJ673TbWiJs8EPGZYOGbnmcW9FFjfugeW8f4IGBipEvFsHAd2LFkwpKZmSgyDyA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793711412; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=PSDntGuIfgagBvAExwS6AxASDwHywut+hO3ZGe4XpBM=; b=egR+3LtTyBxTxPxFspTzoATrHc/P3+Rp5yLf321o0am4Zz72V8Qtrsf19uXYcduxG43V 31lPnsfLkbMd+ZXb9pqfu4vzifmcYO+peAMlZp4CSCCXZCKvAIXlGj9WzUmpCMFSKVcCM EfmROie0UPN+RRm5Pk4TnzFWLDFT5mdKOxLe5fId49DpmwtcwNnHeSXQNvnDPg63rrbNu /tXst5DANkxILy3LzqqapYmxVyUzN4AYnimvwZAnt1nrmf/HgIGGy6p7qnR6OS/HAThF1 TlpkjI2l7TqfXr9PTubSbKy0PhP6iP2DakjspnC8FzLj3X+PNzRmCIW+LsyPzZ82Z/Q== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YEyqadUq; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7281C6082BD9; Tue, 3 Nov 2026 13:10:12 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AA251F00919; Tue, 3 Nov 2026 13:10:11 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793711412; bh=PSDntGuIfgagBvAExwS6AxASDwHywut+hO3ZGe4XpBM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=YEyqadUq/vD7mn2sQm7rW5cXSKEBCH/ZXFx7VIjAsR/sVuKdO9E4SzT3UBw28oGOW Y7Ssto7CIv59mQru1uVSibGFkHy7VhU738TmPn+3NAAiDX51ZozvEL6Y8iZQFP1DTV agZkjzhjBgXYAaJikdv8RYfrbedIEFKozfjGca95CoT7B50B3on4TeX9nl0QKVVXYv zNKNxyVKc0oydZyn4uCwh3J1Ua63+sfHDokcgfmtd8B03fsr9dw5Rev67vzcl+uvS7 EUUnWfpoTnqLU3BY13hlaFhffZl8oYr7ngAl2gyiJarVZfTiTIwA6b2RqBV/dgN+fF bcjZeTbE5WRaA== X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, anjali.k.kulkarni@oracle.com, liam@infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, AutonomousCodeSecurity@microsoft.com, tgopinath@linux.microsoft.com X-In-Reply-To: <20261102130922.75629-3-cenzhang@linux.microsoft.com> X-sashiko-severity: High 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