tls_device_down() visits sockets with hardware offload in either direction, but installs tls_validate_xmit_skb_sw() even when TX is not offloaded. That validator calls tls_sw_fallback(), which expects priv_ctx_tx to point to a hardware TX context. An RX-only TLS socket can still send plain TCP data after the device goes down, and the validator stays installed after the device comes back up. Its priv_ctx_tx is NULL, so the fallback crashes when fill_sg_in() tries to take ctx->lock: BUG: kernel NULL pointer dereference, address: 0000000000000008 #PF: supervisor write access in kernel mode RIP: 0010:_raw_spin_lock_irqsave+0x31/0x60 Call Trace: tls_sw_fallback+0x11b/0x450 validate_xmit_skb.isra.0+0x14f/0x420 validate_xmit_skb_list+0x41/0x60 sch_direct_xmit+0x11d/0x2d0 __dev_queue_xmit+0x5e8/0xf30 __neigh_update+0x354/0xcf0 arp_process+0x252/0x800 A socket using software TLS for TX also lacks the hardware TX context required by this validator; there, priv_ctx_tx points to a tls_sw_context_tx instead. Only install the TX fallback when tx_conf is TLS_HW. Leave the validator unchanged for RX-only and software-TX sockets; tls_set_device_offload_rx() never installs one, so they keep sending plain TCP data as before. The NULL dereference above was reproduced on an RX-only socket. With the fix, RX-only TLS sockets on two hosts survived an interface down/up cycle and continued receiving TLS records and sending plain TCP replies. The software-TX case was identified by code inspection only. Fixes: c55dcdd435aa ("net/tls: Fix use-after-free after the TLS device goes down and up") Signed-off-by: Rishikesh Jethwani --- net/tls/tls_device.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index f11d0528fc43..15ef6c3c0648 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1319,8 +1319,13 @@ static int tls_device_down(struct net_device *netdev) list_for_each_entry_safe(ctx, tmp, &list, list) { /* Stop offloaded TX and switch to the fallback. * tls_is_skb_tx_device_offloaded will return false. + * Only sockets with offloaded TX have the + * tls_offload_context_tx the fallback needs; leave RX-only + * and SW-TX sockets alone. */ - WRITE_ONCE(ctx->sk->sk_validate_xmit_skb, tls_validate_xmit_skb_sw); + if (ctx->tx_conf == TLS_HW) + WRITE_ONCE(ctx->sk->sk_validate_xmit_skb, + tls_validate_xmit_skb_sw); /* Stop the RX and TX resync. * tls_dev_resync must not be called after tls_dev_del. -- 2.50.1