🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14625

Re: [PATCH net v2] nfc: rawsock: serialize SEND_SHUTDOWN with the TX work requeue

#14625
From: Simon Horman
Date: Wed, 11 Nov 2026 17:14
101 lines
12253 bytes
On Thu, Nov 05, 2026 at 07:38:12PM +0800, Yaohan Li wrote:
> rawsock_release() sets SEND_SHUTDOWN before cancelling tx_work, but it
> updated the shutdown flag without the write-queue lock that
> rawsock_data_exchange_complete() holds while it tests the flag and
> re-queues tx_work.  A deferred completion could pass that check before
> the flag was set and still schedule the work after cancel_work_sync()
> had returned; the worker then ran on a socket that was freed right
> after release dropped its reference.  KASAN reports the
> slab-use-after-free in rawsock_tx_work().
> 
> Set SEND_SHUTDOWN under the write-queue lock, so the completion either
> queues the work before the flag becomes visible (and cancel_work_sync()
> then covers it) or observes the flag and does not queue.  The
> completion-side check from the previous submission is kept.
> 
> The remaining requeue window after the cancel-based teardown was
> previously raised in review of that change (CVE-2026-23372): an
> asynchronous NFC completion can queue tx_work after
> cancel_work_sync() has returned.  This change closes that window and
> does not claim to be the first report of a rawsock teardown
> use-after-free.
> 
> This issue was found during an AI-assisted source review of the socket
> release, TX work and deferred data-exchange completion paths.  It was
> reproduced on a KASAN kernel with a deterministic timing-injection
> harness for a deferred NFC completion callback: with only the
> completion-side check, stalling the completion between its shutdown
> check and schedule_work() while release ran produced seven
> slab-use-after-free reports in rawsock_tx_work(); with this change the
> same sequence and the original purge-window injection produce no
> reports.  The tests run in QEMU with a virtual NFC device; no NFC
> hardware is involved.
> 
> Link: https://lists.openwall.net/netdev/2026/03/24/271
> Fixes: d793458c45df ("nfc: rawsock: cancel tx_work before socket teardown")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
> ---
> 
> v2:
> - Set SEND_SHUTDOWN under the write-queue lock, so a completion that
>   tested the flag before it was visible can no longer requeue tx_work
>   after cancel_work_sync() returned (v1 only added the completion-side
>   check, which left this ordering window open).
> - Added deterministic A/B testing of that window: stalling the
>   completion between its shutdown check and schedule_work() while
>   release runs reproduces the use-after-free on the v1 code and is
>   clean with this change.
> - Corrected the Fixes tag to the cancel-based teardown commit and
>   linked the earlier review thread for the remaining window.
> 
> v1: https://lore.kernel.org/r/179378590950.74297.14503648624087894519@gmail.com/

Thanks for the updates.

>  net/nfc/rawsock.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
> index f7d7a599fade7..dd8401e3402d3 100644
> --- a/net/nfc/rawsock.c
> +++ b/net/nfc/rawsock.c
> @@ -68,12 +68,23 @@ static int rawsock_release(struct socket *sock)
>  		nfc_sock_unlink(&raw_sk_list, sk);
>  
>  	if (sk->sk_state == TCP_ESTABLISHED) {
> -		/* Prevent rawsock_tx_work from starting new transmits and
> +		/*
> +		 * Prevent rawsock_tx_work from starting new transmits and

I don't think there is a need to respin just because of it.
But if there is a v3 for some other reason then I think the change
above can be dropped. Perhaps tooling flaged the existing style,
but it is acceptable for Networking code. And, for many years
it was required.

>  		 * wait for any in-progress work to finish.  This must happen
>  		 * before the socket is orphaned to avoid a race where
>  		 * rawsock_tx_work runs after the NCI device has been freed.
> +		 *
> +		 * Set SEND_SHUTDOWN under the write-queue lock so it is
> +		 * ordered against rawsock_data_exchange_complete(), which
> +		 * tests the flag and re-queues tx_work under the same lock:
> +		 * either the completion queued the work before we take the
> +		 * lock (cancel_work_sync() below then covers it), or it
> +		 * sees SEND_SHUTDOWN and does not queue.
>  		 */
> +		spin_lock_bh(&sk->sk_write_queue.lock);
>  		sk->sk_shutdown |= SEND_SHUTDOWN;
> +		spin_unlock_bh(&sk->sk_write_queue.lock);
> +
>  		cancel_work_sync(&nfc_rawsock(sk)->tx_work);
>  		rawsock_write_queue_purge(sk);
>  	}

...

Overall this looks good to me.

Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID: <20261111171418.GG18859@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-361194-linux-kernel-netdev=dewy.ru
References: <20261105113812.969651-1-shunsheng1218@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.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-361194-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] nfc: rawsock: serialize SEND_SHUTDOWN with the TX
 work requeue
Date: Wed, 11 Nov 2026 17:14:18 +0000
Organization: Usenet Network
Message-ID: <20261111171418.GG18859@horms.kernel.org>
References: <20261105113812.969651-1-shunsheng1218@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="903404"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FiEOSxnJfCP5VEkwAGPWdKUsl/0= sha256:g82VzkGRQMk6CpKC1+XgrBBQXxd9Em3pA90ppZr5e5w=
	sha1:oU5QXRZLcWM+OCSCQc+rjxARTXk= sha256:fohpMLayCdlxaEdzYBL6H1i3NIisrIhcyx3xDGciPHY=
Content-Disposition: inline
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 A5E3F113F6D; Wed, 11 Nov 2026 20:35:10 +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 Yd_VUZ2-yoPT;
	Wed, 11 Nov 2026 20:35:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361194-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 1F88C113F40; Wed, 11 Nov 2026 20:34:53 +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 D123318517A; Wed, 11 Nov 2026 17:14:30 +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=1794417263;
	b=qWwkVNcIbrflpdnlRhrgCiWYWipnMyKXlueVUORg8hdDMhKBUDgVHF8tc5zSoM7jmV6a
	 iqepvwwrJmVebalyft8TGA0StNh8RbuaYfGUQpi1Kmcy/YJHSyx3Zj36x/iW/Wi9UfDtg
	 AQ5XKKI3uSH/+evX97n68k1yEnU8wEkrF4P4MAxFobVK+lCbWxVkU9zQAa+7sEOm9BxeI
	 YIXzJbGbVQvAb5Abg66JC1r1IZ1kL1fgwO/xnAy4kigoSyf4cSfFYiRe5uCjICIKZsTIG
	 UzivZVP2KvAE3Dc2oEsdY/GH3K8TDmgHHX59HeOC/Oer9yDxh8A7+WwGDQtebB+1U0g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794417263;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=K0OUanBq+hsQdFZ3wody+MoiBGNzg1aTJa0o6x23ajI=;
	b=smpxRzqdrcGhIeKgvBBfoykigxHJqYiKBHum/4HVGXMGpU8S8KkEtLV1DENzeNUaOi2s
	 pY50UCRU+j6nzHBw2pFOsAU2w2KMBkaZHKQSvlfBZzv5vkGhCUUBSkZBsVwcw7dZvLbHY
	 niYDG6zrsMNww8pySsYKwkWv0q5SvhRyrNQjkPecPd1Avk5ktG5P6xQDrzGEnehs3x2GS
	 zmxewiZN5unPAHM0wQ5PAivhht+ODRUneZ3VApaQbJCEuvIUn1c+r+V1nlE66vWnzE7dz
	 9PeAdAPoMMWzjg1Y70OTHAWNULX2iFxOOKHijMWcdfugvowGNhkGQLeuJC/CgTdoyHw==
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=nH1JAGr6;
	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 7578F606A887;
	Wed, 11 Nov 2026 17:14:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=nH1JAGr6
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=1794417262;
	b=Fbe+Wpc6fRp5uwiLh2gIaAX9Ax++m3KiLVEvZcuuda7G38IKRRha76J66zhCeJKdveOW
	 MSO+toQvm6nw0WplnaTGoWYTrC1HjDHJKausTG8jCpLxo6YFQQJJaxoH8R5JZD2klAv9V
	 gs4GLUW2lvZHDrf5R/bEl/NMX2NaKGBEfwZztisN/Y3yIgBkccbSM8XXrZWDCjRobu5em
	 h+psj+cDQPLjx4FbO/+y2t9mOXT+8W7/iXHuqwGWugzb9fbHSzvMoWrZExAU5YhzrMEIb
	 zOqBIv6r2YZ5WNV/gC6jXSkjvCHM0K9ZthfNOPiezS7R8vhPw+YtuTlA6BwK3gHIpxA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794417262;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=K0OUanBq+hsQdFZ3wody+MoiBGNzg1aTJa0o6x23ajI=;
	b=aeHAJpaxUfBNdPPN/care1Yh7kekQ4tK3GfJpdznes4XTfi/U+whcSqxIgglNmPtoJtC
	 ZpOc1ESMuT0OwQL9f0p3OVGLqMgwDf4OlrHVegoKNkPOJjlOy81urxqMHAXxaO2Rfh/vu
	 jtQm3mTyPe2+hTxBPkvhclQOpV9iapJ31xQJPvxQSucfWQ/SeGtQLsvtOstoxJ/kwpnSJ
	 iEv7TYTAHrGqOUqchObyHlQzCFZ47ZYK9mSKty++PLUu5o08bEWmS0r6xD/36O6mBx2R8
	 zV82Dl6bhHU2Brz64a4BLuZfriT5U6T/hwpAB0ju0MVFMEGIrS3RvbrRkGHpPxMaiDA==
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=nH1JAGr6;
	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 962D8606A31C;
	Wed, 11 Nov 2026 17:14:22 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D8601F00A06;
	Wed, 11 Nov 2026 17:14:20 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794417262;
	bh=K0OUanBq+hsQdFZ3wody+MoiBGNzg1aTJa0o6x23ajI=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=nH1JAGr6uuk6lIu20lPUVYJov5jYScxDWYtnf7zo9eE3S2TnUVpVQc2m7yUa9zfRW
	 toANGDI6xl6733KtFkVbHEqWbuyJzbY8FVIdr3APnt6AqZcoqumlBXYSbKLkLYsw1P
	 CcMY1JzUpgP5zijw5iCX/+gsy0GKFE/qnGbbYgQ5iSxmndJ8ps+6ycBHs2TmDMIYv5
	 gLIYpwVCm6ILFKaWWFIjA6PoPkdaqPQjl2mzofBUh7kJm3VAO0tgR612U8Ay3yVipF
	 wDdoLOZA7LjMOmLJat3dWTiee8OaQrSsgKNBbHxkDHIO5fEKA9x5Ljbm6SdWSUDJ0f
	 BA19bUmhcxmmQ==
X-Cc: netdev@vger.kernel.org, david@ixit.cz, davem@davemloft.net,
	kuba@kernel.org, edumazet@kernel.org, pabeni@redhat.com,
	oe-linux-nfc@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
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
X-In-Reply-To: <20261105113812.969651-1-shunsheng1218@gmail.com>