Re: [PATCH net v3] tls: restrict device-down TX fallback to hardware TX sockets

From: Rishikesh Jethwani

Date: Tue Nov 10 2026 - 19:23:04 EST


On Tue, Nov 10, 2026 at 1:34 PM Jakub Kicinski <kuba@xxxxxxxxxx> wrote:
>
> On Wed, 4 Nov 2026 14:48:52 -0700 Rishikesh Jethwani wrote:
> > + /* Stop offloaded TX and switch to the fallback.
> > + * tls_is_skb_tx_device_offloaded will return false.
> > + * Only HW TX sockets have the context it needs. Do it under
> > + * tls_device_lock: the reference pins ctx, not ctx->sk.
> > + */
> > + if (ctx->tx_conf == TLS_HW)
> > + WRITE_ONCE(ctx->sk->sk_validate_xmit_skb,
> > + tls_validate_xmit_skb_sw);
>
> The locking in this patch looks way too coincidental.

Agreed. I'll split it in two.

Patch 1 drops tx_conf/rx_conf from tls_device_down(); they're set after
setup releases device_offload_lock. Setup instead publishes state before
up_read(): the HW validator for TX (device-down cmpxchg()es it and uses
the result for TX tls_dev_del()), and for RX it clears TLS_RX_DEV_CLOSED,
which starts set, after a successful add.

Patch 2 switches the validator under tls_device_lock. Since f08d8c1bb97c
("net/tls: Fix race in TLS device down flow") the destructor drops its
ctx reference under that lock, so a successful refcount_inc_not_zero()
there keeps ctx->sk allocated until unlock. We cannot unconditionally
use sock_hold(): sk_refcnt may already be zero while queued skbs keep
the socket allocated. TLS_TX_DEV_DOWN carries the result into cleanup
without touching ctx->sk again.

pw-bot: cr

> --
> pw-bot: cr