Article View: linux.kernel.netdev
Article #16836Re: [PATCH net v4 1/2] tls: restrict device-down TX fallback to hardware TX sockets
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 00:02
Date: Mon, 16 Nov 2026 00:02
112 lines
12435 bytes
12435 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] In tls_device_down() (net/tls/tls_device.c), this patch decides
whether to call tls_dev_del(TX) from the result of…
--
tls: restrict device-down TX fallback to hardware TX sockets
This commit changes tls_device_down() so the TX validator is switched to
the software fallback only for sockets that use hardware TX. The cmpxchg
result now decides whether the driver TX state is deleted. RX driver
state is tracked with TLS_RX_DEV_CLOSED, which is set at context
creation and cleared after a successful RX tls_dev_add().
> diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
> index 4cdfbb57ecff0..a42cbc89db2bb 100644
> --- a/net/tls/tls_device.c
> +++ b/net/tls/tls_device.c
[ ... ]
> @@ -1350,10 +1350,14 @@ static int tls_device_down(struct net_device *netdev)
> spin_unlock_irqrestore(&tls_device_lock, flags);
>
> list_for_each_entry_safe(ctx, tmp, &list, list) {
> + bool tx_hw;
> +
> /* Stop offloaded TX and switch to the fallback.
> * tls_is_skb_tx_device_offloaded will return false.
> */
> - WRITE_ONCE(ctx->sk->sk_validate_xmit_skb, tls_validate_xmit_skb_sw);
> + tx_hw = cmpxchg(&ctx->sk->sk_validate_xmit_skb,
> + tls_validate_xmit_skb,
> + tls_validate_xmit_skb_sw) == tls_validate_xmit_skb;
[Severity: High]
Is ctx->sk still guaranteed to be allocated when this cmpxchg runs?
The cmpxchg is in the second loop, after tls_device_lock has been
dropped. The refcount_inc_not_zero() in the first loop pins only the
tls_context, not the socket.
The final reference on a hardware TX socket can be dropped from skb
freeing, and that path does not take device_offload_lock. The socket
destructor then sees the extra ctx reference held by tls_device_down()
and returns early:
__sk_destruct()
tls_device_sk_destruct()
tls_device_queue_ctx_destruction()
spin_lock_irqsave(&tls_device_lock, flags);
if (unlikely(!refcount_dec_and_test(&ctx->refcount))) {
spin_unlock_irqrestore(&tls_device_lock, flags);
return;
}
The ctx survives, but the sock is freed. ctx->sk is left dangling. Each
earlier context in the list adds a synchronize_net() before this one is
reached, so the window can be fairly wide.
If that happens, can the cmpxchg read and write freed or reused socket
memory? There seem to be two bad outcomes:
If the compare fails, tx_hw is false and tls_dev_del() is never called
for TLS_OFFLOAD_CTX_DIR_TX. ctx->netdev has already been set to NULL,
and the final refcount_dec_and_test() in tls_device_down() goes to
tls_device_free_ctx(), which never calls tls_dev_del(). Would this leak
the driver TX offload state?
If the memory has been reused by another TLS socket whose validator is
tls_validate_xmit_skb, the cmpxchg would switch that unrelated socket to
the software fallback.
The unconditional WRITE_ONCE() through ctx->sk in the second loop was
already a use-after-free before this patch, so that part is pre-existing.
What this patch adds is that driver TX teardown now depends on that
unprotected access, where before it used the pinned ctx->tx_conf.
The next patch in this series, "tls: fix socket use-after-free during
device-down", seems to address this. It moves the cmpxchg into the first
loop under tls_device_lock, records the result in TLS_TX_DEV_DOWN, and
tests that flag in the second loop. Would it make sense to fold that fix
into this patch, or reorder the two? Then this commit would not add the
dependency on its own, which matters since it is marked for stable.
>
> /* Stop the RX and TX resync.
> * tls_dev_resync must not be called after tls_dev_del.
> @@ -1370,13 +1374,14 @@ static int tls_device_down(struct net_device *netdev)
> synchronize_net();
>
> /* Release the offload context on the driver side. */
> - if (ctx->tx_conf == TLS_HW)
> + if (tx_hw)
> netdev->tlsdev_ops->tls_dev_del(netdev, ctx,
> TLS_OFFLOAD_CTX_DIR_TX);
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111232930.2532497-1-rjethwani%40purestorage.com
Technical Details
Message-ID:
<179478734781.3136.1664474557678569331@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder3.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363923-linux-kernel-netdev=dewy.ruReferences:
<20261111232930.2532497-1-rjethwani@purestorage.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!3.eu.feeder.erje.net!feeder.erje.net!feeder3.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363923-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v4 1/2] tls: restrict device-down TX fallback to hardware TX sockets Date: Mon, 16 Nov 2026 00:02:27 +0000 Organization: Usenet Network Message-ID: <179478734781.3136.1664474557678569331@kernel.org> References: <20261111232930.2532497-1-rjethwani@purestorage.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1938770"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:p3EHNMCNVUXtfVvzbO81/KAS8Ww= sha256:CcjW1g5J0LDAhpODUN7G0lKMHyYI0yDjPKXxKj4PCGA= sha1:mqUqUw7pmq0chpgX2Gvsz5LLaw0= sha256:k2l3toZoZCwQj7Dsye4g8ihvTWtQImFoWFVxOBHlRt8= 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 3CE8A114AB0; Mon, 16 Nov 2026 03:02:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 YtpLyWT_aEfI; Mon, 16 Nov 2026 03:02:46 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-363923-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 456F71149D9; Mon, 16 Nov 2026 03:02:36 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 1AB1A606BB9; Mon, 16 Nov 2026 00:02:36 +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=1794787350; b=xtqqXRc1uVaHV4tUg6Ut4bKupUTOeA1Etj6Kb1JCAyxW+PksZdedSLBVEqXyKwOGA3Tt ZHOilYINEWT3ZnE80KWhHGW+o9762BBDgaKOlNJxRi3agzVb3yBF+fp5j8qT5OBmno4FS H9IhsulVlgT1c9OaK1+STm7XCbrVnr+/XSlSqZyX234W5D5f4m1j+rfMR5aFeRhxvnTWZ YFnWCxoXovvl7pF0QaA9nDGz9foHbwxAt2MbgADrju63OwKson/9bPjA0eJXdlmwd6tth e/u4ZEy9K/pe27oNLZuGAP2nBp6v0CpzdDssrLpQMflIxTFW1ydarcqdOUgWXcDJeRQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794787350; 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=0LiZaiovIoEgc2+KzKF9v3Bvxk8MU684up3WOQq16sY=; b=HHWMWt0uqZWmWHN6j+HZXsvojcReCN3s1r3PwX8KrcZmWeY7p8ylkwVgBRgKIZ0+6k4E 4h/e7rTiEj+RaF9ubn2NJxHuM6qSJ9mBoYzrq8P4KNDf78ipIn0s0a28Dt0bLrmeWSs41 fpQ8ZpofxD5IkC7bQvv1C9NG6JAArSZhgi41dmR/LlC/NAFHu4SVWs1mTPJQwbseyjrmi WXgBqhRNBy4BSTI02bOZ4i8KkSuhBfBRcOV6Fe3BMWkOyUfnag5LSSSrLhTtquRxS5WYA SC4dg4NgU0h9+7yz0bOmuVxGd7FgSMv2Y6gqKYEhP6YPagPw6WEoli6F3GXljeCb+CQ== 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=irUiT623; 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 53D62606A338; Mon, 16 Nov 2026 00:02:30 +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=irUiT623 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=1794787349; b=tigxMslloiGjN4dFSt90iTe8+YilpICDwnNnGVHg+BacvwMcqUBVDs+doBd/H6DMMPMM 8moEHt+OswWBW6vcmQ4FDv/m0e6v3R32x7ehImb72l1iK9TJb4xtFAvNeQq3RQAVZNn/Q Vlp/UDX2KVAbUjtPrWL5C+TnPXjDVKJtGuYMarDb42p8JUJn713fH+X/DprS7svVvDSZx QMXdXHOnFhKPq3lK5yvSgNUKDZmOoBDkGIo0uq4+NN3VTt26DkvGQWdFMydnnLWA1oMM/ u9MDq2XTZnuxQQ4o98pvAk8EjYxUXW4qsWgAC4iqMxaePsAM2/iL2xlEqz7ySqABlCA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794787349; 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=0LiZaiovIoEgc2+KzKF9v3Bvxk8MU684up3WOQq16sY=; b=geuFcUB7VQmuN3aBvSFS9sP5pTZOGRJ3GCX3pyqDSHQwPasETDJ534hgq9fZR5tQQW+E Bmk6NOYLueKiBq1RtQA7iwaHnmUqK+SaskLINxtzQ6R/9Q8q5G8243gpRqHfIhpzoklF4 AsoSIya/rOudjGWkdlimhJO5Rk8utPkNFzINVIGF3yDnxNsMAzGlk6GcMJor57b63JQ7h pV4AitCHhy4f/pGNhebMvqK1VmklEkgS54Nvc2g2zuOsndKGfDNvjTMZs4nzgKHYinkkX WFCftugNK/EEVL/mUC/FJZ+vuNnFmniNfId90SDKIOjhmW9Vnagj4nVrxOQzDh+7OPg== 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=irUiT623; 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 6B7A1606A31F; Mon, 16 Nov 2026 00:02:29 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 517CE1F000C4; Mon, 16 Nov 2026 00:02:28 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794787349; bh=0LiZaiovIoEgc2+KzKF9v3Bvxk8MU684up3WOQq16sY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=irUiT623aRt32I4fhbQ5pqZjzskjxyj/oIiFf4X64UuBPVJnLFBEooSWi5qHOsejM 0ZKXg1cLffpgEOkAWwjPWjzFyO9HkVK00eyymwk4FiQppgTiRCW1Yb0I520qBx0fcQ dYbAULLLkF2hV9Kr6IrqpHlQzn1SdqQU1TMcl8Bjwl8HdgtmIj9tdziztL9dEZEr3F DbfY1UjHUUzrqbwrvvzTg1ycDJbeDl909lCiOPYliWDTmAzUdh5RrEz5jwFQ13PZy4 fpmxYxK0Z7vMoJlMLLeU6T3veq+IMlUytVbdariGyV9z52/5Ex5fUUNqasVzGRR88G p1Yhk/viXd7kg== X-Cc: netdev@vger.kernel.org, stable@vger.kernel.org, john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net, davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org, tariqt@nvidia.com, alice.kernel@fastmail.im, linux-kernel@vger.kernel.org X-In-Reply-To: <20261111232930.2532497-1-rjethwani@purestorage.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 X-Received-Bytes: 12149