From: netdev-bot+sashiko@kernel.org
To: rjethwani@purestorage.com
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
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 [thread overview]
Message-ID: <179478734781.3136.1664474557678569331@kernel.org> (raw)
In-Reply-To: <20261111232930.2532497-1-rjethwani@purestorage.com>
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
prev parent reply other threads:[~2026-11-16 0:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 23:29 [PATCH net v4 1/2] tls: restrict device-down TX fallback to hardware TX sockets Rishikesh Jethwani
2026-11-11 23:29 ` [PATCH net v4 2/2] tls: fix socket use-after-free during device-down Rishikesh Jethwani
2026-11-16 0:02 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179478734781.3136.1664474557678569331@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=alice.kernel@fastmail.im \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rjethwani@purestorage.com \
--cc=sd@queasysnail.net \
--cc=stable@vger.kernel.org \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox